1 2 | #!/bin/sh tar -czvf backup.tar.gz /CriticalData/ |
1 2 | #!/bin/sh find /CriticalData/ -depth | cpio -ov > backup.cpio |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/bin/sh // 判读当前系统的日期是星期几 DATE=`date | awk '{ printf $1 }'` case $DATE in Mon) LEVEL=1;; Tue) LEVEL=2;; Wed) LEVEL=3;; Thu) LEVEL=4;; Fri) LEVEL=5;; Sat) LEVEL=6;; Sun) LEVEL=7;; esac // 备份命令 backup -$LEVEL -uf /dev/rmt0 /home |
1 | # mkdir /etc/rsyncd |
1 | #touch /etc/rsyncd/rsyncd.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | gid = users read only = true use chroot = true transfer logging = true log format = %h %o %f %l %b log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid secrets file = /etc/rsyncd.secrets hosts allow = 192.168.0.0/255.255.255.0 max connections = 5 timeout = 300 motd file = /etc/rsyncd/rsyncd.motd [CriticalData] path = /CriticalData list = true ignore errors comment =This is Critical Data auth users = rsync secrets file = /etc/rsyncd/rsyncd.secrets exclude = Common/ |
1 2 | #touch /etc/rsyncd/rsyncd.secrets #chmod 600 /etc/rsyncd/rsyncd.secrets |
1 | rsync:passwd |
1 | #chown -R rsync /CriticalData/ |
1 | #touch /etc/rsyncd/rsyncd.motd |
1 2 3 | ============================ This is Critical Data Server ============================= |
1 | #/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #!/bin/sh export RSYNC_PASSWORD=passwd export PATH=$PATH:/bin:/usr/bin:/usr/local/bin // 设置远程服务器与需要备份的目录 SERVER=rsync@Server DIR=CriticalData // 设置客户端上的用于备份的目录 BDIR=/Backup BASE=Current INCREMENTDIR=`date +%Y-%m-%d` // 在客户端灵活使用 exclude 功能;设置日志 EXCLUDES=/root/rsync/excludes LOG=/tmp/rsync.log // 参数设置,调用 backup-dir 将服务器端的增量文件存储到 INCREMENTDIR 目录下 OPTS="-avz--force --delete --delete-excluded --exclude-from=$EXCLUDES -b --backup-dir=$BDIR/$INCREMENTDIR --ignore-errors" // 确保客户端上的用于备份的目录存在 install -d $BDIR/$BASE // 实现数据备份与同步,将日志邮寄给 root 用户 run_rsync() { echo "==========Begin rsync: `date`===========" >>$LOG 2>&1 du -s $BDIR/* >>$LOG 2>&1 rsync $OPTS $SERVER:DIR $BDIR/$BASE >>$LOG 2>&1 echo "==========End rsync: `date`===========" >>$LOG 2>&1 mail root -s "Backup Report" < $LOG rm $LOG } // 条件测试,运行程序 if [ -f $EXCLUDES ]; then if [ -d $BDIR ]; then run_rsync else echo "cant find $BDIR"; exit fi else echo "cant find $EXCLUDES"; exit fi |
1 2 3 4 | # pwd /Backup # ls 2009-06-16 Current |
1 | 0 0 * * * /root/rsync/rsync.sh 2>&1>>/root/rsync/rsync_cron.log |
1 2 3 4 5 | # mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/root": 1 message 1 new >N 1 root@cdlf2ler02.clus Tue Jun 16 16:53 32/1050 "Backup Report" & |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | Message 1: From root@cdlf2ler02.clusters.com Tue Jun 16 16:53:35 2009 Date: Tue, 16 Jun 2009 16:52:14 -0400 From: root <root@cdlf2ler02.clusters.com> To: root@cdlf2ler02.clusters.com Subject: Backup Report ==========Begin rsync: Tue Jun 16 16:52:14 EDT 2009=========== 16 /Backup/Current =========================== This is Critical Data Server =========================== receiving file list ... done deleting b/ ./ Location/ Name/ Name/Namelist1 sent 214 bytes received 317 bytes 1062.00 bytes/sec total size is 3 speedup is 0.01 ==========End rsync: Tue Jun 16 16:52:14 EDT 2009=========== |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |