My latest blog post on how I use Borg to backup my self-hosted services unintentionally ended with a cliffhanger, like the best TV Shows:
Finally, you can’t say you have a backup until you successfully restore your backup! Don’t skip this step or everything will be useless.
Ok Paolo, thanks for the advice, but how?
Go back in time
When using Borg you’ll probably end up having different revisions of your backup. One of the best selling point is that Borg backups are incremental and having daily, weekly, and yearly checkpoints makes it very robust at a low cost.
First of all, how do I check the available revisions in a Borg repository? Easy peasy, just run borg list. A simple example, without passing any extra arguments, would result in something like this:
$ borg list <MY-REPO>
Enter passphrase for key: <MY-PASSPHRASE>
ubuntu-2023-12-24T03:00:02.564940 Sun, 2023-12-24 04:00:04 [<SHA>]
...
ubuntu-2024-01-07T03:00:03.450590 Sun, 2024-01-07 04:00:05 [<SHA>]
where you can see the ID of each backup (ubuntu-2023-12-24T03:00:02.564940), the date and time (Sun, 2023-12-24 04:00:04) and the checksum. Many other arguments are available, check them out in the man page.
Now that I know the available revisions, how can I check in which one that accidentally deleted picture is available? Borg lets you mount it, like a storage or network device, using FUSE.
$ sudo borg mount <MY-REPO>::<MY-REV> <MOUNTPOINT>
Enter passphrase for key: <MY-PASSPHRASE>
$ cd <MOUNTPOINT>
...
$ sudo borg umount <MOUNTPOINT>
Mount a revision, take a look at what’s inside, and umount it.
I hope you’ve found what you need at this point. It’s time to restore it!
Restore
If you want to restore just a bunch of files, copying from the mount point is already sufficient and probably the quickest solution. But if you’re storage device died, you upgraded your server or you just want a clean start, it’s time to restore the whole content with borg extract.
$ borg extract --list <MY-REPO>::<MY-REV>
Enter passphrase for key: <MY-PASSPHRASE>
...
By default the command extracts the whole content of the backup but you can pass a list of paths to restrict what it will download. I suggest running the command with --list
and --dry-run
a few times to check what the result would be without actually downloading the content until satisfied.
This was just a quick overview of the list, mount, and extract commands: check the official documentation for more details if you’re interested. No cliffhanger this time, ciao!