Restic is a newer backup solution, but far easier to setup than Borg imho. This tutorial is to show you how easy it is to setup, and run daily on Yunohost.
I love Yunohost and wish to give a little back to this community with this walk-through that I hope will help some people.
What is restic?
https://restic.readthedocs.io/en/stable/
1. 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: /mnt/backup
2. Install Restic
sudo 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:
restic version
It will return something like this:
restic 0.12.1 compiled with go1.16.6 on linux/amd64
3. 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.
4. Make a Backup
Now you will make a test backup of Yunohost Backups folder. You make regular backups using sudo yunohost backup
right?
sudo 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.
5. 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
6. 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!
6.1 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"
6.2 Setup Script
Itās better to have a shell script holding all your backup tasks so they can run one after another because itās hard to judge how long a backup will take.
nano restic-backups
Then paste the following:
#!/bin/bash
source /home/admin/.restic-backup
restic backup /home/yunohost.backup/archives --tag yunohost
restic backup /home/admin/ --tag home
# any other backups you want
6.3 Setup a Cron Job
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)
Thanks for reading! Any suggestions on how to improve this, please let me know. Any questions about running restic and Yunohost - ask away.
Put this on my blog for posterity.