LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How do I select destination directory for tar command (https://www.linuxquestions.org/questions/linux-software-2/how-do-i-select-destination-directory-for-tar-command-4175445819/)

fkasmani 01-16-2013 03:23 AM

How do I select destination directory for tar command
 
Hello,

I'm wanting to tar a folder called "mysite" to the destination directory: /var/backups/

I'm trying to issue the following command:

Quote:

tar -C /var/www/mysite/ -zcf mysite_$(date +%y%m%d).tar.gz /var/backups/
However, it's ending up with:

ta
Quote:

r: C: Cannot stat: No such file or directory

tar: Removing leading `/' from member names

tar: Exiting with failure status due to previous errors
I've checked and confirmed that /var/backups/ is a valid directory.

Would really appreciate some help on this, pls.

michaelk 01-16-2013 06:39 PM

Lots of help can be found by searching the web but the basic syntax is:

tar options -f archive_name directory-name

Where directory-name is the directory of the files to be archived and not the destination for the tar file. The -C option basically performs a cd to that directory.

So I assume this is what you are trying to accomplish.

tar -C /var/backups/ -zcf mysite_$(date +%y%m%d).tar.gz /var/www/mysite/

TobiSGD 01-16-2013 06:46 PM

I would just omit the -C option (in fact I am doing that in my backup script) and run the command this way:
Code:

tar -zcf /var/backup/mysite_$(date +%y%m%d).tar.gz /var/www/mysite/

fkasmani 01-17-2013 09:12 AM

Basically what I want to do is, to tar the mysite folder "/var/backup/mysite" into a file called mysite_yymmdd.tar.gz which sould be available in /var/backups/

TobiSGD 01-17-2013 10:03 AM

That is exactly what the command I posted does.

michaelk 01-17-2013 10:37 AM

Mine too :)

linosaurusroot 01-17-2013 10:41 AM

Quote:

Originally Posted by TobiSGD (Post 4871779)
I would just omit the -C option (in fact I am doing that in my backup script) and run the command this way:
Code:

tar -zcf /var/backup/mysite_$(date +%y%m%d).tar.gz /var/www/mysite/

That gives an absolute pathname in the tarfile (/var/www/mysite/) I assume the -C was to make that relative (.) .


All times are GMT -5. The time now is 08:00 PM.