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?

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

Use the appropriate tar command line option:

              stay in local file system when creating archive
  • But it doesn't work for mount --bind /var/www/folder /home/user/html – user2984570 Dec 16 '13 at 19:37
  • Are you saying that files appearing under /home/user/html still end up in the archive? – Michael Hampton Dec 16 '13 at 19:45
  • yes it seems like this is the case – user2984570 Dec 16 '13 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. – user2984570 Dec 16 '13 at 19:56

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.

  • GNU tar doesn't like the first way – Michael Dec 11 '18 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.