Posted inApps / Guides / Open Source

Backrest: How to Automate and Restore Restic Backups

An illuminated Restic backup snapshot connected by an orange arrow to a restored image file inside a glass panel.

We’ve talked about Restic before and how you can use it to create encrypted backups and restore previous versions of your files. Restic doesn’t come with a backup scheduler. So what if you don’t want to mess around with scripts and cron jobs?

Take a look at Backrest, a free and open source front end for Restic. It allows you to manage your repositories, schedule backups, browse your snapshots and restore files, all from your web browser.

And if, for whatever reason, you decide to ditch Backrest, you can still access your backups using Restic.

Install Backrest

Backrest is available for macOS, Linux, Windows and FreeBSD. You can get the app ( and the checksums to verify the download ) from GitHub.

There’s also a Docker version, but for now I’d stick to the native app. There’s a report concerning outdated dependencies in the Docker image, and a fix in a published image hasn’t been verified.

NOTE: Backrest can download and manage Restic for you. However, the version it expects in Backrest 1.14.1 is Restic 0.19.1. Restic 0.20.0 fixes two security issues related to restoring files. So for this tutorial we’re going to use Restic 0.20.0 instead.

You can check which version of Restic you have with restic version. On Linux or macOS, if you’ve got the Backrest binary in your current directory and Restic 0.20.0 in your PATH, run:

./backrest -restic-cmd "$(command -v restic)"

On Windows you can use the same -restic-cmd option and specify the full path to restic.exe.

Backrest will warn you that you’re using a newer version of Restic than it expects. With this combination, the backup, scheduling, browsing, restore and repository check operations were tested on Linux through Backrest’s API ( not by clicking through the web interface ). That’s not a guarantee of compatibility with every operation or on every OS.

To access Backrest, open http://127.0.0.1:9898 in your browser. Give your instance a name and set up a username and password. Authentication is disabled initially.

You don’t need to keep the browser open for Backrest to run your backups. But you DO need to keep Backrest running. Check the installation instructions for setting it up as a service on your OS. Make sure the service also uses the right Restic binary. You can set BACKREST_RESTIC_COMMAND instead of passing the command line option.

Run Backrest as your regular user and leave it listening on localhost. Think about what you can do from that web interface. You can change what’s being backed up, restore files and even delete snapshots. You don’t want just anybody to have access to it. If you need access from another machine, use authentication and an encrypted connection via a properly secured proxy or private tunnel. Don’t expose the interface directly to the internet.

Create a repository and a backup plan

If you already use Restic, you can add your existing repository to Backrest. If you’re new to Restic, a repository is where it stores your encrypted backup data. Every snapshot represents the state of your files at the time of a backup. Backrest doesn’t use its own backup format. It runs Restic for you.

Before you set up a plan to back up all your documents, try it with a couple of dummy files.

  1. Create a folder called backrest-demo somewhere on your computer. Inside it create a folder called documents with the following files:
    • notes.txt ( write first version in the file )
    • nested/old.txt ( create the subfolder nested and write recover me in the file )
    • ignore.tmp

    Make a copy of the first two files outside the documents folder. We’ll need them later.

  2. In Backrest click Add Repo. Give your repository a name ( e.g. demo ) and set the repository URI to the full path to a new folder called repository inside backrest-demo. Choose a password and test the connection. When you add the repository, Backrest can initialize it if it doesn’t already exist.
  3. Click Add Plan. Give your plan a name, select your repository and, under Paths, add the full path to the documents folder. Under Excludes add *.tmp. Restic will ignore files matching that pattern.
  4. For now we want to run the backups manually and keep both snapshots, so choose Disabled as the schedule type and set Retention Policy to None. Leave scheduled retention in the repository settings disabled as well. Save the plan and run a backup.
  5. Open notes.txt in the dummy folder, change the text to second version and delete nested/old.txt. Run another backup. You should now have two snapshots.

What if you want to back up your files to a NAS or to the cloud instead? You can specify the path to an external drive or a mounted network share just like we did with our demo repository. Or you can use any of the appropriate Restic backends ( SFTP, Amazon S3 and compatible services, Backblaze B2, Azure, Google Cloud Storage etc ). You’ll have to specify the URI and any environment variables or flags required to access the storage. You can also use rclone, provided it’s installed and configured for the account running Backrest. Check the Restic docs for the details of each backend.

NOTE: for the purpose of this tutorial the repository can be on the same drive as our dummy files. But what good is a backup of your Documents folder if the backup is on the very same drive that dies? Make sure your external drive or network share is actually mounted and has enough free space. You don’t want to end up writing backups to the wrong drive. And remember that while Restic encrypts your data, it can’t stop somebody with permission to delete the repository from doing just that.

Automate your backups

Now that we’ve got our little backup plan working, how do we get Backrest to run it automatically?

You can set an interval or use a cron expression. Say you want to back up your Documents folder once a day but don’t always leave your computer on. Edit the plan, choose Interval (Days), set it to 1 and select Last Run Time as the reference clock. Backrest calculates the interval from the end of the last backup operation ( even if that attempt failed ). It won’t wake up your computer or recreate every backup that was missed while the computer was off.

Set Backrest to start automatically as described above, and make sure it can access the files and the repository when it runs. Every once in a while check the operation history. A snapshot can be created even if some of the files couldn’t be read.

You can also configure notifications when backup or maintenance events occur. Useful if you’re not always in front of the computer running Backrest. Just be aware that when you send notifications to a service like Slack or Discord, you may also be sending file paths and details of errors to that service.

Backrest also lets you run your own commands ( hooks ) when these events occur. But if you’re using Backrest 1.14.1, leave command hooks disabled. There’s a reported command injection vulnerability that can cause error text from Restic to be interpreted as shell commands and executed with the permissions of the user running Backrest. Updating Restic doesn’t fix this issue in Backrest itself. Don’t enable command hooks until a fix has been verified.

What do you do with all those snapshots?

Let’s say you want to keep a daily backup for a week, weekly backups for a month and monthly backups going back six months. You can set the retention policy for your plan to keep 7 daily, 4 weekly and 6 monthly snapshots. That doesn’t necessarily mean you’ll have 17 snapshots. There has to be a snapshot in a given period to keep in the first place, and the same snapshot can satisfy more than one rule.

You can also set a retention policy for the whole repository. In Backrest 1.14.1, enabling scheduled retention there takes precedence over automatic retention for the individual plans. The repository policy groups snapshots by their tags. So don’t just set a bunch of retention rules in both places and assume they’ll work independently.

There are three operations that you’ll come across in Backrest:

  • Forget: removes snapshots. Do you still need the version of a file you deleted a month ago? Make sure your retention policy keeps a snapshot that contains it.
  • Prune: frees up the space occupied by data that none of the remaining snapshots use. This can take quite a bit of time and, if you’re using remote storage, bandwidth. You don’t need to prune every time you run a backup.
  • Check: checks the repository for errors. By default a structure check doesn’t read all the data you’ve backed up. You can tell Backrest what percentage of the stored data to read ( including 100% ). If you’ve got hundreds of GB in the cloud, consider the cost of reading all that data.

You can schedule maintenance in the repository settings or run a check manually with Check Now. Look at the result in the operation history.

NOTE: if you access the same repository from more than one computer ( with Backrest or directly with Restic ), coordinate your maintenance jobs. Restic uses locks to prevent conflicting operations. Don’t remove a lock just because a job is taking longer than you’d like.

Restore your files

Back to the two snapshots we created earlier. Open the first snapshot and browse the directory tree. You should see notes.txt and nested/old.txt. In the second snapshot old.txt should be gone. Neither snapshot should contain ignore.tmp.

Let’s get the old version of notes.txt back WITHOUT overwriting the new one.

  1. In the first snapshot find notes.txt, open its menu and choose Restore to path.
  2. Specify the full path to a new folder called recovered-notes inside backrest-demo. Don’t create the folder yourself. Backrest 1.14.1 won’t let you restore to a path that already exists.
  3. Confirm the restore and check the operation history to see if the restore actually finished.
  4. Now do the same for the nested folder in the first snapshot, but use a different destination ( e.g. backrest-demo/recovered-nested ).
  5. Open the files you’ve just restored. notes.txt should contain first version and old.txt should contain recover me. Remember those copies of the original files? On macOS or Linux you can use cmp to compare them with the recovered ones. Both files in the Linux test matched their originals byte for byte. And the current version of notes.txt was left alone.

You can also download individual files from the snapshot browser. But try restoring a whole directory as well. If you rely on file permissions, ownership or other filesystem metadata, check those too. What gets restored depends in part on the filesystem, OS and permissions of the user running Restic.

What if you no longer have Backrest?

You might have set up Backrest on a computer that is no longer working. Or maybe you just don’t want to use Backrest anymore. As long as you’ve got access to the repository, the password and a compatible version of Restic, it doesn’t really matter.

Once your Backrest jobs have finished, stop Backrest. Open a terminal with no other Restic credentials or repository configured, navigate to backrest-demo and run:

restic -r ./repository snapshots

You should see your snapshots. To restore the first one ( replace SNAPSHOT_ID with the ID of your first snapshot ):

restic -r ./repository restore SNAPSHOT_ID --target ./recovered-cli --verify

Use a new target directory. Type in the repository password when asked. Locate the restored documents folder ( the original source path may be part of the restored directory tree ) and check your files. This is how you can recover your data on another computer as well, without having to set up Backrest again.

Which brings us to another important point. Where do you keep your repository password? If the only place you’ve got it stored is the computer you’re backing up, you may have a problem. Keep the password and any credentials or configuration needed to access your storage somewhere you can get to them even if that computer is gone. Not just inside the encrypted repository itself.

NOTE: your repository is encrypted but the passwords and credentials you enter in Backrest as repository passwords or environment variables are stored in plain text in its configuration file ( unlike your Backrest login password, which is hashed ). You can find the location of that file in the Backrest dashboard. Keep a protected copy of it. You don’t need it or the operation history to read the repository with Restic if you have the necessary credentials separately.

If you’ve already got your Restic scripts set up the way you want them, I see no reason to switch to Backrest. But if you’re looking for a GUI backup app, Backrest has the advantage that you can use the same repositories with or without the GUI. There’s also Kopia, but Kopia uses its own repository format.

One more thing… try restoring some of your actual files while you still have them. Getting a notification telling you that the backup was successful is great. Can you get the files back?

Support FSMdotCOM on Liberapay