Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-12-2005, 05:07 AM   #1
LQ Newbie
Registered: Mar 2005
Posts: 4

Rep: Reputation: 0
Bash backup script failing using tar and --newer option

Hello, I'm trying to write a simple bash backup script. It works....well, sort of and that's why I'm here.

Basic scenario. I want to perform an incremental backup where I check the last time a backup was completed. To do this, I have a reference text file ($LastBackup) that has one line, a date. So here are the lines in question.

tar --newer=$(cat $LastBackup) -cjf BackupFile.tar.gz2 $BackupDirectory
echo $(date +%m/%d/%Y) > $LastBackup

The idea here is to run the tar command and then update the the time in the $LastBackup file. Now, if I run it this way, all I get in my tar file is the directory structure. The strange thing is, if I remove the second line (echo ....), then the script works fine meaning that the newer files get tar'ed. It's as if the echo line runs before the tar line which doesn't make any sense to me.

Thanks for any help.

Old 03-12-2005, 07:24 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
The "--newer" doens't take a date-string as an argument, but it takes a file-name. "tar" will then take the modify-time. So you should use "--newer $LastBackup" instead.

Also, to make incremental backups, tar provides another way. See: info tar "Inc Dumps".
Old 03-12-2005, 11:05 AM   #3
LQ Newbie
Registered: Mar 2005
Posts: 4

Original Poster
Rep: Reputation: 0
Hmmmm, I tried it with a date string at the command prompt and it worked.

tar --newer=03/11/2005 -cjf blah.tar.bz2 /path/to/directory/
Anyway, I'll lookup your suggestion. Thanks!
Old 03-12-2005, 12:03 PM   #4
LQ Newbie
Registered: Mar 2005
Posts: 4

Original Poster
Rep: Reputation: 0

Well, here's what I failed to indicate in my message. I have a list of directories that I'm backing up so I loop through them saving each to it's own file. Unfortunately, I was updating $LastBackup each time so after the first directory nothing would be backed up. As it turns out, I only had new data in my 2nd directory so I didn't expect anything more than the directory structure in the first directory.



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
backup: tar with the -L option help Paxmaster Linux - Software 1 11-18-2005 07:06 PM
Bash script - confirmation option satimis Programming 4 10-21-2004 07:29 AM
Basic backup script using Tar GraemeK Linux - General 1 09-17-2004 05:19 AM
Backup script to tar untoldone Programming 2 05-20-2004 03:03 PM
Tar with --newer option tarring all dirs jlangelier Linux - Newbie 0 07-09-2003 12:31 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:43 PM.

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