Making Backups Easy

How to keep your system reasonably safe and distro-agnostic.

Kobi Rosenstein
Aug 12, 2020 · 3 min read

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:

bin/bash
BKPDIR=~/Backups/daily_backup_`date +%d-%m_%Y`/
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 \
--exclude='BlackmagicDesign' \
--exclude='Image-Line' \
--exclude='ExpedaHours' \
--exclude='rundeck' \
--exclude='Postman' \
--exclude='Screenshots' \
~/scripts \
~/eBooks \
~/Documents \
~/Pictures \
~/Dev

GZIP=-9 tar -czvf $BKPDIR/config.tar.gz \
~/.config \
~/.ssh \
~/SoftMaker \
~/Templates \
~/.p10k.zsh \
~/.zshrc \
~/.aliases \
~/.davmail.properties \
~/.vimrc \
~/.bashrc \
~/.gitconfig

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.

Kobi Rosenstein

Written by

Devops DBA. This blog chronicles my “gotcha” moments — Each post contains an answer I would have like to have found when searching for those pesky errors I get.

For Linux Users

If you use Linux from the command line or from a GUI, we want to help you get the most from it. Look for tutorials, software reviews, and more. Using WSL or Cygwin? We got you covered. Some software topics will apply to any platform (e.g,. Chrome, Google Docs, etc.).

Kobi Rosenstein

Written by

Devops DBA. This blog chronicles my “gotcha” moments — Each post contains an answer I would have like to have found when searching for those pesky errors I get.

For Linux Users

If you use Linux from the command line or from a GUI, we want to help you get the most from it. Look for tutorials, software reviews, and more. Using WSL or Cygwin? We got you covered. Some software topics will apply to any platform (e.g,. Chrome, Google Docs, etc.).

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