Peter Heiss
2008-Apr-22 13:00 UTC
using rsync with scripts (cronjobs) and automated backups
Hello all, I am wondering if it would be possible to write a script or a cronjob in linux using Rsync to run an automated backup of a server, or serveral servers if possible. I am very new with writing scripts and such, so any help or suggestions with how to get started would be great!!! Thanks ahead of time for the help!!! ----- Computers are like air conditioners. They both dont work, if you open windows. -- View this message in context: http://www.nabble.com/using-rsync-with-scripts-%28cronjobs%29-and-automated-backups-tp16824035p16824035.html Sent from the Samba - rsync mailing list archive at Nabble.com.
Hans-Juergen Beie
2008-Apr-22 20:58 UTC
using rsync with scripts (cronjobs) and automated backups
Peter Heiss schrieb am 22.04.2008 14:59 Uhr:> Hello all, > > I am wondering if it would be possible to write a script or a cronjob in > linux using Rsync to run an automated backup of a server, or serveral > servers if possible. I am very new with writing scripts and such, so any > help or suggestions with how to get started would be great!!! > > Thanks ahead of time for the help!!!You may have a look at http://www.pollux.franken.de/backup/rsback/ This is a Perl script just for this purpose. There you'll find some links to related information or other tools, too. hjb :-? -- Hans-Juergen Beie mailto:hjb@pollux.franken.de
lewis Eklund butler
2008-Apr-24 00:04 UTC
using rsync with scripts (cronjobs) and automated backups
On 22-Apr-2008, at 06:59, Peter Heiss wrote:> I am wondering if it would be possible to write a script or a > cronjob in > linux using Rsync to run an automated backup of a server, or serveral > servers if possible. I am very new with writing scripts and such, so > any > help or suggestions with how to get started would be great!!!#!/bin/bash BACKUP="/backup/" MACHINE="mymachine" BAKLOC="${BACKUP}${MACHINE}" if [ -f ${BAKLOC}.sday.0/.rsync_bak_complete ] then if [ "`date +%d`" -eq 1 ] then [ -d ${BAKLOC}.monthly.6 ] && rm -rf ${BAKLOC}.monthly.6 [ -d ${BAKLOC}.monthly.5 ] && mv ${BAKLOC}.mothly.5 $ {BAKLOC}.monthly.6 [ -d ${BAKLOC}.monthly.4 ] && mv ${BAKLOC}.mothly.4 $ {BAKLOC}.monthly.5 [ -d ${BAKLOC}.monthly.3 ] && mv ${BAKLOC}.mothly.3 $ {BAKLOC}.monthly.4 [ -d ${BAKLOC}.monthly.2 ] && mv ${BAKLOC}.mothly.2 $ {BAKLOC}.monthly.3 [ -d ${BAKLOC}.monthly.1 ] && mv ${BAKLOC}.mothly.1 $ {BAKLOC}.monthly.2 [ -d ${BAKLOC}.monthly.0 ] && mv ${BAKLOC}.mothly.0 $ {BAKLOC}.monthly.1 [ -d ${BAKLOC}.weekly.3 ] && mv ${BAKLOC}.weekly.3 $ {BAKLOC}.monthly.0 fi if [ "`date +%w`" -eq 0 ] then echo "Rotating Weekly" [ -d ${BAKLOC}.weekly.3 ] && rm -rf ${BAKLOC}.weekly.3 [ -d ${BAKLOC}.weekly.2 ] && mv ${BAKLOC}.weekly.2 $ {BAKLOC}.weekly.3 [ -d ${BAKLOC}.weekly.1 ] && mv ${BAKLOC}.weekly.1 $ {BAKLOC}.weekly.2 [ -d ${BAKLOC}.weekly.0 ] && mv ${BAKLOC}.weekly.0 $ {BAKLOC}.weekly.1 [ -d ${BAKLOC}.daily.6 ] && mv ${BAKLOC}.daily.6 $ {BAKLOC}.weekly.0 fi if [ "`date +%H`" -eq 0 ] then echo "Rotating Daily" [ -d ${BAKLOC}.daily.6 ] && rm -rf ${BAKLOC}.daily.6 [ -d ${BAKLOC}.daily.5 ] && mv ${BAKLOC}.daily.5 $ {BAKLOC}.daily.6 [ -d ${BAKLOC}.daily.4 ] && mv ${BAKLOC}.daily.4 $ {BAKLOC}.daily.5 [ -d ${BAKLOC}.daily.3 ] && mv ${BAKLOC}.daily.3 $ {BAKLOC}.daily.4 [ -d ${BAKLOC}.daily.2 ] && mv ${BAKLOC}.daily.2 $ {BAKLOC}.daily.3 [ -d ${BAKLOC}.daily.1 ] && mv ${BAKLOC}.daily.1 $ {BAKLOC}.daily.2 [ -d ${BAKLOC}.daily.0 ] && mv ${BAKLOC}.daily.0 $ {BAKLOC}.daily.1 # See line below # fi echo "Rsyncing..." /usr/local/bin/rsync -aCHh --stats --delete-after --delete-excluded \ --exclude="/backup/" --exclude-from=/var/.rexcludes \ --link-dest="${BAKLOC}.daily.1" / ${BAKLOC}.daily.0 /usr/bin/touch ${BAKLOC}.sday.0/.rsync_bak_complete echo "...done." This will create a daily backup for 7 days, a weekly backup for 4 weeks, and a monthly backup for 6 months. It uses hard links to conserve space. I use a different script to do hourly backups against daily.0, but I remove all of those each day. #insert above# [ -d ${BAKLOC}.hourly.23 ] && rm -rf ${BAKLOC}.hourly.* This line only gets executed if all 24 hourly backups ran that day. the hourly backup command is /usr/local/bin/rsync -aCHh --stats --delete-after --delete-excluded \ --exclude="/backup/" --exclude-from=/var/.rexcludes \ --link-dest="${BAKLOC}.daily.0" / ${BAKLOC}.hourly.0 and /var/.rexcludes contains: ===begin SPAM/ *.core tmp/* *.mov *.avi *.mp3 user1/ user2/ ===end which should be pretty self-explanatory.