A VPS for backups: how to set up backups that will actually restore
A backup server is chosen not by its CPU but by the price per gigabyte, its location and its bandwidth. That's why the table above is sorted by disk cost and starts with plans of 500 GB or more. But cheap capacity is only half the job: a copy is useful only if you can get it back quickly, it wasn't damaged along with the main server, and it wasn't wiped by whoever broke into the source.
The 3-2-1 rule in practice
The classic formula is three copies of the data, on two different storage systems, with one of them off the main site. For a project on a VPS it usually looks like this:
- the working data on the main server;
- local snapshots or dumps on the same server, for a quick rollback after a failed update;
- an encrypted archive on a separate backup VPS in another data centre, or better still with another host.
A different data centre is a requirement, not a wish: a fire, a power outage across the whole site or an account suspension at the host takes out every machine there at once. If the copies contain personal data of Russian citizens, keep the storage in Russia too; elsewhere, follow the data residency rules that apply to you. More about the large-disk server itself, and what a host's RAID really guarantees, is on the storage VPS page.
What exactly to back up
The most common mistake is copying the files of a running database. Such an archive will almost always be inconsistent and won't start. Export the database with its own tools: pg_dump or pg_basebackup for PostgreSQL, mysqldump --single-transaction or mariadb-backup for MySQL and MariaDB, and send the finished dump to the archive. The finer points of backing up large databases are covered on the VPS for databases page.
Besides the data, the copy should include configuration (/etc, docker-compose files, web server settings), certificates, crontab and application secret files. Without them, a restore turns into a day of manual setup.
Backup frequency is set by the question "how much work can we afford to lose". For an online shop taking orders that's minutes, and the database needs continuous archiving of its transaction logs; for a business-card website a nightly archive is enough. Run jobs during off-peak hours and limit the upload speed so the backup doesn't take over the production server's whole bandwidth.
restic or BorgBackup
Both programs encrypt data on the client side, deduplicate repeated blocks and keep many versions without the size multiplying. The differences are practical:
- BorgBackup works over SSH and requires Borg to be installed on the storage server as well. It's fast, compresses efficiently and suits a server-to-server setup.
- restic is a single executable that can write over SFTP, to S3-compatible storage and to its own rest-server. It fits when the storage doesn't let you install your own software.
For both, set a retention policy, for example 7 daily, 4 weekly and 6 monthly copies (borg prune or restic forget --prune), otherwise the archive grows forever. Keep the encryption key and repository password off both servers, in a password manager or on paper in a safe. A lost key means lost backups; it can't be recovered.
Protection against deletion
If an attacker gets root on the main server, they will also see the storage access key. To stop them wiping the archive, use one of these options:
- append-only mode:
borg serve --append-onlyinauthorized_keyson the storage server, orrest-server --append-onlyfor restic, and run pruning of old copies from the storage itself; - a pull setup: the backup server fetches the data from the production machines itself, and they have no access to it at all;
- a separate SSH key for each source, restricted to a specific command and directory.
Testing restores and recovery time
Run borg check or restic check --read-data-subset regularly to find damaged blocks before you need them. Once a month do a full test restore onto a clean hourly-billed VPS: deploy the database, start the application, open the site. Only then will you know your real recovery time.
That time is limited by bandwidth. A terabyte over a 1 Gbps port downloads in about two and a half hours, over 100 Mbps it takes almost a day. If services must be back up within an hour, keep a small "hot" set (the database and configuration) separately and restore it first; for large archives look at plans with 1 TB of disk or more and a wide port.
And finally: a backup that has silently stopped running is discovered on the day of the disaster. Set up an alert for when a job fails to report on time, for example through Uptime Kuma or another monitoring server; see the VPS for monitoring selection.