Snapshots are a quick way to undo a change, but they are not backups. A snapshot lives with its server: it is deleted with the server, it can only be restored onto that server, and the service level agreement does not cover data loss. Keep at least one copy of the data that matters on another machine, ideally in another region.
Why a snapshot is not enough
- Deleting a server removes its snapshots at the same time.
- A server that stays suspended past the 7-day grace period is deleted with its snapshots.
- You cannot open a snapshot to pick out one file, or restore it onto a different server.
- CloudSat does not back up your servers for you: what you keep is up to you.
Choose where backups go
- A second CloudSat server in another region. A storage-oriented plan starts at $2.78 a month; see storage VPS hosting.
- Object storage from a provider you choose.
- A machine of your own, such as a NAS at home or in the office.
A good rule is three copies of your data, on two kinds of storage, with one copy off-site.
Set up nightly backups with restic
restic is an open-source backup tool: it encrypts, deduplicates and only sends what changed. These steps back up an Ubuntu or Debian server to another server over SFTP. Replace the addresses and paths with yours.
- On the backup server, create a user and a directory for the backups, for example the user
backupand/srv/restic, owned by that user. - On the server you back up, install restic and create an SSH key for root if it has none:
apt-get install -y restic
ssh-keygen -t ed25519
- Add the content of
/root/.ssh/id_ed25519.pubto/home/backup/.ssh/authorized_keyson the backup server. Then connect once withssh backup@198.51.100.20 exitto accept the backup server's host key. - Create a repository password and save a copy in your password manager. Without it, nobody can read the backups, including you:
openssl rand -base64 32 > /root/.restic-pass
chmod 600 /root/.restic-pass
- Write the settings to
/root/.restic.env:
export RESTIC_REPOSITORY="sftp:backup@198.51.100.20:/srv/restic/web-01"
export RESTIC_PASSWORD_FILE="/root/.restic-pass"
- Create the repository and run the first backup:
. /root/.restic.env
restic init
restic backup /etc /var/www /root
- Schedule a nightly run with a file
/etc/cron.d/restic-backup. It backs up at 02:30, then keeps 7 daily, 4 weekly and 6 monthly copies:
30 2 * * * root . /root/.restic.env && restic backup --quiet /etc /var/www /root /var/backups && restic forget --quiet --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
restic calls each backup a "snapshot" too. Those live in your repository, not in the CloudSat console.
Back up databases as dumps
Copying the files of a running database can produce a broken copy. Dump it first, into a folder that restic backs up, for example in the same cron line before restic backup:
mysqldump --single-transaction --all-databases > /var/backups/mysql.sql
sudo -u postgres pg_dumpall > /var/backups/postgres.sql
Test a restore
A backup you have never restored is a guess. Once a month, restore the latest copy into a scratch folder and look at it:
. /root/.restic.env
restic snapshots
restic restore latest --target /tmp/restore-test
restic check
restic check verifies the repository structure. Compare a few files, and import a database dump into a test database now and then.
Tips
- Put the backup server in another region than the servers it protects.
- Attach a cloud firewall to the backup server that allows SSH only from the addresses of your servers. See Create and apply cloud firewalls.
- Only outbound traffic counts toward a transfer allowance: a backup uses the allowance of the server that sends it, and a restore that of the backup server. See Transfer allowance and overage.
- On Windows servers, restic also runs on Windows, or use Windows Server Backup with a destination on another machine.
- Keep snapshots for quick rollbacks before risky changes: Take a snapshot.