0
tar -czvf /var/local/mybackup.tar.gz -C /etc/alternatives/

I used the above mentioned code to create a backup file. But it is showing me this error.

tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.

What is wrong with my code??

1

tar requires a list of files to include in the archive. The command

tar -czvf /var/local/mybackup.tar.gz -C /etc/alternatives/ .

will create a compressed tar file containing all of the files within /etc/alternatives/.

  • That star at the end of your command will be expanded by the shell in the current directory, won't it? – dhag Sep 21 '15 at 16:45
0

You don't need to use the -C flag

$ tar czvf /path/of/the/backup/name.tar.gz /path/of/the/files

If you want to backup a bunch of files, use wildcard. If you want to backup an entire dir just do not end the line with the slash /

Files backup $ tar czvf /path/to/backupdir/files.tar.gz /path/to/files/*

Dir backup $ tar czfP /path/to/backupdir/files.tar.gz /path/to/dir

From man tar

-P, --absolute-names
   don't strip leading `/'s from file names
-1

Usually /etc/alternatives is entirely populated with links. Try using the -h command of tar to dereference the links they point to and include the actual files. (If that is your goal, which I assume it would be.)

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.