Create a backup cron script
Hey,
I have a few web servers, and there is a backup cron setup in the web panel of my server to create a tarball for every website hosted on my server and save it locally to /home/backups every Saturday evening. I just installed and mounted an external hard drive to the /mnt/usbfantom directory. My goal here is to make a script that automatically copies everything from the /home/backups directory and save it to the /mnt/fantom directory on Sunday (the day AFTER the backups from the server are created) on a cron schedule. I am completely lost here. I found some similar threads, but nothing that I could figure out to make work with what I need. Thanks in advance for the help! |
You really wouldn't need to create a separate script, something this easy could be done within the crontab.
Example: Code:
0 10 * * 7 /usr/bin/rsync -av /home/backups /mnt/usbfantom/ 1> /dev/null 2>&1 |
...What do I do with this code? Where do I put it? Excuse my ignorance, I'm pretty new to linux. And what do you mean by "would copy only the new backups"? Do you mean only the backups (or files within the /home/backups directory) that have been changed will be copied? A new baackup is created for each domain regardless, so I'm pretty sure everything would be changed weekly, whether the website itself changed or not as it makes a new tarball with every cron backup.
|
Quote:
To put this in your cron file, brokenhalo, first SU to root. Then, make sure your default editor is VI, by typing in "export EDITOR=vi", then type in "crontab -e". This will bring up your cron (job scheduler) file. If you don't have one, it will create a new one for you. Put the entry in as shown, but modify it as needed. This page http://www.pcwebhosting.net/support/cron_scheduler.htm will show you what's up with the different fields, and how to specify an entry. The case as shown here would run at 10 AM, every Sunday. |
Quote:
|
Quote:
0 or 7 is Sunday. 0 = Sunday 1 = Monday 2 = Tuesday 3 = Wednesday 4 = Thursday 5 = Friday 6 = Saturday 7 = Sunday I always seem to use 7 instead of 0 cause while at work, the start of the week is always Monday for me and Sunday is the last day of the week when it comes to backups. Just my own rule of thumb I've kept over the years. As for changing to test, here are what the fields represent: MIN HOUR DOM(Day of month) MONTH DOW(Day of week) Also for DOW, you can actually use names instead of Numbers if that makes it easier to remember. Here's what you could do to change it to what you specified: Code:
42 10 * * 5 /usr/bin/rsync -av /home/backups /mnt/usbfantom/ 1> /dev/null 2>&1 |
Quote:
|
Okay... I really appreciate your help, but what about the rest of the questions about the minute and day (for testing purposes right now).
|
One last thing... Tried to make the crontab and got this...
[root@host ~]# crontab -e no crontab for root - using an empty one crontab: installing new crontab "/tmp/crontab.XXXXUmMqZH":2: bad minute errors in crontab file, can't install. Do you want to retry the same edit? y crontab: installing new crontab What the hell does all this mean??? |
Quote:
Chances are, your editor is set to ed, which IS a user-friendly editor...it's just very picky about who its friends are. The "export EDITOR=vi" line I mentioned, puts you into the VI editor, ready to create/edit your crontab file. |
Well, I DID follow your direction, all except for "export EDITOR=vi" I changed to nano instead (I hate vi with a passion and love nano :) ) What I find odd is that it created the cron in the /tmp directory... I really need to test this out, so I want to change the date to today (what is the number?) and I need to change the time to 5 minutes from now (how do I do minutes in the time field?). Please, any help would be great so I cna leave today and know that the backups are being made... Thanks!
|
Quote:
|
when I type the command crontab -e, does it create a new crontab every time? If it does, how do I delete the old ones? If it doesn't, how do I create new ones? (I'm almost done with the questions guys, bear with me :) ) Thanks a million! You guys are so much help, I can't thank you enough
|
Okay, everything seemed to work great!! I really appreciate all of your time.
|
Quote:
To delete a job, just either remove the line, or prefix it with a # (i.e. comment out that line) Il |
Okay, thats what I thought. Thanks guys!
|
All times are GMT -5. The time now is 02:25 PM. |