CODEX

Restic Backup IV — Real-life examples

Remo Hoeppli
Mar 22 · 5 min read
Photo by Jay Heike on Unsplash

TL;DR

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

Restic Backup I — Simple and beautiful backups
Restic Backup II — In action
Restic Backup III — How to setup
Restic Backup IV — Real-life examples (this post)

Forgotten snapshots

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:

restic recover to create a snapshot of the whole backup repo

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:

two starting point snapshots

We create a third and fourth one also containing a file called “c”.

the third and fourth snapshot are identical

We call the “recover” command and get a fifth special snapshot containing three roots with the following files:

Three roots (a), (a,b), (a,b,c)

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.

new recovery snapshot

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:

mounting the whole backup repository to the filesystem
mounting the backup repository

We can now open another terminal and just browse the whole backup repository:

tree of all snapshots in the backup repository

Changing passwords

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:

restic key commands
adding a new key

When we have multiple keys in the repository, we can see which is the key currently in use.

removing a key

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.

changing a key

Self-updating restic

Once restic is installed it can self-update its binary without the need of a package manager using the following command:

restic self-update feature
restic self-update feature

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:

unlock a locked backup repository

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.

install restic via apt
restic repository credentials

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.

Last Words

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.

Remo Hoeppli

Written by

Remo Höppli is co-founder and software engineer at Earlybyte. He is a technology enthusiast and minimalism advocate striving for simplicity and efficiency.

CodeX

CodeX

Everything connected with Tech & Code

Remo Hoeppli

Written by

Remo Höppli is co-founder and software engineer at Earlybyte. He is a technology enthusiast and minimalism advocate striving for simplicity and efficiency.

CodeX

CodeX

Everything connected with Tech & Code

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store