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 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:
That’s it. We have a repository on our S3 storage that is encrypted with our password.
Once our repository is initialized let’s start our first backup by using:
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:
Or we just add and remove tags from already existing snapshots:
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.
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:
Additionally, we can make use of the tags to filter the output of our snapshots list:
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:
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:
Finding files in your backups
To show all files backed up in a restic snapshot the “ls” command can be used:
To find a specific file we can grep for it as we would using the normal ls command in the shell.
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:
Forgetting and pruning snapshots
With the “forget” command we can forget single snapshots.
Instead of defining a certain snapshot, we can make use of policy to forget old snapshots.
If we want to see what would be deleted when using the forget command, we can make use of the “dry-run” flag:
The data chunks of the forgotten snapshots are still kept in our repository and can be definitely deleted using the “prune” command.
Using the “restore” command we can restore whole snapshots or single files from a snapshot.
Instead of specifying the snapshot id, we can also use the “latest” shortcut to restore from the latest snapshot.
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.