UNIX / Linux Dump Command Exclude Directories / Files

by on June 11, 2009 · 3 comments· LAST UPDATED June 20, 2009

in , ,

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

Further Readings:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 Ahmad June 13, 2009 at 5:54 am

Thanks for this cool tip

Reply

2 Peter Yardley August 10, 2009 at 10:11 pm

Clearing the attribute should be

chattr -d /var/spool/squid

The ‘+’ adds the attribute(s), ‘-‘ clears it/them, ‘=’ makes it/them the only attribute(s)

Reply

3 sarfraz December 20, 2009 at 10:48 am

Hi,
we are using sunsolaris 2.6 dababase server , i need to get dump file, our file size could be
14GB so when am trying to execute exp command to get the dump file, its start executing
but when the file size reach approx 2GB then the execution terminated, means i can not get dump file completely successfully. i think the operating system dont allow to make the file having more than 2GB on the server. so give me any solution to get the complete dump file successfully.
Note : you can send the soultion on my give id “mdsarfrazahmad@gmail.com”

Thanx & Regards
Sarfraz

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: