cron job - run a backup then rsync results to mounted drive
Hi
Just looking for some advice, I have set up a cron job using crontab -e as root that looks as follows, Code:
[root@backup win]# crontab -l I then need to rsync these .tar.gz files to a mounted drive, I can do this manually using Code:
rsync -avz /root/sitebackup.tar.gz /mnt/win Code:
0 13 * * wed tar -zPvcf testbackupWED.tar.gz /var/www/html | rsync -avz /root/sitebackup.tar.gz /mnt/win Should this work or is there a better, easier, cleaner way to do this? (I am looking into doing an incremental backup using the update switch on the tar but this will do for now - if it works) If I have to use a script file is there any chance of a pointer as to how to write it? Thanks for any help Luke |
Hi and welcome to LinuxQuestion!
A cron job runs as if it were launched from the user's home directory, so that you will find them under Code:
/home/luke Code:
0 13 * * wed tar blah blah blah && rsync blah blah |
Thanks very much for the prompt reply
Kind regards Luke |
You're welcome! :)
|
My solution
Just for anyone else who finds this forum post, this is what i have ended up with in crontab -e
Code:
0 23 * * sun tar -zPvcf /root/testbackupSUN.tar.gz /var/www/html && rsync -avz /root/testbackupSUN.tar.gz /mnt/win My next task is to do exactly the same but omitting log files. If anyone knows how to do this by adding it into the crontab above please feel free to comment, im off to google it now though... I have only run it once so will be interested to see if rsync overwrites last weeks file with the new one - im hoping it does! Couldn't have done it without the help from colucix so thanks again.... Regards Luke |
tar has the --exclude option to exclude files based on a pattern. Suppose the files you want to exclude have the .log extension, you basically need to add
Code:
--exclude='*.log' |
Don't make it more complicated in a cron statement. I recommend to create a script file instead and call it from cron.
When calling the script file you can either pass the day as a command line parameter, or use the date command e.g. testbackup$(date +%a).tar.gz Since you are using rsync anyway I advice not to use tar at all, except if you think you badly need the compression or you want to minimize the file size during transfer. Just rsync your files to a different directory every day. You can use the --exclude command for excluding files. Since you are writing to a mounted drive, you should test the existence of the mounted drive. If not, sooner or later it will happen that the drive is not mounted and you are writing to the mount point of the local drive. Below the code how I solved this: Code:
#!/bin/bash |
Thanks for taking the time to help me jinkels, I am however just starting to learn linux - im a windows man myself - and scripts are just a tad too difficult for me to get my head around just yet!
I can see what you are saying about using a script file to enable a check to see if the mount point exists but for now at least I am just going to live in hope that the automount works as it should. Probably not the best approach but time is money and i dont have much of either! I have to use tar as i have one backup server which will hold all the website backups for 4000+ websites, I dont want millions of folders, by using the tar i can just select the individual .tar.gz file for the server in question, copy it back to where it needs to be, untar and replace the (required) files. Thats the plan anyway! |
Scripting is basically putting the cmds you normally use into a file and calling that, but does make it more practical to eg generate the day on the fly, thus only requiring one cron job instead of 7 :)
Also, doing everything on one line rapidly becomes difficult to achieve and a pain to try and read or debug. These may help http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
All times are GMT -5. The time now is 11:57 AM. |