LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 07-18-2012, 07:56 AM   #1
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 20.04
Posts: 383

Rep: Reputation: 30
Creating tar gz from directory


I'm trying to backup some files to a tar.gz file while preserving file permissions but I'm confused about where to specify the filename. I've tried:
Code:
cp -R -p /var/log /mnt/Backup | tar -c MachineNameLogs$date.tar | gzip -r MachineNameLogs$date.tar.gz
MachineNameLogs20120718.tar.gz: No such file or directory
tar: MachineNameLogs20120718.tar: No such file or directory

I've also tried:
Code:
cp -R -p /var/log /mnt/Backup | tar | gzip -r MachineNameLogs$date.tar.gz
machineNameLogs20120718.tar.gz: No such file or directory
Usage: tar {txruc}[vfbFXhiBEelmopwnq[0-7]] [-k size] [tapefile] [blocksize] [exclude-file] [-I include-file] files ...
 
Old 07-18-2012, 08:07 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Code:
cd /var/log
tar cfzv /mnt/Backup/MachineNameLogs$date.tar.gz .
something like this should work.
in your command cp will not send the required data to the pipe, tar will not take usable data from the pipe and cannot write file and also send data to pipe, gzip cannot do recursive operation on stdin and will not write the result to the given file, so almost everything is wrong.
 
Old 07-18-2012, 08:25 AM   #3
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 20.04
Posts: 383

Original Poster
Rep: Reputation: 30
Perhaps not entirely wrong, the version of tar I'm using doesn't have a conviant z option, hence the reason I was piping it to gzip:
Code:
tar: z: unknown option
Usage: tar {txruc}[vfbFXhiBEelmopwnq[0-7]] [-k size] [tapefile] [blocksize] [exclude-file] [-I include-file] files ...
What would be the best way to do it with this in mind?
 
Old 07-18-2012, 08:30 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
in that case cd /var/log; tar cvf - . | gzip > /mnt/Backup/MachineNameLogs$date.tar.gz will do the job.

You ought to look at the man pages of these tools: gzip will compress stdin (from pipe) to stdout and you can redirect output to write the final file.
tar will create an archive (c), will be verbose (v) and send the result to stdout (f -). Tar is recursive by default.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to tar a directory and then copy it to another directory locally wdsmith45 Linux - Newbie 7 02-07-2012 11:49 AM
creating a tar-1.13 in my path kibirango Slackware 2 10-01-2010 07:56 AM
Useradd not creating home directory when creating newuser meneedham Linux - Newbie 4 10-05-2007 12:11 PM
Need tips on creating scripts for daily backup (tar) a directory to an external drive Joejr4u Linux - Server 2 06-07-2007 07:46 AM
Tar gives error when creating a tar file archive davidas Linux - Newbie 10 04-13-2004 12:35 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 10:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration