abandoned bytes
Engineering: the art of making what you want from things you can get.

Backup with dump

May 15, 2009

dump is a rather aged, but still very useful Unix tool for backuping ext2 and ext3 filesystems. I use it for complete backup of my home partition, which is useful to restore it completely after a disk crash, stolen laptop etc.

For those who don't want to read the whole manpage to grasp how to basically call dump, a short explanation:

dump -3u -h 0 -f - /home | gzip > /path/to/backup/directory/backupfile.dump.gz

The first number, 3 here, is the dump level used for incremental backup - you need to increase it every time if you only want to do incremental backups (which I do daily); the appended -u means "update the list of backups". The -h 0 option tells dump to "honor the nodump flag", meaning that files marked with the attribute "nodump" will not be backuped at dump levels at or above 0 (hence, they are never backuped - I use this flag for videos, pretty pictures and other files I don't need essentially). See later for the dump flag.

The -f - tells dump where to store the backup file, which in this case is the standard output (-). The final parameter is the file system (device or mount point) which will be backuped.

I let dump output to the standard output, which I pipe into gzip to get the backup file a bit smaller. I use an NFS mount point for the target backup file, which means the file is stored on my server. You could, of course, give a filename after -f, and omit the piping to gzip.

nodump flag

This is an ext2/3 filesystem attribute, which is used by dump (when you tell it to) to determine whether a file or directory needs to be backuped at all. I use this to flag files and folders that are not essentially needed, but are rather large, like videos or picture folders. The attribute is set with:

chattr +d <file or directory>

You can also clear the attribute with the same command using -d. You can also view ext2/3 attributes with:

lsattr

The syntax of the lsattr command is quite similar to the syntax of the well-known ls command.

Shell script

You should do a full backup every so often, otherwise you will need ALL backup files to restore completely. You will also need to do a full backup before being able to backup incrementally. You can do a full backup with -0u (use the full argument to the script).

Below I present a small shell script I use for daily incremental backup. The basic idea is to count the backup number automatically, and to create backup files with the backup date appended to a prefix. Use the script at your own regard:

#!/bin/bash # LAST_BACKUP="/etc/last_backup" BACKUP_PATH="/mnt/public/David/_bak/laptop" BACKUP_MOUNTPOINT="/home" sudo smbmount //LINUX/PUBLIC /mnt/public sudo umount "$BACKUP_MOUNTPOINT" if [ "$1" = "full" ]; then if sudo dump -0 -u -h 0 -f - /home | gzip > "$BACKUP_PATH/home-full-`date +%Y-%m-%d`.dump.gz"; then echo 0 | sudo tee "$LAST_BACKUP" > /dev/null exit 0 fi exit 1 fi lb=`cat "$LAST_BACKUP"` nb=`expr $lb + 1` if sudo dump -$nb -u -h 0 -f - /home | gzip > "$BACKUP_PATH/home-`date +%Y-%m-%d`.dump.gz"; then echo $nb | sudo tee "$LAST_BACKUP" > /dev/null fi sudo mount "$BACKUP_MOUNTPOINT"
Last modified: September 07, 2009

Comments

Mark M., February 05, 2010:

This is valuable and well written. Thank you.

Claudio, August 04, 2010:

Cool to hear about that ancient tool for backups.

My former setup has been Unison for essential stuff (between two machines) and kdiff3 for the large and less important stuff. That was fun.

Still dumping? ;-)

David Madl, August 04, 2010:

Cool to hear about "new" approaches :-)

When I first wanted to simplify backups, I was just looking for some simple solution - the Unix-philosophy-compliant dump tool was the perfect match.

I'm starting to abandon dump as almost all of my work is now stored within some kind of revision control system (git is my favourite) and they synchronize well with other machines.

Write a comment

The fields e-mail and website are optional. Your e-mail-address will not be displayed, it's only for me to be able to reply.

Name:
E-Mail:
Website:

Fill in the CAPTCHA to prove you are human:

© 2009 by David Madl. Impressum | Home (English) | Home (Deutsch) | Processing time: 0.485 s

abandoned bytes (en) > Software > Linux stuff > dump backup
User:
Pass: