Why I get "tar: Cowardly refusing to create an empty archive"? when trying to backup the whole server
I am new at ubuntu and dealing with servers. I use Ubuntu 16.04 x64. I want to have a backup for my entire system, So I followed this video https://www.youtube.com/watch?v=KTayZIou-1M
I type this command
sudo tar -cvpzf mybackup.tar.gz --exclude=/backup/mybackup.tar.gz --one-file-system
But I got this error
tar: Cowardly refusing to create an empty archive
Then I realised that I forget to add '/' after '--one-file-system' So I add it.
sudo tar -cvpzf mybackup.tar.gz --exclude=/backup/mybackup.tar.gz --one-file-system/
and get this error
tar: unrecognized option '--one-file-system/'
Thanks in advance.
Add a space before the /
at the end of your command. Change your:
sudo tar -cvpzf mybackup.tar.gz --exclude=/backup/mybackup.tar.gz --one-file-system/
to
sudo tar -cvpzf mybackup.tar.gz --exclude=/backup/mybackup.tar.gz --one-file-system /
Just for completeness:
A simple invocation of tar
might be something like: tar cf foo.tar file1 file2 file3
. This tells tar to create an archive in a file named foo.tar containing file1
, file2
and file3
. (Note that with tar, the -
before the "command" arguments is optional, so you can use cf
or -cf
as you see fit).
Eliminating some other (somewhat irrelevant, for the moment) flags, your first invocation is essentially equivalent to tar cf foo.tar
. Like above, this tells it to create an archive in a file named foo.tar
, but it does not tell it any files to put into the archive. And that's what the error message is telling you: since you haven't specified any files to archive, there's no point in creating an archive to contain nothing.
When you add the /
(and properly separate it from the other parameters), that tells it what files you want to add to the archive, so now it can create an archive that actually contains something (so, barring other errors, it'll do so).
Because you never told it to back up anything
You have
- the command
tar
- some options that go before the tar file name:
-cpzvf
- the tar file name:
mybackup.tar.gz
- some options that go after the tar file name:
--exclude=/backup/mybackup.tar.gz --one-file-system
and then nada. You do not specify a directory to back up. That is a required argument, as you might guess.
Then you caught yourself, and you added the /
, but thought it was a modification of an option, rather than a parameter all its own.
The /
is a directory. It is the root directory. Saying that in this context means "back up the entire filesystem".
As Peter discussees, tar
is not the best way to back up a boot volume. Not least, leaving the tarball on the boot volume does nothing for you if the disk fails.