LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 12-20-2003, 12:07 PM   #1
HomeBrewer
LQ Newbie
 
Registered: Dec 2003
Location: Massachusetts, USA
Posts: 17

Rep: Reputation: 0
Creating a date-based filename for a tarball?


I am using tar to backup portions of my Linux server to another disk on a WinXP machine via a mounted share. I run the backup as a cron job each night.

The command I'm using now (tar -czvf /mnt/HelixBackups/Helix_backup.tar.gz /var/www /home /var/lib/mysql /etc/my.cnf) works well, backing up the files I want archived, and storing the tar file on the windows machine. It has an obvious drawback, however, in that each time it is run, it destroys the previous night's backup in favor of the current one, due to the filename being specified on the command line.

Is there a way to automatically genterate a unique filename each night, perhaps based on the date? That way I could keep a week or so of backups on the drive...

Thanks for any assistance!
 
Old 12-20-2003, 12:17 PM   #2
green_dragon37
Member
 
Registered: Oct 2002
Location: Lower Alabama
Distribution: Slackware, OpenBSD 3.9
Posts: 344

Rep: Reputation: 31
You bet:
Using the "date" command (note, the ( ` ) is a backtick, next to the 1 key):
"tar -czvf /mnt/HelixBackups/Helix_backup.`date +%d%m%y`.tar.gz ...."

Ian

Last edited by green_dragon37; 12-20-2003 at 12:18 PM.
 
Old 12-20-2003, 01:16 PM   #3
HomeBrewer
LQ Newbie
 
Registered: Dec 2003
Location: Massachusetts, USA
Posts: 17

Original Poster
Rep: Reputation: 0
Thank you for your quick response, green_dragon37!

Now, so that I don't have weeks and weeks of these backup files accumulating on my disk, I'd like to delete those that are over a certain age old. So, if I scheduled another cron job to run after the completion of the backup job, and decided I wanted to keep three days of backup tars but delete anything older than that, would the following command work?

find /mnt/HelixBackups -mtime +3 -exec rm -f Helix_backup.*.tar.gz

I put this command together by piecing together various pieces of data found with Google. It looks (to my inexperienced eye) like it would do the job, what do you think? On some of the reference sites I saw, the line was terminated with a semi-colon (, is that required here?
 
Old 12-20-2003, 01:32 PM   #4
green_dragon37
Member
 
Registered: Oct 2002
Location: Lower Alabama
Distribution: Slackware, OpenBSD 3.9
Posts: 344

Rep: Reputation: 31
I think the command needs to be:

" find /mnt/HelixBackups -name Helix_backup.*.tar.gz -mtime +3 -exec rm -f {} \; "

the {} says to work on the matching filename(s) and the \; tells find that that is the end of the command to execute.

Also, might I suggest using bzip2 compression on those backups, it is a more efficient algorithm. "tar -cvjf filename.tar.bz2 files"

Ian
 
Old 12-20-2003, 02:16 PM   #5
HomeBrewer
LQ Newbie
 
Registered: Dec 2003
Location: Massachusetts, USA
Posts: 17

Original Poster
Rep: Reputation: 0
I knew I was close on the "find" command string, but I was really unsure of what the line ended with...

Quote:
Originally posted by green_dragon37
Also, might I suggest using bzip2 compression on those backups, it is a more efficient algorithm.
You certainly can -- I'm not proud! If there's a better way to do it, I'm all for it.

Thanks again, green_dragon37, you've been a big help!

Last edited by HomeBrewer; 12-21-2003 at 08:50 PM.
 
  


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
logrotate with date in filename ptp Linux - Newbie 1 04-14-2011 10:55 AM
adding date to filename (creating a quick screenshot button) toaster.waffle Linux - Software 2 04-27-2005 03:19 AM
using bash in cron to get the date in filename rstoutmna Programming 1 12-29-2004 02:39 PM
use date as output filename? wijnands Linux - Newbie 1 05-12-2004 03:39 PM
how to add date to filename x2000koh Programming 1 07-08-2003 09:44 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration