backing up a complete (debian) system with tar

The problem is mainly what to not backup, or even how to specify that which should not be included in the backup. This system had an extra harddisk and a usb-stick plugged in mounted under /media. In addition, this system have /exports for nfs4 shares, and /exports had (parts of) /media bind-mounted under it. Also, the target for the backup was a partition of the usb-stick, temporarily mounted under /mnt.

/media/extra_hd on /exports/extra_hd type none (rw,bind)

So, I wanted to exclude contents under the following directories, but include the directories them selves.

/mnt
/exports
/media

In a addition we have the standard dirs that should be included, but without their contents.

/tmp
/dev
/sys
/proc
/lost+found

To include a dir, but exclude any content, use

--exclude='/mnt/*'

To exclude a dir completely:

--exclude='/mnt'

Single or double quotes work equally well:

--exclude="/mnt/*"

Here is what I finally used:

nice -n 19 tar -cvp \
 --exclude="/mnt/*" \
 --exclude="/exports/*" \
 --exclude="/media*" \
 --exclude="/tmp/*" \
 --exclude="/dev/*" \
 --exclude="/sys/*" \
 --exclude="/proc/*" \
 --exclude="/lost+found/*" \
 / \
| nice -n 19 tar -xvp -C /mnt/

To actually run this system from the usb-stick, /boot was not necessary to copy here, since the target of this backup was a LVM-over-LUKS partition - to unlock that one, you still need to boot files from elsewhere. But this post was about tar, not about booting the backed up system.

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: oktober 17, 2019