Making Backups Easy
How to keep your system reasonably safe and distro-agnostic.
Okay look, we all love Linux as our daily driver. We love to flout how great it is. After all, Linux powers the vast majority of all webservers in the world, so certainly it is robust…
Well, here’s the thing. Every self-respecting sysadmin has good backup policies for a reason. Disasters DO happen, it’s as much a fact of life as death, taxes, and people saying that Windows is so awesome. We all know someone who asked us to fix their pc after a mysterious crash on their work laptop which has TONS of important stuff on it that they NEED. Linux, unfortunately, is no exception, and this is especially true for desktop Linux, where the chance of a dumb end user (read, Yours Truly) screwing up a graphics driver or network manager or something is all too high.
Therefore, every smart user should implement backups on their computer. You could install a tool to manage this for you, but at its core, a backup just needs to include whatever files you need to move to a new system with minimal effort. This can include a reinstall of your current distro, an upgrade, a downgrade, a different distro, your next computer, your dog/cat/drinking buddy, or whatever. You should never have to worry that a different system will take ages to set up.
That’s why I have a small script which creates daily backups of my most important files and configurations, why I keep a text file with installation instructions for all my most used apps (from git clone and cmake to apt install, I copy my commands to this file every time I install something and then I can usually just run it, or make minor edits, and I’m good to go on my new system), and why I keep my home folder structure very clean and organized. (That last bit makes it very easy for me to specify what I want backed up and what I don’t care about.)
I’m sure you know this, but on most distributions, all app-related settings are saved in
~/config . So that’s a good idea to backup. Same with your dotfiles. (Thos are the ~/.bashrc, .vimrc, .history, and the like). Then it’s just whatever actual files you have. You could simply take your entire home directory, but that is often overkill, especially if you plan to upload your backups to online storage. (I don’t. I know, I know, practice what you preach, but in my experience, just having a tarball on my filesystem is almost always available for copy to a USB stick, even if it means booting a live USB to access the files. Of course, I just copy the folder to external storage before attempting anything I deem risky.) SO, my script lets me finetune what I care about.
I’ll attach a link to my git so that if I change it, anyone reading this in the future can use those changes too, but this should be good enough for anyone who just wants to backup some files:
mkdir -p $BKPDIR
# All of the excludes are relative to ALL of the folders to backup - EG, if I have a Postman folder in ~/scripts and in ~/eBooks, both will be excluded.
GZIP=-9 tar -czvf $BKPDIR/files.tar.gz \
GZIP=-9 tar -czvf $BKPDIR/config.tar.gz \
This way, I keep my tarballs small and manageable. You could also add a command to automatically clean older backups, but I don’t bother. If I’m running out of space I just manually delete the entire backup folder and make a new one right away.
You can find the latest version of the script here.
Keep your files safe, keep your head free of worry, and keep on learning! Never be afraid to bork up yum or apt again. And like this, even if you somehow mess up everything, a quick reinstall is super easy and painless.