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

Further Readings:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Ahmad Jun 13, 2009 @ 5:54

    Thanks for this cool tip

  • Peter Yardley Aug 10, 2009 @ 22:11

    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)

  • sarfraz Dec 20, 2009 @ 10:48

    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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum