Reputation: 4436
I'm trying to run a command like this to back up my public directory:
tar -zcvf backups/2014-09-09-public_html.tar.gz public_html -C home/path
My understanding is that this is supposed to create and an archive with the compressed contents of my public directory. But I'm getting the following errors:
tar (child): backups/2014-09-09-public_html.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
This has me confused because I want it to create the file, not open it. I've used similar commands in other projects without problems, so I'm not sure what the problem could be here. What could I be doing wrong?
Upvotes: 0
Views: 538
Reputation: 4436
Well, I finally got it working by putting -C /home/path at the beginning and using the absolute path for the archive name instead of the relative path:
tar -C /home/path -zcvf /home/path/backups/2014-09-09-public_html.tar.gz public_html
I still don't understand why I need to specify the absolute path for the archive name since I've always used the relative path in other projects. I guess maybe it's a difference in how this server is set up or something?
Upvotes: 0
Reputation: 9916
When you create a file, you actually open it in write mode, even if it does not yet exist (read man 3 open
to further understand how this works on *nix).
Are you sure you have write permissions for the destination where you're trying to compress? Can you touch(1)
that location?
Upvotes: 1