0

When I use the command

tar -czf /var/backups/completa.tgz -g /var/backups/backup.info /home

... then tar says

tar: Removing leading `/' from member names

How may I prevent tar from removing the leading /?

Kusalananda
  • 333,661
Cuscus
  • 1

2 Answers2

1

From the GNU tar manual:

-P, --absolute-names
Don't strip leading slashes from file names when creating archives.

You should therefore be able to say, e.g.,

tar -c -Pz -f /var/backups/completa.tgz -g /var/backups/backup.info /home

Note that this creates an archive containing absolute pathnames, making it impossible to extract the archived files into a subdirectory without taking extra care (e.g., using GNU tar with its --strip-components option).

If you create a backup, then it would be better to not use -P. When you want to restore files from the backup, you most likely want to extract the relevant files from the archive into a subdirectory and then manually move them into place. You most likely do not want to extract files directly into the absolute locations stored in the archive as that would potentially overwrite files that you might not want to restore.

Kusalananda
  • 333,661
0

Having leading / in archive names is dangerous, since if you are under some directory and they had not been removed, then you are quite likely to inardverantly write over existing files. So to protect users, they are removed. If you really need the full path, and you know what you are doing, then change to the / directory and run an extraction from there. But leave it off your archive.

Bib
  • 2,380