Backup Configurations with tar Helpers

Update: This article has been supplanted by The Beauty of rsync and Backup Script.

When I have to do a reinstall, sometimes I have to install from scratch – doing a clean install is just sometimes necessary. My configurations are priceless to me and after my reinstall I restore them from a backup copy. Here’s how I quickly add my configurations to an include file and back them up on a regular basis done with a basic script.

Basic tar Command

A good number of GUI programs can do this (you can read about the ones I’ve looked at here), but they seem to make the process more complicated, so I went back to tar and created a script. And it makes adding and subtracing files easy. For those new to tar the basic archive command is:

tar -c --xz -f <backupname>.tar.xz /folder/file /folder ...

Include/Exclude Files

By putting the archive command in a bash script it can be used later. Files and folders can be appended to the command in the script but for multiple files consider using include and exclude files:


tar --files-from=include.txt --exclude-from=exclude.txt -c --xz -f backupname.tar.xz

Include/exclude files contain the path on a line of what or what-not to backup. The include file should list the full path and cannot use regexps but the exclude fine can:


Add Paths to Include/Exclude Quickly

To add paths to the include/exclude files readlink can be used. Adding to the include and exclude files can be done like this (using the script below):

$ bckcfg i /etc/rc.conf 
 Added "/etc/rc.conf" to bckcfg include file.
$ bckcfg e ~/.thumbnails/
 * "bckcfg" doesn't check if patch is correct because the exclude file can
 contain regexps.  Be sure the path is correct (e.g. '/mnt/win/*')
 Add "/home/todd/.thumbnails/" to bckcfg exclude file? (y/n): y
 Added "/home/todd/.thumbnails/" to bckcfg exclude file.

Creating notes of backups can be done by:

$ bckcfg n Added font config
$:cat bckcfg-not.txt | tail -n 2
20xx-08-14-02:52:23 PM: Added dhcp cacher config
20xx-08-14-02:52:33 PM: Added font config

The Backup Script

To backup do:

bckcfg c

The script names the backup by several definable variables and removes old backups if desired.

Consider putting it in a cron job to get regular backups.


About Gen2ly

<3's linux

Posted on 2009-07-18, in Command Line, Linux, Script. Bookmark the permalink. 2 Comments.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 58 other followers

%d bloggers like this: