Restic is a newer backup solution, but far easier to setup than Borg backup, in my humble opinion. This tutorial is to show you how easy it is to setup, and run daily on Yunohost. This tutorial could also be used to setup Restic on Debian or other flavours of Linux.
What is restic?
restic is a backup program that is fast, efficient and secure. It has multithred support. It supports many backends (SFTP, SSH, Amazon S3, Backblaze, etc.) It supports the three major operating systems (Linux, macOS, Windows) and a few smaller ones (FreeBSD, OpenBSD).
More info: https://github.com/restic/restic/
Restic user manual: https://restic.readthedocs.io/en/stable/
Setup Your Backup Location
Prepare a your backup location (another computer on the LAN, or a USB hard drive, or an internal hard drive)
NOTE: This sort of backup doesn’t protect you against theft, fire, or flood. You should have an offsite backup as well as this local one.
In this example, I am using an internal hard drive that is mounted at:
$ apt-get install restic
You can also download the latest binary from the Github page, or even compile your own binary with Go.
After installing, check that it works with the command:
It will return something like this:
restic 0.12.1 compiled with go1.16.6 on linux/amd64
Setup the Repository
A repository (repo) can hold different backups (snapshots) from different users, or even different machines. They can all be backed up in the same repository as long as the user has the right password. In this example I’ve called the repository my-backups.
$ restic init --repo /mnt/backup/my-backups enter password for new repository: enter password again: created restic repository 085b3c76b9 at /mnt/backup/my-backups Please note that knowledge of your password is required to access the repository. Losing your password means that your data is irrecoverably lost.
NOTE: Make sure you save this password in a password manager. If you lose it, you lose access to all your backups.
More info about setting up repositories, if you want to make an offsite backup - look into using a REST-server.
Make a Backup
Now you will make a test backup of Yunohost Backups folder. You make regular backups using sudo yunohost backup right?
$ restic backup /home/yunohost.backup/archives --verbose --tag yunohost
That’s it! If you run this command again, it will make another snapshot of those files, but it deduplicates the backup so only the files that have changed will be added to the repo.
Check your Backup
Make sure it all works!
$ sudo restic -r /mnt/backup/my-backups snapshots enter password for repository: repository 9f935439 opened successfully, password is correct ID Time Host Tags Paths =================== c72d2899 2021-07-09 01:00:02 blah.com yunohost /home/yunohost.backup/archives =================== 1 snapshot
Automate Your Backups
Since restic deduplicates backups it makes sense to make daily backups of your important data. If you automate your backups, you won’t forget to do it and you’ll have a backup when you really need it!
Setup Password File
Your server needs a password to your repo so it can automate your backups.
cd ~ nano .restic-backup export RESTIC_REPOSITORY=""/mnt/backup/my-backups"" export RESTIC_PASSWORD=""YOURPASSWORDHERE""
Setup a Script
It’s better to have a shell script holding all your backup tasks so they can run one after another. It’s hard to
nano restic-backups #!/bin/bash source /home/admin/.restic-backup restic backup /home/yunohost.backup/archives --tag yunohost restic backup /home/admin/ --tag home etc.
Setup a Cron Job for the Script
0 11 * * * root /home/admin/restic-backups
There you go, now you have a simple solution to make daily backups! If you want to go further:
- make a script to do ‘prune’ jobs (deleting old backups - i.e. snapshots)
- get another computer, and setup an offsite backup using a REST-server (I am doing this and will make another tutorial in the future for it)
NOTE: Restic currently doesn’t have compression on its backups. If you need compression, look into Borg backup.
In my opinion, hard drive space is so ‘cheap’ and plentiful at the moment, so compression isn’t a very big deal for most. I also believe the simpler user experience of Restic makes it the clear winner.
Just as with a camera, the best backup is the one you do everyday. If it’s too complicated to make backups, most people won’t bother. I know I struggled to setup Borg backup when I used it in the past. Restic has been such a great thing to use, I can never see myself going back.