LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2010, 02:28 PM   #1
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Rep: Reputation: 46
tar gz shell script fails


Hi guys. Someone gave me a script that would tar then gzip my music directory, as well as remove the previous days backup. I have it set up in crontab, but it appears to have stopped working the last couple days, so i tried running it manually. Below is the script and the output I got. Any ideas why its failing now? I dont think anything changed on the server, maybe someone installed updates but idk why that would affect this.

Here's the musicbackup.sh script
Code:
## CREATE tar backup
        tar cf /backups/`date +%Y%m%d`-music.tar /data/music

## CLEANUP yesterdays backup
        rm -f /backups/*.tar.gz

## GZIP backup just created
        gzip /backups/`date +%Y%m%d`-music.tar
output on screen:
Code:
tar: Removing leading `/' from member names
gzip: /backups/20100727-music.tar: No such file or directory
 
Old 07-27-2010, 02:51 PM   #2
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
Actually, it looks like the .tar.gz is in the directory, but why would it give that message like something didn't work?

guess i just dont understand gzip well since this script was given to me.
 
Old 07-27-2010, 03:31 PM   #3
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,829

Rep: Reputation: 256Reputation: 256Reputation: 256
You have to use:

rm -f /backups/*.tar.gz

tar -C /backups zcvf `date +%Y%m%d`-music.tar.gz /data/music/

Otherwise, you'll remove the archive you just made, and the one from yesterday. And these paths assume that /backup is off the root, '/', directory. If it isn't, you would either use the canonical path (full path), or use a variable to denote the full path:

HOME=/home/sam/
tar -C $HOME/backups zcvf `date +%Y%m%d`-music.tar.gz $HOME/data/music/

I have faith in you. Good luck.
 
Old 07-27-2010, 03:45 PM   #4
rjo98
Senior Member
 
Registered: Jun 2009
Location: US
Distribution: RHEL, CentOS
Posts: 1,668

Original Poster
Rep: Reputation: 46
I do remove the .tar.gz before making the new .tar.gz so i think i'm ok there.

I actually do want to get rid of today's .tar once the .tar.gz is made, but I guess i was just confused as to why it said the .tar wasn't there anymore, as i thought that was by design with the way the commands are written. is that message just more informational than anything?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
shell script fails to exit twrig3846 Linux - Newbie 11 02-10-2010 01:10 AM
Shell Script To extract more than one tar file in to a single folder greensuman Linux - General 5 12-03-2009 12:08 AM
tar error in shell script fanoliv Programming 4 11-04-2006 04:52 AM
grep in shell script fails on redhat 3.0 rlangsto Linux - General 4 03-06-2005 08:42 PM
Tar files in a dir modified before 7 days in a shell script jayachristina Linux - Newbie 4 05-14-2004 03:49 AM


All times are GMT -5. The time now is 10:33 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration