3
tar cvf backup.tar  -C /  /   # or
tar cvf backup.tar    /

produces an archive like

etc/

and gives warnings

tar: Removing leading `/' from member names
tar: Removing leading `/' from hard link targets

on the other hand

tar cvf backup.tar  -C /  . 

produces an archive like

./etc/

and gives no warnings. I got the last one from a Debian tutorial.

Which is best for a system backup, do they work exactly the same?


Is there no difference between tar -tvh producing

./etc/

from an archive

and tar -tvh producing

etc/

from an archive

?

2
  • I don't see that using execve precludes you from using shell commands. Couldn't execve call /bin/sh with option -c followed by a command line that includes pipes, globs, or whatever else might be needed to create the tar file the way you want? Jan 25, 2011 at 19:23
  • Had I been using Unix only, it would have been acceptable. But utility must be portable, and sh doesn't exist on Windows, for example
    – Daniel
    Jan 25, 2011 at 19:36

3 Answers 3

0

Both the examples you give are effectively equivalent - you end up with relative paths in the archive.

If you want to include absolute paths in the archive use -P, but beware that it will be inconvenient to restore to anywhere other than the root.

2
  • Is there no difference between tar -tvh producing ./etc/ from an archive and tar -tvh producing etc/ from an archive ?
    – sabgenton
    Jun 10, 2011 at 1:20
  • They are different spellings of the same relative path. Jun 11, 2011 at 14:08
0

What you want to use depends on what you're doing.

If you're just trying to make a backup of your files, then the tar command will work for you (more on that below). If you're trying to make an image of your harddrive, then use the dd command. Please know that you can't just put your tar backup on a new drive and boot with it.

The issue you'll run into with the tar command is that your file will be placed under the / directory, which is what you're backing up. So you'll need to exclude your backup file.

cd /
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz /

2
  • I know it won't get the MBR but if I have a /boot partition and I just tarballed the partition the bootloader points to won't that work? I do the same thing with rsync, works fine.
    – sabgenton
    Jun 10, 2011 at 1:26
  • That should work if you're planning on restoring your backup to the same drive. I always plan for the worse (ie, the drive dying). Has the tar command produced what you were expecting?
    – Chris Ting
    Jun 10, 2011 at 14:13
0

I have found a sed solution, it's better than using tar twice.

tar cvfz backup.tar.gz -C /path/to/dir/ --transform 's/^\.//' .
1
  • Note that this will skip your dotfiles :)
    – iElectric
    Sep 1, 2011 at 10:13

You must log in to answer this question.

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