5

we want to backup our server and this seems to be pretty simple thing to do except one. Currently we use something like this:

tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

Everything is fine, but we do not want to include mount points, as several ftp users has chrooted access to their homes with mounts like:

mount --bind /var/www/folder /home/user/html

Is the any way to exclude such folders from being backuped?

2
  • 1
    Does --one-file-system do what you're looking for?
    – user143703
    Dec 16, 2013 at 18:49
  • @yoonix: My thought exactly. Only issue would be maybe an external device? Dec 16, 2013 at 18:50

2 Answers 2

8

Use the appropriate tar command line option:

       --one-file-system
              stay in local file system when creating archive
4
  • But it doesn't work for mount --bind /var/www/folder /home/user/html Dec 16, 2013 at 19:37
  • Are you saying that files appearing under /home/user/html still end up in the archive? Dec 16, 2013 at 19:45
  • yes it seems like this is the case Dec 16, 2013 at 19:53
  • What about this approach? mkdir /mnt/root mount --bind / /mnt/root -o ro tar -C /mnt/root -c . (...) It seems this excludes all mounts from the system. I'm not really sure if it is the best solution though. Dec 16, 2013 at 19:56
2

The option --one-file-system does work, it just needs some very specific syntax.

tar -cvzf /mnt/backup.tar.gz --one-file-system /

works, but

tar --one-file-system -cvzf /mnt/backup.tar.gz /*

does not. This is probably because shell globbing will result in the option being applied to each and every subdirectory of / individually. So /proc gets included because everything in /proc is indeed one file system.

2
  • GNU tar doesn't like the first way
    – Michael
    Dec 11, 2018 at 16:42
  • I fell into the * glob trap with this initially. cd /ing into the root directory first and then passing . to tar seems to work, and the --one-file-system option appears to skip mount points.
    – pmdj
    Feb 18 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .