1、客户端脚本
这里我拿nfs服务器充当客户端
代码语言:javascript复制#/bin/bash
Backup_dir="/backup"
IP_info=$(hostname -i)
#cerate backup dir
mkdir -p $Backup_dir/$IP_info
#tar backup data
cd /
tar zchf $Backup_dir/$IP_info/system_backup_$(date %F_week%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables
#del 7 day ago data
find $Backup_dir/ -type f -mtime 7|xargs rm 2>/dev/null
#create finger file
find $Backup_dir/ -type f -mtime -1 ! -name "finger*"|xargs md5sum >$Backup_dir/$Ip_info/finger.txt
#backup push data info
rsync -az $Backup_dir/ rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
2、web服务器脚本
代码语言:javascript复制#/bin/bash
Backup_dir="/backup"
IP_info=$(hostname -i)
#cerate backup dir
mkdir -p $Backup_dir/$IP_info
#tar backup data
cd /
tar zchf $Backup_dir/$IP_info/system_backup_$(date %F_week%w).tar.gz ./var/spool/cron/root ./etc/rc.local ./server/scripts ./etc/sysconfig/iptables
#tar zchf $Backup_dir/$IP_info/www_backup_$(data %F_week%w).tar.gz ./var/html/www
#tar zchf $Backup_dir/$IP_info/www_log_backup_$(data %F_week%w).tar.gz ./app/logs
tar zchf $Backup_dir/$IP_info/www_backup_$(date %F_week%w).tar.gz ./var/html/www
tar zchf $Backup_dir/$IP_info/www_log_backup_$(date %F_week%w).tar.gz ./app/logs
#del 7 day ago data
find $Backup_dir/ -type f -mtime 7|xargs rm 2>/dev/null
#create finger file
find $Backup_dir/ -type f -mtime -1 ! -name "finger*"|xargs md5sum >$Backup_dir/$Ip_info/finger.txt
#backup push data info
#rsync -az $Backup_dir/ rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
rsync -az $Backup_dir/ rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
3、备份服务器脚本
代码语言:javascript复制#del 180 day ago data
find /backup/ -type f -mtime 180 ! -name "week1.tar.gz"|xargs rm 2 >/dev/null
#check backup data
find /backup/ -type f -name "fingex.txt"|xargs md5sum -c >/tmp/check.txt
#sed check mail
mail -s "check info $(date %F)" 3285884651@qq.com </tmp/check.txt
4、实现自动完成全网数据备份(定时任务)
代码语言:javascript复制 客户端定时任务:
crontab -e
# backup data
0 0 * * * /bin/sh /server/scripts/backup.sh &>/dev/null
服务端定时任务
# check backup data
0 5 * * * /bin/sh /server/scripts/backup_server.sh &>/dev/null
当然这些还是有完善的地方