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

last updated in Categories , , , , ,

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


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: Vivek Gite

The author is the creator of nixCraft 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.

8 comment

  1. Old habit for me is rather than using absolute pathname for root, you cd there and use the relative pathname “.” instead. Old versions of tar would restore the file exactly as it was created in the archive, so if you did this:

    tar cvf /dev/st0 /

    it created a tar file that could only be restored in /. Whereas if you do this:

    cd /
    tar cvf /dev/st0 .

    you get a tar file that can be restored anywhere (including root as long as you cd there first).

    Yes, many versions of tar have fixed this and Linux strips leading /s by default, but unless you’re sure and there’s no chance you may ever take your tar file to another machine (say an old Unix box), this is an easy way to be sure.

  2. I seem to recall if you explicitly call a directory, tar will ignore your one-file-system argument for that case.

    Ie if you execute
    tar cvzf /path/to/file.tar.gz --one-file-system /*
    You’ll end up with /sys and /proc et al, because you globbed them in!

    Definitely test it before you send it after 1TB of data…

  3. would like to put my root to tape on the hp dds-4c5718A. using the unix command, how do i do it. when using the tar cvf /dev/st0 /* and Iam getting an error message
    tar: Error exit delayed from previous errors.

  4. How to tar below filesystem in AIX and copy to another server
    /opt/db2/ – 2GB
    /opt/db2/data1 – 4GB

    when I tar /opt/db2/ , its considering 2+4=6GB.

    Still, have a question? Get help on our forum!