PREMISE
For most computer users, it's important to have a plan for creating backups, and most folks already know that. Just how important depends on two factors: what you use the computer for, and how easily you could return a compromised computer to a good working condition. There are many approaches available for creating a backup, and later to restore it. In this document, I'll suggest one popular backup tool for Linux, and discuss how easy it is to use.
SOFTWARE
Not every backup package will run on every Linux system. A good one that is available on Solus is called Restic. To install it on your computer, just use this command at a terminal: sudo eopkg it restic
. The package installs quickly, and it provides both backup and restore capabilities. For more details, check out https://restic.net .
INITIALIZING REPOSITORIES
Restic requires you to create a destination for your backups, called a repository. That just means that you need to create a directory and initialize it for that use. Books have been written on backup strategies, and I don't plan to do that here. I'll just mention that the repositories you use should not be on the same drive that you're backing up. Here's where those two factors I mentioned in the premise above come into focus.
If you're doing critical work with your computer, the very best place to create that repository is on a computer that's located in another building. That might be in the IT department of a head office in another city, or "in the cloud," such as Google's, Microsoft's or Amazon's. For personal use, where computer failure might be more of an annoyance instead of a financial catastrophe, it could simply be located on a different computer in the same building.
I'm a proud geek, but a retired one. My computers support my hobbies, chatting with family and friends, and exploring interesting new computer languages or playing time-wasters like Mahjongg or Shisen-sho. If my house were to burn down, the loss of my emails and browsing data would be way down on my list of things to worry about. And most software could be fairly easily replaced and installed on a new computer. So I use a file server in another part of my house to store backups. Actually, it's a NAS (Network Attached Storage). Its shares are mounted on all the computers here: my wife's laptop and her desktop, my laptop and workstation, a travel laptop, a media machine for streaming TV, and a general-purpose server I plan to expose to the Internet so that family members in remote locations (e.g., Sicily) can easily access it.
How to mount remote shares on a Solus computer would be a good topic for another tutorial, so I'll resist the urge to dive into that here, but I will point out that mine are mounted to /mnt/Backups/Linux
and /mnt/Backups/Windows
. I name the directories I've created there with the host name of each computer they correspond with. Thus, for one example, the repository for my main laptop is located at:
/mnt/Backups/Linux/malachite-solus-4-1-budgie
INITIALIZATION
Having created a directory where you want to save your backup, the next step -- done only once -- is to turn that ordinary directory into a Restic repository. At a terminal, use the command restic init -r
respository, where repository is the path to the directory you created. For example, in the case of my main laptop, it would be:
restic init -r /mnt/Backups/Linux/malachite-solus-4-1-budgie
.
To recap an important point, this needs to be done just once, but it must be done before Restic can save a backup there.
BACKUP COMMAND
Backing up your home directory to the repository you've created requires a command that's almost as simple as that init
command. Naturally, you need to provide not only the destination for the backup, but also where it's coming from. Continuing with the laptop example, the command to back up my profile would simply be:
restic backup /home/jerry -r /mnt/Backups/Linux/(you get the idea)
Since I backup a number of computers frequently, I've created an alias in my .bashrc
file to make that easy. It looks like this:
alias backup='restic backup /home/$USER -r /mnt/Backups/Linux/hostname
'
(Note, I didn't format that as code because I use those left-quote characters for my alias.) Thus, before a weekly package update, or any other time I need to create a backup, all I need to type in a terminal prompt is backup
. The result of that command will look like this:
# backup
enter password for repository: <password>
repository 32cade9a opened successfully, password is correct
Files: 7580 new, 2300 changed, 155343 unmodified
Dirs: 0 new, 1 changed, 0 unmodified
Added to the repo: 7.320 GiB
processed 165223 files, 38.300 GiB in 4:13
snapshot 4f4ba715 saved
This backup is rather large, because there are two Solus virtual machines hosted by this laptop, and those are stored in my home directory as well.
Notice two other things about this output: The first response from the backup
command is to ask you for a password for the repository. That's the password you assigned to it during the init process. And the last line of output identifies the snapshot that you just saved. You'll need that in order to restore this backup.
SUMMARY
This is where the Strategy in the title of this document comes into play. I've described how to get a backup tool, and how to use it to back up a home directory. Using this information, you may need to modify how you use it, depending on where your backups are stored, how important your data is, and so on. Feel free to modify these suggestions to fit your own situation and equipment. Restic is very versatile, as you can appreciate if you run the command: restic -h
.
You might ask, "What about restoring a backup?" I won't go into that here for two reasons. First, I've never needed to restore a Restic backup, and I may never need to, so I've not yet created an alias to do that. (Besides, you're probably as tired of reading by now as I am of typing.) Obviously, if you don't have a backup, it doesn't matter how they're restored. Second, I do know that restoring a Restic backup is as easy as creating it in the first place. If the time ever comes when I need to restore one of my backups, I already know exactly where to find the syntax to do that. You can use the command: restic snapshots
to list all the snapshots in a repository. Use the identifier to indicate which snapshot to restore. Again, use Restic's excellent help for more details.
EDIT: Apologies for the way discuss screwed up the formatting I used. The original I typed looked a lot better!