6 Apps and Tricks to Optimize Your Linux System Backups
When moving to Linux you may notice your version comes with a default back up tool. But it may not be set to back up all the important parts of your system. Furthermore, using the default tool may lead to backups that are bigger and less efficient than they need to be.
Here are some alternate ways to back up your Linux system to make the best use of the storage you have available.
Make Sure You Are Backing It ALL Up
The default tool on Ubuntu desktops, dejá-dup, is only set up by default to back up your home directory. But this leaves out some important things you’ll need to easily restore your system to working order. Think of your system as the following three parts:
Now, you can easily set the default tool to back up all three of the above. But this assumes you have lots of storage, or it might involve shuffling large amounts of data over the internet. The following apps and tricks can help minimize the space you need while still making sure you’re covered in the event of a meltdown.
1. Clone the Partition to Snapshot Your Home Directory
This is the data residing in your user account(s) under the /home/[username] directory. This includes your personal configurations, often stored in files or directories starting with a dot (e.g. /home/[username]/.local) as well as music, pictures, and other files and folders (like the default Documents or Download folders). It’s the data you’ll probably focus on backing up, and the one most often handled out of the box.
A great reason to keep your /home directory on a separate partition is so you can work with it separately from the main parts of your system. If you do so, you can back up your home directory by cloning the entire partition. It can then be restored precisely as you had it at the disk level.
As previously covered , one option for this is dd, which will clone a disk or partition exactly (meaning your backup is the same size as the entire partition). Consider using Clonezilla. It can back up the structure of the disk/partition but omit unused disk space, so your backup is only the size of the actual data the partition contains.
2. Store Home Directory Snapshots on Multiple Machines With File Synchronizers
File synchronizers are a good option for your personal files, especially if you use more than one device. There are almost too many options to name here, but they include simple file-copying utilities such as rsync, online services such as Dropbox , or local/peer-to-peer programs like Resilio Sync . Some of these will offer to track history for you, although it will be for each and every minute change, which can become unwieldy, and waste storage.
3. Use Archiving Tools to Keep Historical Snapshots of System Data
Outside of your home directory, you should definitely consider the following as part of your back up:
- /etc, which contains configurations such as /etc/apt/lists (lists describing the repositories from which your system installs new programs).
- /var, which contains supplemental data used by applications. Examples of this include logs (e.g. /var/log/dpkg.log, where package transactions are logged on a .deb-based system), caches (such as /var/cache/dpkg, where a copy of all packages installed are kept), and /var/lib/dpkg (where the package database is stored).
Standard “archive-style” back up tools can handle these system directories as well. They will typically look at the files in the source directory(s), determine if an up-to-date backup of this file exists, and create/update if not. They can keep multiple copies (i.e. a daily one and a weekly one) and the archives are often compressed to save disk space. There are a variety of options , including programs like dejá-dup or backintime.
You’ll need to set these back up jobs up as root, or use the built-in capabilities of the tool to run with admin privileges.
Then, using these apps (backintime is shown below) you can simply add the directories you want to a new or existing back up job:
By picking and choosing which of these directories you back up, you can score some space savings compared to typical “whole system” backups. Check out this post for tips on what /var sub-directories you may want and which ones you don’t.
4. Use etckeeper to Keep Records of Config Changes
For the /etc directory specifically, the utility etckeeper uses source control to help you back up your important system configurations. Installing it in Ubuntu requires the following command:
sudo apt-get install etckeeper
As part of the installation, it will create a backup (actually, a git repository) and commit all the files under /etc into it.
You can then use any git client to take a look at the history of your system configurations. More importantly, the app also sets up a cron job to commit changes to your configs every day. But most configuration files are created in plain text, and since git (and other source control systems) work off the principle of saving changes line-by-line, the storage of multiple versions can end up being quite small.
5. Use aptik to Back Up Configs and Software Packages
The aptik program wraps up a number of back up/restore tools in a convenient GUI:
Its Installed Software feature will backup the packages you’ve explicitly installed by default — the image below shows that this can be a pretty short list:
Why is it so short? Well, it doesn’t require the base system’s packages, because in order to use this backup you’ll already need a base system installed. And if you install just these few dozen packages, the package manager will take care of installing all their dependencies for you. So your “full software backup” can consume just a few dozen megabytes of storage. Clever, yes?
6. Back Up Your Packages With a Package List
You can do even better than aptik if you’re comfortable with the command line. To make sure you can restore your system at a later time, try this: don’t back up packages at all, but rather capture a package list instead. The following command will export a list of your installed packages to a text file:
sudo dpkg --get-selections > my-packages.txt
In addition to giving you the human-readable accounting (shown above) of the packages on your system, the following commands can reinstall them in bulk:
sudo dpkg --set-selections < my-packages.txt sudo apt-get -u dselect-upgrade
Note that you’ll need to handle programs you’ve installed by hand (probably living in /usr/local and/or /opt) yourself. But otherwise the only difference between your previous and restored system is that everything will be at the newest versions available—probably what you want anyway. And all this for the price of a measly few thousand kilobytes.
Remember, you aren’t limited to using just one of the above. Combine as many as you need to make sure that if the worst happens, you’ll be back up and running quickly.
Do you use any of the above tools above to help with backup duties? Give us your kick-butt backup tips below in the comments!
Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.