全网备份脚本

罗小黑
2021-01-17 / 0 评论 / 17 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年05月15日,已超过82天没有更新,若内容或图片失效,请留言反馈。

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

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

0

评论 (0)

取消