The scripts/ directory contains six backup scripts:
| Script | Purpose |
|---|---|
backup-db.sh |
Dump PostgreSQL database (gzipped) |
backup-env.sh |
Snapshot .env file |
backup-freeswitch.sh |
Archive /etc/freeswitch (tarball) |
backup-gofaxserver-config.sh |
Snapshot /etc/gofaxserver/config.json |
backup-ftp-upload.sh |
Upload backup files to an FTP server |
backup-all.sh |
Runs all of the above in sequence |
All backups are saved to ./backups/<type>/ by default, with timestamped filenames.
Add these to your .env (see sample.env for reference):
# Backup retention (optional, default 30 days for DB/FS, 90 for .env)
BACKUP_KEEP_DAYS=30
# FTP upload (optional — omit to skip FTP entirely)
FTP_HOST=ftp.example.com
FTP_USER=backupuser
FTP_PASS=backuppassword
FTP_PORT=21
FTP_REMOTE_DIR=/backupsNote: If
FTP_HOSTis not set, the FTP upload step is silently skipped (handled bybackup-ftp-upload.shvia[ -z "$FTP_HOST" ]check at the top of the script). All other steps run regardless.
| Script | Reads |
|---|---|
backup-db.sh |
POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, BACKUP_KEEP_DAYS |
backup-env.sh |
BACKUP_KEEP_DAYS |
backup-freeswitch.sh |
BACKUP_KEEP_DAYS |
backup-gofaxserver-config.sh |
BACKUP_KEEP_DAYS |
backup-ftp-upload.sh |
FTP_HOST, FTP_USER, FTP_PASS, FTP_PORT, FTP_REMOTE_DIR (all optional) |
backup-all.sh |
All of the above (chained) |
sudo ./scripts/backup-all.sh./scripts/backup-db.sh # database only
./scripts/backup-env.sh # .env only
sudo ./scripts/backup-freeswitch.sh # freeswitch only (needs root)
sudo ./scripts/backup-gofaxserver-config.sh # gofaxserver config only (needs root)Every script accepts an optional path argument:
./scripts/backup-db.sh /mnt/nfs/backups/db
sudo ./scripts/backup-all.sh /mnt/external/gofax-backups./scripts/backup-ftp-upload.sh ./backups/db dbsudo crontab -eAdd:
0 3 * * * cd /opt/gofaxserver && ./scripts/backup-all.sh >> /var/log/gofax-backup.log 2>&1Tip: Use
sudo crontab -e(notcrontab -e) when your project lives in a root-owned path or your.env/config files require root to read.
0 */6 * * * cd /opt/gofaxserver && ./scripts/backup-db.sh >> /var/log/gofax-backup-db.log 2>&1Tip: Replace
/opt/gofaxserverwith wherever your project lives on the server.
# Check the log after the scheduled time
tail -50 /var/log/gofax-backup.log
# List what's been backed up
ls -lhR ./backups/Old backups are automatically pruned each time a backup runs:
| Type | Default Retention | Override |
|---|---|---|
Database (.sql.gz) |
30 days | BACKUP_KEEP_DAYS |
| .env snapshots | 90 days | BACKUP_KEEP_DAYS |
FreeSWITCH (.tar.gz) |
30 days | BACKUP_KEEP_DAYS |
GoFaxServer config (config.json) |
30 days | BACKUP_KEEP_DAYS |
# Locate the backup
ls -lh ./backups/db/
# Restore (replace the filename with your target backup)
gunzip -c ./backups/db/fax_20260317_030000.sql.gz | \
PGPASSWORD="$POSTGRES_PASSWORD" psql \
-h localhost -p 5432 \
-U "$POSTGRES_USER" \
-d "$POSTGRES_DB"To restore into a fresh database:
# Create the database first
PGPASSWORD="$POSTGRES_PASSWORD" createdb \
-h localhost -p 5432 -U "$POSTGRES_USER" "$POSTGRES_DB"
# Then restore
gunzip -c ./backups/db/fax_20260317_030000.sql.gz | \
PGPASSWORD="$POSTGRES_PASSWORD" psql \
-h localhost -p 5432 \
-U "$POSTGRES_USER" \
-d "$POSTGRES_DB"If using Docker Compose:
# Restore directly into the container
gunzip -c ./backups/db/fax_20260317_030000.sql.gz | \
docker exec -i postgres psql -U fax -d fax# List available snapshots
ls -lh ./backups/env/
# Restore (simply copy back)
cp ./backups/env/.env_20260317_030000 ./.env
chmod 600 ./.env# List available archives
ls -lh ./backups/freeswitch/
# Preview contents before restoring
tar tzf ./backups/freeswitch/freeswitch_20260317_030000.tar.gz
# Restore (overwrites current /etc/freeswitch)
sudo tar xzf ./backups/freeswitch/freeswitch_20260317_030000.tar.gz -C /etc/
# Restart FreeSWITCH to pick up changes
sudo systemctl restart freeswitch# List available snapshots
ls -lh ./backups/gofaxserver-config/
# Restore (overwrites current /etc/gofaxserver/config.json)
sudo cp ./backups/gofaxserver-config/config_20260317_030000.json /etc/gofaxserver/config.json
sudo chmod 600 /etc/gofaxserver/config.jsonIf you need to pull backups from the FTP server to restore on a new machine:
# Download all backups
wget -r -nH --cut-dirs=1 ftp://backupuser:backuppassword@ftp.example.com/backups/
# Or a specific file
curl -u backupuser:backuppassword \
ftp://ftp.example.com/backups/db/fax_20260317_030000.sql.gz \
-o fax_20260317_030000.sql.gz| Task | Command |
|---|---|
| Full backup | sudo ./scripts/backup-all.sh |
| DB only | ./scripts/backup-db.sh |
| Restore DB | gunzip -c backup.sql.gz | psql -U fax -d fax |
| Restore DB (Docker) | gunzip -c backup.sql.gz | docker exec -i postgres psql -U fax -d fax |
| Restore .env | cp ./backups/env/.env_TIMESTAMP ./.env |
| Restore FreeSWITCH | sudo tar xzf backup.tar.gz -C /etc/ |
| Restore GoFaxServer config | sudo cp ./backups/gofaxserver-config/config_TIMESTAMP /etc/gofaxserver/config.json |
| Check backups | ls -lhR ./backups/ |