| trying to save time to automate everything related to backing up....i wanna bee lazy! 1. each day run the following (program only runs correctly starting on a Sunday). 1a: #!/bin/sh COMPUTER=usr-home # name of this computer DIRECTORIES="/usr/home/" # directories to backup BACKUPDIR=/usr/backup/week0 # where to store the backups TIMEDIR=/usr/backup/week0/last-full # where to store time of full backup TAR=/usr/bin/tar # name and locaction of tar PATH=/usr/local/bin:/usr/bin:/bin DOW=`date +%a` # Day of the week e.g. Mon DOM=`date +%d` # Date of the Month e.g. 27 DM=`date +%d%b` # Date and Month e.g. 27Sep # Weekly full backup if [ $DOW = "Sun" ]; then NEWER="" NOW=`date +%d-%b` # Update full backup date echo $NOW > $TIMEDIR/$COMPUTER-full-date $TAR $NEWER -cpf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES # Make incremental backup - overwrite last weeks else # Get date of last full backup NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`" $TAR $NEWER -cpf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES fi 1b: backup mysql: ** cd /usr/backup/ rm current.sql.gz /usr/local/bin/mysqldump -u root -p*&^&^% --all-databases >current.sql gzip current.sql cp current.sql.gz ../week0/Mysql-`date +%U`.sql.gz 1c: rsync.sh from backup server to synchronize all files under /usr/backup /usr/local/bin/rsync -avz main:/usr/backup/ /usr/backup 2. weekly: (2a might have to run it before #1 is run when a new week starts?). 2a: run this script once a week ** cd /usr/backup/ rm -r week5 mv week4 week5 (just found that some months has 5 sundays!). (if there is a 5th sunday of the month, repeat the red loop below? how do I jump over the next one so it does not get overwritten though?) mv week3 week4 cd week4 ` ../year0 #(move the largest tar file of week4 to year0) mv `ls -ltr *.gz| tail -1 | awk '{print $9}'` year0 cd .. #(move the newest gz file of week4 to year0) mv week2 week3 mv week1 week2 cp -r week0 week1 2b: on backup server, restore the databases once a week. mysql -h localhost -u root -p*&*^&( <current.sql 3. monthly once each month (00:00:01 of first day), run the following: ** cd /usr/backup/ rm -r month3 mv month2 month3 mv month1 month2 mkdir month1 mv week? month1 (this can cause problem also, week0...week5 are moved to inside month1.so weekly backup will not start correctly, unless it is a sunday).. #test below to solve this. cd month1 cp -r `ls -ltr | tail -1 | awk '{print $9}'` ../week0 cd .. 4. yearly. not implemented...probably no need to back up stuff more than 1 year old. therefore rm -r year0 and start over. |

hanxin: It is easier to write a shell script with 'dump'.

waspking: dump is for system files. My backup has an identical system. so only user created files needed to be backed up. these are web files (mostly) and mysql ...
hanxin: It is easier to write a shell script with 'dump'.

xcr: 呵呵,这是典型的再创造轮子。
fancao: 费这个牛劲!你的OS没有backup的功能吗?
fancao: 费这个牛劲!你的OS没有backup的功能吗?

Powered by Discuz! X3.4
© 2001-2017 Comsenz Inc.