Linux / UNIX: tar Command Stay In Local / File System When Creating Archive

I‘d like to make / file system backup but the problem is there are other file systems mounted under / such as:

/mnt/cdrom
/mnt/nfs
/iscsi
/boot
/var

I’d like to skip all other file systems mounted at / and only make backup of local / and not /boot, /var, /iscsi, and /mnt/cdrom etc. How do I force tar to use a single file system under Linux / UNIX / BSD operating systems?

The –one-file-system option ask the tar command not to cross mount points and stay in local file system when creating / updating archives. The syntax is as follows:

tar zcvf /path/to/file.tar.gz  --one-file-system fileSystems
tar zcvf /path/to/file.tar.gz  --one-file-system /

In this example, make a backup of / file system to /dev/st0 without crossing file system boundaries, enter:

tar cvf /dev/st0  --one-file-system /

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.