Tuesday, May 1, 2012

UNIX / Linux Dump Command Exclude Directories / Files

I'm using dump command to backup file systems to tape and remote server. However, I'm not able to find any option that will allow me to exclude files or directories from backup. How do I force UNIX / Linux / FreeBSD dump command to exclude selected files (such as /var/cache or /usr/basejails) which I don't want to backup?

First, dump is a physical filesystem level backup program to archive and restore entire dump'ed file system. It is not like your tar or other programs to exclude files from backup. dump command works on i-node number and cannot exclude specific files from the archive. However, there is an option for UNIX UFS and Linux ext3 file system to mark files and directories to exclude from dump program. This is useful to exclude certain directories such as caching directories used by squid proxy (/var/cache/squid) or jail caching templates directories etc.
WARNING! Note the following example is ignored by default on level 0 full dump, and works only at the incremental backups of level 1 and later. If you want this to work on level 0, you should specify h option on the dump command line (see dump command example below)

FreeBSD nodump And dump Flag

The chflags command modifies the file flags of the listed files as specified by the flags operand:
  1. nodump: set the nodump flag
  2. dump: clear the nodump flag

Task: See dump flag on FreeBSD UFS File System

To see current dump flag on directory called /var/cache/squid, enter:
# ls -ldo /var/cache/squid/
Sample Output
drwxr-xr-x  11 root  wheel  - 512 Jun  7 14:51 /var/cache/squid/

Task: Exclude /var/cache/squid/ Directory From dump

Type the following command:
# chflags nodump /path/to/dir
# chflags nodump /var/cache/squid
# ls -ldo /var/cache/squid

Sample Output:
drwxr-xr-x  2 root  wheel  nodump 512 Jun 7 14:51 /var/cache/squid/
To remove flag, enter:
# chflags dump /var/cache/squid
# ls -ldo /var/cache/squid

Sample Output:
drwxr-xr-x  11 root  wheel  - 512 Jun  7 14:51 /var/cache/squid/
Now, to dump full /var file system to /dev/sa0 tape, enter:
# /sbin/dump -0uLf /dev/sa0 /var
To make incremental backups, enter:
# /sbin/dump -1uLf /dev/sa0 /var
By default zero level dumps (full file system) cannot be excluded from dump command. The -h option can honor the user nodump flag only for dumps at or above the given level. The default honor level is 1, so that incremental backups omit such files but full backups retain them. In other words to exclude directories from full backup, enter:
# /sbin/dump -h0 -0ulf /dev/sa0 /var

Linux d Attribute For dump Program

First, you need Linux kernel 2.5.19 and later to work with d attribute. This attribute can be set with chattr command. A file or directory with the d attribute set is not candidate for backup when the dump program is run.

View d Attribute

To list file attributes on a Linux second extended file system use lsattr command:
# lsattr -d /path/to/file
# lsattr -d /var/spool/squid

Sample Output:
------------------- /var/spool/squid/

Set d Attribute

Use chattr command as follows:
# chattr +d /var/spool/squid
# lsattr -d /var/spool/squid/

Sample Output:
------d------------ /var/spool/squid/
To clear d attribute, enter:
# chattr +d /var/spool/squid
# lsattr -d /var/spool/squid/

Sample Output:
------------------- /var/spool/squid/
To start with a level 0 backup, for example:
# /sbin/dump -0u -f /dev/st0 /var
To honor the user nodump flag at level 0, enter:
# /sbin/dump -h 0 -0u -f /dev/st0 /var

No comments:

Post a Comment