Appearance
Backups & restore
An exchange holds other people's money. If the server is lost, the backup is the only record of who owns what. Back up automatically, keep copies away from the server, and test a restore before you need one.
What to back up
| What | Where | Why | How often |
|---|---|---|---|
| Database | PostgreSQL database from DB_DATABASE | Users, balances, orders, trades, deposits, withdrawals, and all admin settings, including hot-wallet private keys | Every few hours, plus before every update |
| Uploaded files | storage/app/public/ | Logos, coin icons, KYC documents, P2P appeal evidence, article images | Daily |
.env | Project root | Encryption key (APP_KEY), database and service credentials | After every change |
socket-config.json | Project root | WebSocket credentials | After every change |
| Translations | resources/lang/ | Language files edited in Admin → Languages are saved here | Daily |
| Matching engine state | rust-matching-engine/state/ | Only if you use the matching engine. It can be rebuilt from the database, so this is optional. | Daily |
| Fireblocks key | fireblocks_secret.key (or FIREBLOCKS_PUBLIC_KEY_PATH) | Only if you use Fireblocks | After every change |
| Bitcoin Core wallet | The node's wallet.dat | Only if you run BTC | After every change |
Your backups contain private keys
Admin settings, including hot-wallet private keys, are stored in the settings table of the database. Anyone who gets a copy of a database backup can empty your hot wallets. Encrypt every backup before it leaves the server, and store it where only you can read it.
Keep APP_KEY safe
APP_KEY encrypts sessions and some stored values, including users' two-factor secrets. A restored database with a different APP_KEY logs everyone out, and 2FA stops working. Back up .env together with the database.
Automatic database backups
1. Create a backup script
Save as /usr/local/bin/exchange-backup.sh:
bash
#!/bin/bash
set -euo pipefail
APP=/var/www/exchange
DEST=/var/backups/exchange
KEEP_DAYS=14
STAMP=$(date +%F_%H-%M)
mkdir -p "$DEST"
# Database (compressed custom format, restorable with pg_restore)
sudo -u postgres pg_dump -Fc exchange > "$DEST/db_$STAMP.dump"
# Uploads, translations and configuration
tar -czf "$DEST/files_$STAMP.tar.gz" -C "$APP" \
storage/app/public resources/lang .env socket-config.json
# Encrypt both with a passphrase kept outside the server
for f in "$DEST/db_$STAMP.dump" "$DEST/files_$STAMP.tar.gz"; do
gpg --batch --yes --pinentry-mode loopback \
--passphrase-file /root/.backup-passphrase -c "$f" && rm "$f"
done
# Remove old backups
find "$DEST" -name '*.gpg' -mtime +$KEEP_DAYS -deleteReplace exchange in pg_dump with your database name. Create the passphrase file once and keep a copy of the passphrase in your password manager:
bash
sudo sh -c 'openssl rand -base64 48 > /root/.backup-passphrase && chmod 600 /root/.backup-passphrase'
sudo chmod 700 /usr/local/bin/exchange-backup.sh2. Run it on a schedule
bash
sudo crontab -etxt
0 */6 * * * /usr/local/bin/exchange-backup.sh >> /var/log/exchange-backup.log 2>&1This makes a backup every 6 hours.
3. Copy backups off the server
A backup on the same server is lost with the server. Copy the encrypted files somewhere else at least daily, for example to object storage with rclone:
txt
30 */6 * * * rclone copy /var/backups/exchange remote:exchange-backupsYour hosting provider's disk snapshots are a useful extra, but not a replacement: a snapshot taken while the database is writing may not restore cleanly.
Restore to a new server
Install the platform on the new server by following Installation up to Create the database. Don't run
migrateordb:seed.Copy and decrypt the latest backups:
bashgpg --batch --passphrase-file /root/.backup-passphrase -d db_2026-10-27_06-00.dump.gpg > db.dump gpg --batch --passphrase-file /root/.backup-passphrase -d files_2026-10-27_06-00.tar.gz.gpg > files.tar.gzRestore the database into the empty database:
bashsudo -u postgres pg_restore --no-owner --role=exchange -d exchange db.dumpRestore the files, which also brings back
.envandsocket-config.json:bashcd /var/www/exchange tar -xzf ~/files.tar.gz php artisan storage:link sudo chown -R www-data:www-data storage bootstrap/cacheCheck
.envfor anything that changed with the server: database host,APP_URL,PUSHER_HOST.Run any new migrations, in case the backup is older than the code:
php artisan migrate --force.Continue the installation from Build the front-end: Nginx, HTTPS, PM2, scheduler, Soketi, chart service and bridges.
Check with the checklist at the end of the installation guide.
Pause the old server first
If the old server is still running, put it in maintenance mode and stop its scheduler and bridges before you take the final backup. Otherwise deposits or withdrawals could be processed on the old server after the backup was taken.
Test your backups
A backup you haven't restored is a guess. Every month, restore the latest backup on a spare server or a local machine, and check that you can sign in and that balances look right.
