Skip to content

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.

20 minutesServer administrationSite owner / DevOpsVerified against the platform code

What to back up ​

WhatWhereWhyHow often
DatabasePostgreSQL database from DB_DATABASEUsers, balances, orders, trades, deposits, withdrawals, and all admin settings, including hot-wallet private keysEvery few hours, plus before every update
Uploaded filesstorage/app/public/Logos, coin icons, KYC documents, P2P appeal evidence, article imagesDaily
.envProject rootEncryption key (APP_KEY), database and service credentialsAfter every change
socket-config.jsonProject rootWebSocket credentialsAfter every change
Translationsresources/lang/Language files edited in Admin → Languages are saved hereDaily
Matching engine staterust-matching-engine/state/Only if you use the matching engine. It can be rebuilt from the database, so this is optional.Daily
Fireblocks keyfireblocks_secret.key (or FIREBLOCKS_PUBLIC_KEY_PATH)Only if you use FireblocksAfter every change
Bitcoin Core walletThe node's wallet.datOnly if you run BTCAfter 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 -delete

Replace 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.sh

2. Run it on a schedule ​

bash
sudo crontab -e
txt
0 */6 * * * /usr/local/bin/exchange-backup.sh >> /var/log/exchange-backup.log 2>&1

This 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-backups

Your 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 ​

  1. Install the platform on the new server by following Installation up to Create the database. Don't run migrate or db:seed.

  2. Copy and decrypt the latest backups:

    bash
    gpg --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.gz
  3. Restore the database into the empty database:

    bash
    sudo -u postgres pg_restore --no-owner --role=exchange -d exchange db.dump
  4. Restore the files, which also brings back .env and socket-config.json:

    bash
    cd /var/www/exchange
    tar -xzf ~/files.tar.gz
    php artisan storage:link
    sudo chown -R www-data:www-data storage bootstrap/cache
  5. Check .env for anything that changed with the server: database host, APP_URL, PUSHER_HOST.

  6. Run any new migrations, in case the backup is older than the code: php artisan migrate --force.

  7. Continue the installation from Build the front-end: Nginx, HTTPS, PM2, scheduler, Soketi, chart service and bridges.

  8. 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.

Owner documentation for the CryptoTech exchange platform.