Skip to main content
Published on November 16, 2026 Backing up a Linux VPS with restic gives you an encrypted copy of your files and databases off the server, with months of history, and lets you restore a single item with one command. The automatic VPS backup copies the whole disk every night and restores it in one go from the console. restic adds the finer layer: it restores one configuration file, one site directory or one database, on this server or another, without touching anything else. This guide sets up that second layer on Debian, Ubuntu, AlmaLinux and Rocky Linux: file and database backups, scheduling, retention, verification and a restore test.

VPS backup, snapshot or restic?

All three work together: a snapshot before an upgrade, the nightly backup to bring the server back, restic to recover one specific piece of data.

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:
Copy this password into your password manager, off the server. The restic documentation is explicit: without it, the data in the repository is lost. If the VPS goes away, it is the only key to your backups.

Option 1: S3-compatible storage

If your provider requires a region, add AWS_DEFAULT_REGION= with its value.

Option 2: an SFTP server

restic uses the system ssh client. The login must use a key, with no password prompt, or the timer cannot run on its own:
The two 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.
To manage your VPS SSH keys, see SSH keys.

Initialize the repository

Check. 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:
On MySQL, replace 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:
With --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:
Keep the plain SQL format, uncompressed: restic already compresses data (repository format 2, the default since restic 0.14.0), and an uncompressed file deduplicates well from one night to the next. Check. restic snapshots --tag postgresql shows one line per database, plus postgresql-globals.sql.
On Debian 12 and Ubuntu 24.04, the packaged restic predates --stdin-from-command. Write the dump to a file, then back up the directory:
Avoid 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.
Check. 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. The forget 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:
Check. After the first few months, 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:
On S3 storage billed by download volume, --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

Files are restored under --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

The dump has no 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

In a second terminal, 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

Have a question about a server hosted with us? Our team is available from your client area.