Results 1 to 5 of 5
Yet more backup questions. I use
Code:
sudo tar -cvf /media/disk/filedate.tar /etc
sudo tar -cvf /media/disk/filedate.tar /home/joe
What I want to do is write a short script(mybackup) that will automate ...
- 06-14-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 39
how to write a backup script?
Yet more backup questions. I use
What I want to do is write a short script(mybackup) that will automate that for me, so when I type mybackup it executes the commands AND replaces the "filedate.tar" with "the date of that day".tar.Code:sudo tar -cvf /media/disk/filedate.tar /etc sudo tar -cvf /media/disk/filedate.tar /home/joe
Possibly using some variation of the "date" command. I triedand that gives me the output I want. How do I sub that for filedate.tar in the script?Code:date %m%d%y
Thanks in advance
- 06-14-2009 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
Well here are two things to start you off.
- I see you are using sudo. If the script needs root access, run it as root. You should use sudo in scripts. Maybe a cron job under root could do it for you
- When using the date command, you're best to use the YYYYMMDD format, i.e. high-to-low. That way you have an inherent file sorting and the output directory won't seem as garbled
If you intend using the date a few times, set it into a variable and then use the variable in each command. That way if the day changes during the script you won't get inconsistent resultsCode:tar -cvf /media/disk/$(date +%Y%m%d).tar /home/joe
Also, you've used the same archive name for both backups. Don't forget to put something into the name to distinguish them, or at least don't use the create switch the second time.Code:BACKUPDATE=$(date +%Y%m%d) tar -cvf /media/disk/$BACKUPDATE.tar /home/joe
- 06-14-2009 #3
no need to do a script
sudo apt-get install sbackup
then go to system-> admin -> sbackup configuration
you can set it for however frequently and what folders. It'll auto make a compressed folder with everything in itBodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 06-14-2009 #4Just Joined!
- Join Date
- Apr 2009
- Posts
- 39
jmadero, thanks for your reply
bigtomrodney, thank you for your practical and clear reply. Sounds like you have the answer and I will try that very soon.
Thanks againBACKUPDATE=$(date +%Y%m%d)
tar -cvf /media/disk/$BACKUPDATE.tar /home/joe
- 06-15-2009 #5Just Joined!
- Join Date
- Apr 2009
- Posts
- 39
Thank You for all your help. Problem is solved


Reply With Quote