Skip to content
Log In Sign Up info@muvcloud.com

Install restic

# Debian and Ubuntu
sudo apt install restic
# AlmaLinux and Rocky Linux (EPEL)
sudo dnf install epel-release
sudo dnf install restic

Run backups as root so every file can be read. Check the version with restic version.

Step 1: Create the Password File

sudo install -m 600 /dev/null /root/.restic-password
sudo nano /root/.restic-password    # one line: STRONG_PASSPHRASE

restic encrypts everything with this password, and there is no recovery without it: lose it and the backups are unreadable. Store a copy in a password manager or another place off the server.

Step 2: Initialize a Repository over SFTP

export RESTIC_REPOSITORY='sftp:user@your_server_ip:/srv/restic/web1'
export RESTIC_PASSWORD_FILE=/root/.restic-password
restic init

restic logs in with the system ssh client, so key login must work for root first, with no prompt in between. Create /srv/restic on the backup host beforehand, writable by the SSH user.

Or Use S3-Compatible Object Storage

Put the settings in an environment file with mode 600, not on a command line:

# /etc/restic/env  (chmod 600)
RESTIC_REPOSITORY=s3:https://S3_ENDPOINT/BUCKET/web1
RESTIC_PASSWORD_FILE=/root/.restic-password
AWS_ACCESS_KEY_ID=ACCESS_KEY
AWS_SECRET_ACCESS_KEY=SECRET_KEY
set -a; . /etc/restic/env; set +a
restic init

The variable names come from the S3 protocol and work with any S3-compatible service. Give the key access to this one bucket only.

Step 3: Back Up

restic backup /etc /home /root /var/www /var/backups \
  --exclude-caches --exclude '/home/*/.cache'

Each run creates a snapshot. Only new data is uploaded. Dump databases into /var/backups first: see mysqldump and pg_dump.

Step 4: List Snapshots and Files

restic snapshots
restic ls latest /etc/nginx

latest stands for the newest snapshot; you can also give a snapshot ID from the list. To find which snapshots contain a file, use restic find nginx.conf.

Where the Repository Should Live

Not on the server you back up, and not on the same disk. An SFTP repository on a second server is one copy; an S3-compatible bucket at another provider, with its own account and keys, is the off-site copy. A snapshot of the server at the same provider is a useful extra layer, not a replacement for either. The difference is explained in snapshot vs backup.

Step 5: Restore and Compare

Restore into a scratch directory, never over live files, and compare:

restic restore latest --target /tmp/restore-test --include /etc/nginx/nginx.conf
diff /tmp/restore-test/etc/nginx/nginx.conf /etc/nginx/nginx.conf
restic restore latest --target /tmp/restore-test --include /var/www
diff -r /tmp/restore-test/var/www /var/www

Differences in files that changed since the snapshot are expected. Do this test every month.

Step 6: Forget and Prune

restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --dry-run
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune

forget removes snapshots from the list; --prune then deletes the data no longer used and gives the disk space back. Both are permanent, so read the dry run first. Then check the repository:

restic check
restic check --read-data-subset=5%

The second form reads a sample of the stored data as well.

Schedule It

Use a systemd service with EnvironmentFile=/etc/restic/env and a timer, the same pattern as in the BorgBackup guide. With cron, call a root-owned script that loads the environment file; never put the password or keys in the crontab line. For where this copy belongs in a full plan, see the 3-2-1 backup rule.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations