Backup modified config & system files on Linux

cool_penguin_smallIf you love to tweak your Linux system on the go, you probably have a lot of modified (and added) configuration and system files. What if you want to take a backup of those files before doing an upgrade? There are simple ways to accomplish things on Linux without installing new packages. Here’s what I do.

  • Maintain a list of modified files in a plain text file, each entry separated by a newline. Whenever you modify a file, add it to this list. Use absolute paths so that it’s easy to replace the files when restoring (you’ll see). Here’s an example list:
    $ cat list.txt
  • Save the following shell script in a file:
    BACKUP_DIR=backup-$(date "+%Y_%m_%d_%H_%M_%S")
    mkdir $BACKUP_DIR
    cat $1 | xargs cp --parents -t $BACKUP_DIR
    cd $BACKUP_DIR
    tar -jcvf ../$BACKUP_DIR.tar.bz2 *
    cd ..
    rm -rf $BACKUP_DIR
    echo -e ${lt_red}Backed-up in $BACKUP_DIR.tar.bz2
  • Make it executable:
    $ chmod +x
  • To take a backup:
    $ ./ list.txt

    The script is in verbose mode to show every file being backed-up. It will show the final archive name in light red.

  • The directory structures are preserved. So you can restore all the files using:
    $ tar -xvf backup-timestamp.tar.bz2 -C /

This is a basic script. You can modify and extend it to meet your needs. It does need manual entry into the list of files. But on your box you are the best one to choose what you want to save.

One thought on “Backup modified config & system files on Linux”


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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s