#!/bin/bash
user=samba
samba_data=/vda/samba/files
des_ip= IP地址
date=$(date '+%Y-%m-%d %H:%M:%S')
#intofy监控内容
/usr/bin/inotifywait -mrq --format '%e:%w%f' -e modify,create,delete,attrib,close_write,move $samba_data |
#判断事件进行传输
while read files
do
#对监控事件和文件进行切割
rsync_event=$(echo $files | awk -F "[:]" '{print $1}')
rsync_files=$(echo $files | awk -F "[:]" '{print $2}')
#创建和关闭操作时进行同步
if [[ $rsync_event = 'CREATE' ]] || [[ $rsync_event = 'CREATE,ISDIR' ]] || [[ $rsync_event = 'CLOSE_WRITE' ]]; then
rsync -azPR -e 'ssh -p 2222' $rsync_files $user@$des_ip:/back
fi
#删除和移动操作时进行同步
if [[ $rsync_event = 'DELETE' ]] || [[ $rsync_event = 'MOVED_FROM' ]]; then
rsync -azPR --delete -e 'ssh -p 2222' $samba_data $user@$des_ip:/back
fi
done
Rsync-同步备份服务器脚本
最新推荐文章于 2023-02-14 10:40:26 发布