首页 学习笔记 📖 / 未收录,推送中

请注意,本文最后更新时间:2021-02-03,最后编辑于130天前,内容可能已经不具有时效性,请谨慎参考。

1、客户端脚本

这里我拿nfs服务器充当客户端

#/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

image-20210111211641737

2、web服务器脚本

#/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

image-20210111212112634

3、备份服务器脚本

#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

image-20210111212325042

4、实现自动完成全网数据备份(定时任务)

客户端定时任务:
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

当然这些还是有完善的地方


您阅读这篇文章共花了:



文章评论

评论已关闭

目录