天涯小站 2.0

 找回密码
 注册
搜索
天涯小站 2.0 › 首页 ›拾萃› 科技网络 › 查看内容

蜂王:backing up strategy

2013-6-15 06:35 AM| 发布者: 星光| 查看: 918| 评论: 14|原作者: 蜂王|来自: 小站空间

摘要: 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/shCOMPUTER=usr-home # na ...
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
mv `ls *.tar -S | head -1
` ../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.




本文内容由 waspking 提供

发表评论

最新评论

引用 2014-4-13 06:49 PM
还好!  这里有我的Notes。。。自己写的, 自己都看不懂了。。原来没有写Comments, 这里有
引用 2013-6-18 12:06 PM
1A was not working properly (creating full backups each day). I modified it by using "newer-than" the Monday backup (no need to check date of last backup, which is stupid) and now it works.

so each monday full backup for /usr/home, and then incremental after that.

also save in a dir called week24 (the 24th week of the year).

2A now works by removing the first line ("#!/bin/sh").

now all scripts work...a matter of tweaking to get what I need. will see if I have room to keep backups of all 54 weeks of a year. if not, I will write another script to delete files older than 30 weeks.
引用 2013-6-15 10:12 PM
darn....2A wont work at all...script terminates if it encounters one error...giving up and try something simpler...

why &quot;cp&quot; does not work in shell script but works fine in command line?  

-- after removing the first line "#!/bin/sh/" , now it works...a bit strange.
引用 2013-6-15 09:40 PM
hanxin: It is easier to write a shell script with 'dump'.
Script!
引用 2013-6-15 07:21 PM
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 ...
我自己没用过dump。但看说明,并不是光用于系统文件呀。

不过,反正只要你写的能做到你需要的,不管什么方法都无所谓。
引用 2013-6-15 06:41 PM
hanxin: It is easier to write a shell script with 'dump'.
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 databases. hence tar and mysqldump are used.
引用 2013-6-15 05:59 PM
看了两行头就发晕。
引用 2013-6-15 05:33 PM
It is easier to write a shell script with 'dump'.
引用 2013-6-15 05:27 PM
unix 的 dump 是 backup 的。用过吗?
引用 2013-6-15 05:06 PM
looks like monhtly could be a problem there. originally I was assuming each month would have 28-31 files there (one per day)...now they are divided into weekly dirs....this will mess up things.... also pickup up one last one is no good. because it will be a incremental one unless it is a sunday.

more headache to think it over.
引用 2013-6-15 03:49 PM
xcr: 呵呵,这是典型的再创造轮子。
没有的事。 Unix Admin都要搞这些的。
引用 2013-6-15 03:43 PM
fancao: 费这个牛劲!你的OS没有backup的功能吗?
要自动化!
引用 2013-6-15 03:19 PM
fancao: 费这个牛劲!你的OS没有backup的功能吗?
呵呵,这是典型的再创造轮子。
引用 2013-6-15 03:18 PM
费这个牛劲!你的OS没有backup的功能吗?

查看全部评论(14)

手机版|天涯小站

GMT-5, 2026-10-17 10:51 AM

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部