CODEX

Restic Backup II — In Action

Remo Hoeppli
Mar 8 · 5 min read
See restic in action

TL;DR

This blog post is the second of four posts about restic, a simple, beautiful, and extremely versatile file backup solution. I show how restic looks like in action give a brief overview of its core functions such as backing up, handling tasks on the backup repo, finding the right files, and restoring them.

The restic blog post series

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

Restic in action

People that are used to work with the command line in Linux will feel very familiar when using restic. In fact, its usability is so close to one of the normal command-line tools such as “ls”, “diff”, “cat” and others that it can be used intuitively almost without reading any documentation. It just feels as everything was in its place.

Configuration via environment variables

To avoid entering information such as the repository, the repository credentials, or the encryption password, again and again, I suggest making use of environment variables. To do so, I prepared an executable shell script to export the values needed in a file called “restic.sh”.

In this case, I am using a self-hosted Minio S3 storage to which I will back up my server. To use this file, make it executable and export the values to your environment using the following command (./restic.sh only will not work):

Creating the repository

Once we have exported our environment variables, we can initialize our repository on the S3 storage. We do so by using the following command:

initialize a repository

That’s it. We have a repository on our S3 storage that is encrypted with our password.

Backing up

Once our repository is initialized let’s start our first backup by using:

create a backup
restic backup command

Yes. Again. That’s it. Restic is ridiculously simple to use and that is just awesome. If we want to schedule it we just create a cron job. Surely there is more we can do. Let’s assume we want to add a tag to better tell the different snapshots apart. We create a tagged backup by using:

create a tagged backup

Or we just add and remove tags from already existing snapshots:

add and remove tags

I guess you are getting a feeling why I mention easy that much in this blog post series. Using restic just feels as natural as breathing air.

Repository operations

Viewing snapshots

At some point, we certainly not only want to backup data but have a closer look at what is actually saved in the repository. We can list all the snapshots available using:

show all snapshots in a repository
restic snapshots

Additionally, we can make use of the tags to filter the output of our snapshots list:

restic snapshots filtered using tags

Viewing stats

Further, we might want to know more information on how much data we have backed up in our repository or how big a certain snapshot actually is. This can be achieved using the “stats” command:

show the stats of the repository or a single snapshot
restic stats

Checking the repository

As already mentioned, restic also provides a feature ensuring file integrity in the repository. We can do this with the check command:

check the repository for integrity
restic check

Finding files in your backups

To show all files backed up in a restic snapshot the “ls” command can be used:

list all files from a snapshot
restic ls

To find a specific file we can grep for it as we would using the normal ls command in the shell.

restic ls -> grep

Getting the difference of two snapshots

To tell what files differed from one snapshot to another we can make use of the “diff” command. This way we can easily find files that were changed, deleted, or newly created in between two snapshots:

show the diff between two snapshots
restic diff

Forgetting and pruning snapshots

With the “forget” command we can forget single snapshots.

forget a snapshot

Instead of defining a certain snapshot, we can make use of policy to forget old snapshots.

forget policy flags

If we want to see what would be deleted when using the forget command, we can make use of the “dry-run” flag:

forget all snapshots but one, dry run mode
forget dry run output

The data chunks of the forgotten snapshots are still kept in our repository and can be definitely deleted using the “prune” command.

prune to delete unreferenced data chunks

Restoring files

Using the “restore” command we can restore whole snapshots or single files from a snapshot.

restore a whole snapshot
restore certain files from a snapshot

Instead of specifying the snapshot id, we can also use the “latest” shortcut to restore from the latest snapshot.

restore from the latest snapshot

Last Words

I hope these examples could demonstrate that restic is very easy to use and amazingly powerful. In my next blog post, I will show how we can setup restic using a self-hosted Minio S3 server running on docker and the resticker docker image. In the last post of these four posts series, I will show what else restic can do in real-life examples. Thanks for reading!

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.

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

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