How to backup your application settings
by Igor Ljubuncic on 28 February 2019
A reliable data backup plan should be an integral part of everyone’s software arsenal. If you accidentally delete your files, or something goes wrong in your setup, you will have your data safely stored in another location. This will allow you to recover quickly and resume working. Likewise, if you suffer a hardware failure or lose a device, you vital data will still be available and intact.
Data loss is a function of time. It is not the question of if, but when. Unfortunately, few people place sufficient emphasis on backups. In this article, we’d like to show you how you can safely and elegantly protect your data with regular backups, including your application settings.
When people think about backups, they usually think about the files they typically work with, their music collection, some office documents, maybe a photo album or two. But there’s much more to it. Backups come in three major flavors – system imaging, application configuration backups, and data backups.
- Imaging allows you to create a snapshot in time of your operating system, which you can then revert to at a later point. Restoring an image means any change introduced to the system after the snapshot was taken will be lost if you revert back to the previously created image.
- Data backups essentially mean copying your personal files, like documents, photos and other content to other media, both offline and online.
- Application configuration backup is the trickiest of the three, as it sits between the system and personal data. On one hand, it’s not system data, because it depends on the user’s choice of software. On the other, it’s not strictly personal data, because people do not directly interact with their application settings. And yet, the customization and different options we use in applications do represent personal information, and losing those can be painful. If you’ve ever needed to set up a brand new system, configuring a dozen programs from scratch to look and behave just the way you like them can be a pain.
The simple answer to that need is – backup your application settings.
In Linux, this is both easy and hard. If you backup your entire home directory, you will have effectively backed up your application settings, too. But if you only want to save the application data and not the rest of your personal files, there isn’t an immediate way to accomplish this, like you would do on a typical smartphone (where you can backup configurations relatively quickly with a single tap of a button).
The main reason for the complexity comes from the fact there is no standardized location for all applications to save their settings. Some software will place their configurations into a hidden folder or a file inside your home directory, often named after the application itself. For instance, a Firefox profile will be kept under ~/.mozilla. Then again, Thunderbird keeps its data under ~/.thunderbird. Some applications use less clearly named folders, like ~/.purple for Pidgin. Many other programs will store their configuration inside ~/.config. This is manageable, but not obvious. And it can create some difficulties if your goal is to backup only your application settings for a future install.
The manual way
If you don’t want to rely on any third-party tools, you can create your own backup script, and then execute it opportunistically or run it as a scheduled task via cron. You can use the cp command for the task, but with this method, you will only copy new files and overwrite existing files, but you will not be able to delete files in the destination (backup) folder.
A more convenient way is to use the rsync program, which has many useful flags and options. It can preserve permissions, mirror the folder structure and contents, and has a dry-run feature to lets you simulate a backup before you set it up in earnest. For instance:
/usr/bin/rsync -a /home/foo/.bash* /backup/
This command will run rsync in the archive mode, copying all the BASH shell configuration files into the backup folder.
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
The archive mode means rsync will recurse all directories in the specified path, copy symlinks, preserve file permissions, owner, groups and modification times, as well as preserve device and special files. The combination of these options make the archive mode quite useful for backups.
You can extend the backup script to include multiple rsync commands, or use exclude and include patterns to fine-tune the backup procedure. Furthermore, you can use the –delete flag to delete any file in the destination that does not exist in the source, effectively creating a mirror backup.
/usr/bin/rsync -a --delete /home/foo/.bash* /backup/
The manual process can be tedious, but it is a good way to learn and understand the structure of folders and application settings in your home directory. Moreover, you have full control of the script, and you are not limited in what you want to do.
The automated way – mackup
If you are not keen on scripting yourself, you can use existing tools to do the hard work for you. A very convenient software designed to specifically backup your applications is mackup.
This is a versatile, intelligent tool designed to make application settings backup fast and elegant. Currently, mackup supports more than 400 common applications. Mackup also works with cloud backends, including Box, Copy, iCloud, Google Drive, Dropbox, and any other provider capable of folder sync. Mackup is available in the Snap Store, so just grab it:
snap install mackup --classic
Once the program is installed, the next step is to create a configuration file ~/.mackup.cfg, and then populate it with your desired backup options. If you do not, you will get an error:
Error: Unable to find your Dropbox install =(
For instance, if you want to backup to a local folder called backups, then you would use something like
engine = file_system
path = /home/foo/backups
You will need to create the target folder (the mackup directory will be created inside it). You can customize the name of the mackup directory name, backup only a subset of applications, exclude certain applications, and more. Once you’re happy with the configuration, you can dry-run and test (with the -n option), and finally run the script in earnest:
In the verbose mode (-v), you will also see the details of the run, including all the applications that were not backed up, because the specific folders do not exist. This can also help you rectify any gaps in your backup setup. For instance:
is already backed up to
does not exist
is a broken link, you might want to fix it.
does not exist
If you want to restore settings, you can run:
Mackup is practical utility that can save you a lot of trouble and time in having to manually organize your data. The fact it is a command line tool also allows you to include it in your scripts and scheduled runs. A great little addition that goes into the toolbox for a rainy day.
If you have any questions or suggestions regarding backups, application settings or mackup itself, please join our discussion forum.