This blog post is the fourth of four posts about restic, a simple, beautiful, and extremely versatile file backup solution. In this post I will show real-life examples on how to recover forgotten snapshots, mounting the whole repository to a server, changing repository encryption password, and self-updating the installed restic version.
The restic blog post series
If you accidentally “forgot” a snapshot by using the following command:
There is still hope to restore data from that snapshot if you haven’t called the “prune” command yet by using the “recover” command:
The “recover” command does create a special snapshot that contains every snapshot (actually only every unique snapshot). But I will try to emphasize what really happens when calling the “recover” command.
Imagine we have already two snapshots containing the following files:
We create a third and fourth one also containing a file called “c”.
We call the “recover” command and get a fifth special snapshot containing three roots with the following files:
Even though we have already four snapshots (and the special recovery snapshot) we only have three roots, due to the fact that the third and fourth snapshots are identical (remember we had de-duplication). At this point, I’m going to forget and prune our special snapshot, so we are back to the four snapshots. We then forget (not prune!!!) our snapshot number two containing the files “a” and “b” so we are left with three snapshots. The first with “a”, and the third and fourth which are identical having the files “a”, “b” and “c”. Again, we call the “recover” command and get a special snapshot still containing all the three differing roots we had before.
Due to the stale data chunks, we were able to recover the forgotten second snapshot data.
Mounting the whole backup directory
In certain cases, we don’t want to stick with recovering single snapshots or trying to find files in multiple snapshots. We’d love to just browse our whole backup repository as if it was our filesystem. Thanks to restic we can exactly do this by mounting the whole backup repository to our filesystem by using the following command:
We can now open another terminal and just browse the whole backup repository:
Restic allows us to set multiple access keys for our backup repository. We can do so using the “key add”, “key list”, key remove” commands:
When we have multiple keys in the repository, we can see which is the key currently in use.
A key can also be changed using the “passwd” command. Just be sure to remember the new password. It might be a good idea to create an emergency recovery key.
Once restic is installed it can self-update its binary without the need of a package manager using the following command:
Unlocking the backup repository
Restic does apply repository locks to ensure data integrity within the backup repository. In some cases, it can happen that a server or container crashes leaving the backup repository in a locked state. This is nothing you have to worry about since you can unlock it with the following command:
Just use the command wisely since it also unlocks a repository that is locked by an ongoing backup. This could in the worst case then lead to data corruption. Anyway, if you are sure the repository was locked by an already aborted task you can use this command to unlock the backup repo.
Restoring to any server
To restore data from a backup repository, you don’t need to be on the same server. All you need is restic installed and your restic.sh credentials file.
This is enough to restore the backed-up data to any new server. In case of disaster recovery of a docker server, it would be enough to have all the docker-compose files as well as the docker volumes.
I hope the above example helps to understand what else besides normal backup you can do with restic and how to handle special situations. That was the last of four blog posts about restic. I hope you enjoyed reading it. Let me know if you have any questions.
About the author
Remo Höppli is Co-Founder and Software Engineer at Earlybyte.
Earlybyte is an IT consultancy firm specialized in developing new digital solutions for companies around the world from digitalization to IoT solutions, close to the client and its business embracing agility.
Follow me on Twitter to get informed on new blog posts.