步骤
bash
#!/bin/bash
# 源目录
SOURCE_DIR="/path/to/source/config/files"
# 目标服务器和目录
DESTINATION="user@destination_server_ip:/path/to/destination/config/files"
# 监控源目录的变化
inotifywait -m -r -e create,delete,modify,move $SOURCE_DIR | while read path action file; do
# 当文件发生变化时,使用 rsync 进行同步
rsync -avz --delete $SOURCE_DIR/ $DESTINATION
done