VPS backup, snapshot or restic?
Install restic
Versions in the official repositories, checked on November 16, 2026. The latest upstream release is 0.19.1 (July 5, 2026).--stdin-from-command streams the output of a dump command straight into the repository. It arrived in restic 0.17.0. A variant for earlier versions is given below.
Prepare the backup repository
A restic repository is encrypted and deduplicated: each run only uploads new blocks. It must live off the VPS.Credentials in a single file
restic reads its repository and password from environment variables. Keep them in a file only root can read:Option 1: S3-compatible storage
AWS_DEFAULT_REGION= with its value.
Option 2: an SFTP server
restic uses the systemssh client. The login must use a key, with no password prompt, or the timer cannot run on its own:
ServerAlive lines come from the restic documentation: they stop the server from dropping the connection while restic walks through a large set of unchanged files.
Initialize the repository
restic cat config prints the repository configuration with no error. Keep this shell open for the next steps.
Back up files
Problem. The system can be reinstalled. Your configuration and your sites cannot. Solution. Back up the directories that hold your data, and leave caches out:--one-file-system stays on the file system of each path. --exclude-caches skips directories that contain a CACHEDIR.TAG file. Adjust the paths to your server: /srv, /opt, Docker volumes.
Check. restic snapshots --tag files lists the new snapshot.
Consistent MySQL and MariaDB backups
Problem. Copying/var/lib/mysql while the server runs gives inconsistent files.
Solution. Take a logical dump with --single-transaction: it reads InnoDB tables exactly as they were when the transaction started, without blocking applications. restic stores the output directly, with no intermediate file on disk:
mariadb with mysql and mariadb-dump with mysqldump: the options are the same. --routines and --events add stored procedures and scheduled events; triggers are included by default.
As root, the login goes through the Unix socket on Debian and Ubuntu. If your server asks for a password, put it in /root/.my.cnf:
--stdin-from-command, restic watches the exit code of the dump. If mariadb-dump fails, the backup is cancelled and no snapshot is created.
Check. restic snapshots --tag mariadb shows one line per database, with the path /mariadb-<database>.sql.
Back up PostgreSQL
Problem. Same constraint: the files under/var/lib/postgresql cannot be copied while the server runs.
Solution. pg_dump produces a consistent export even while the database is in use, without blocking readers or writers. It exports one database at a time; roles are backed up separately with pg_dumpall --globals-only:
restic snapshots --tag postgresql shows one line per database, plus postgresql-globals.sql.
On Debian 12 and Ubuntu 24.04, the packaged restic predates Avoid
--stdin-from-command. Write the dump to a file, then back up the directory:mariadb-dump ... | restic backup --stdin: the restic documentation advises against it, because a failed dump still produces a snapshot.Schedule backups with a systemd timer
Problem. A backup you run by hand eventually stops being run. Solution. A script holds the steps, a service runs it, a timer schedules it.Persistent=true catches up on a missed run if the VPS was off at the scheduled time. RandomizedDelaySec spreads the start, which helps when several servers write to the same storage.
systemctl list-timers restic-backup.timer shows the next run, and systemctl status restic-backup.service shows status=0/SUCCESS after the first run.
Retention: restic forget —prune
Problem. Without a retention policy, the repository only grows. Solution. Theforget line in the script keeps the latest snapshot of each of the last 7 days, 5 weeks and 12 months. restic groups snapshots by host and paths before applying the policy, so each database keeps its own history. --prune then frees the space of data nothing refers to any more.
Before changing the policy, simulate it:
restic snapshots does not go back further than the policy you chose.
Verify the repository: restic check
Problem. A backup that was never checked is an assumption. Solution.restic check verifies the repository structure. --read-data-subset=5% also reads back a random sample of the data on every run: over the nights, the whole repository gets read. Once a month, run a full read:
--read-data downloads the whole repository: a regular sample covers the rest of the time.
Check. The output ends with no errors were found.
Test a restore
This is the step that turns a copy into a backup. Do it when you set things up, then regularly.Restore a file or a directory
--target with their full path. For a whole site, replace the file with its directory: --include /var/www/mysite. For an older version, use the ID shown by restic snapshots instead of latest.
Restore a database into a test database
CREATE DATABASE statement: it imports into any empty database, on this server or another one. To replace the production database, import it into the original database after emptying it.
restic dump combines latest and --tag: it picks the latest snapshot with that tag, then reads the given file from it.
Browse backups with restic mount
ls /mnt/restic shows the snapshots, tags, hosts and ids directories. Copy what you need, then stop restic mount with Ctrl-C. Mounting goes through FUSE: on Linux, the fuse kernel module must be loaded and the fusermount command available. For many files, restic restore is significantly faster.
Check. The restored file matches the original, and the test database holds the expected tables.
What to restore, and how
Common pitfalls
The repository password only exists on the server. If the VPS is lost, so are the backups. Keep a copy of the password and of/etc/restic/env somewhere else.
latest without --tag. The latest snapshot in the repository is often a database one. Always add --tag, or pass a snapshot ID.
A dump sent through a pipe. mariadb-dump | restic backup --stdin creates a snapshot even when the dump fails. Use --stdin-from-command.
The SFTP host key was never accepted. The timer fails on a question nobody answers. Make the first connection by hand, as root.
forget without --prune. Snapshots leave the list, but space is only freed by prune.
MyISAM tables. --single-transaction only guarantees consistency for InnoDB. Convert those tables, or back them up during a quiet window.
A lock left by an interrupted run. restic unlock removes locks created by other restic processes. Make sure no backup is running first.
Going further
- Free VPS backup trial: a full copy of the server every night, in one click
- Backups and snapshots: the two protections you manage from the console
- SSH keys: key-based login, also useful for the SFTP repository
- VPS won’t boot: rescue mode, step by step
- Disk full on a Linux VPS: the restic cache and dumps take space too
- Automatic security updates: the other setting that should run on its own

