LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-05-2004, 08:49 AM   #1
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Rep: Reputation: 15
Is there a way to ...


When backup up directories ...

Is there a way to have the backup files rename themselves when the backup runs each night so that there can be many existing in a folder? I guess what I'm asking is, is there a way to automate the backups to run nightly for a week and collect in a file where I will retrieve them once a week? Each zipped file for each day of the week would have its own unique name.

I want to have a history of zipped backups for each week, instead of replacing a single backup file nightly with the latest version.

Any way to automate this or will I definitely have to do this manually?

Thanks ...
 
Old 08-05-2004, 09:11 AM   #2
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
This is probably similar to what you're looking for:
Code:
tar -cvjfp `date +%m-%d-%y`-mybackup.tar.bz2 /path/to/backup
 
Old 08-05-2004, 09:17 AM   #3
Galik
Member
 
Registered: Mar 2003
Location: UK
Distribution: gentoo
Posts: 67

Rep: Reputation: 15
yes. i usuall create the backup file name from the current date and time using the date command:

Code:
date_name=$(date +%y%m%d-%H%M%S)

tar -cvf ${date_name}.tar /home/mylogin
 
Old 08-05-2004, 09:26 AM   #4
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Original Poster
Rep: Reputation: 15
Cool, thank you ..

So would the full command be something like this?



date_name=$(date +%y%m%d-%H%M%S)

23 9 * * * tar -cvf $(date_name).tar /backuppath /pathtobackup


Or am I setting it up incorrectly?
 
Old 08-05-2004, 09:33 AM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 377Reputation: 377Reputation: 377Reputation: 377
Quote:
Originally posted by sdebiasio
Cool, thank you ..

So would the full command be something like this?



date_name=$(date +%y%m%d-%H%M%S)

23 9 * * * tar -cvf $(date_name).tar /backuppath /pathtobackup


Or am I setting it up incorrectly?
date_name=`date +%y%m%d-%H%M%S`

23 9 * * * tar -cvf /backuppath/${date_name}.tar /pathtobackup
 
Old 08-05-2004, 10:23 AM   #6
sdebiasio
LQ Newbie
 
Registered: Jul 2004
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks ...

I tried it out and for the resulting backup file, I only get an unidentified-type file simply called "date".

Am I correct to be declaring the data variable in the cron job? Or do I need to declare that somewhere else?
 
Old 08-05-2004, 10:32 AM   #7
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 377Reputation: 377Reputation: 377Reputation: 377
Quote:
Originally posted by sdebiasio
Thanks ...

I tried it out and for the resulting backup file, I only get an unidentified-type file simply called "date".

Am I correct to be declaring the data variable in the cron job? Or do I need to declare that somewhere else?
you could put this stuff in a script, and then just call the script from cron...

Code:
#!/bin/sh
date_name=`date +%y%m%d-%H%M%S`
tar -cvf /backuppath/${date_name}.tar /pathtobackup
and in cron:

Code:
23 9 * * * /path_to_script/script.sh
i think you can do it from cron (without the script) if you want:

Code:
23 9 * * * date_name=`date +%y%m%d-%H%M%S` && tar -cvf /backuppath/${date_name}.tar /pathtobackup

Last edited by win32sux; 08-05-2004 at 10:42 AM.
 
  


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




All times are GMT -5. The time now is 01:58 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration