![处理 rsync、dd 和快照的多次调用](https://linux22.com/image/632937/%E5%A4%84%E7%90%86%20rsync%E3%80%81dd%20%E5%92%8C%E5%BF%AB%E7%85%A7%E7%9A%84%E5%A4%9A%E6%AC%A1%E8%B0%83%E7%94%A8.png)
服务器经常会进行以下操作:对逻辑卷进行快照,然后将内容备份到远程备份服务器。有可能同时进行多个备份和传输。过多的 rsync 会话和挂载的快照卷会不会有问题?处理时如何优化服务器性能?
lvcreate -L10G -s -n snapshot /home/folderA
dd if=/mnt/snapshot bs=1M | (ssh [email protected] of=/tmp/backups bs=1M)
rsync -avzh --rsh "ssh -l username" /mnt/snapshot 192.168.1.5:/tmp/backups/
答案1
对这些进行某种锁定可能是最安全的,以便无论选择哪一个,一次只能运行一个实例,但如果不知道您(计划)运行它们的频率以及它们需要多长时间,就很难确定。
CentOS 有羊群(1)命令将会很有用。
[ “${FLOCKER}” != “$0” ] && exec env FLOCKER="$0" flock -en “$0” “$0” “$@” || :
This is useful boilerplate code for shell scripts. Put it at the top of the shell script you want to lock and it'll automatically lock itself on the first run. If the env var $FLOCKER is not set to the shell script that is being run, then execute flock and grab an exclusive non-blocking lock (using the script itself as the lock file) before re-execing itself with the right arguments. It also sets the FLOCKER env var to the right value so it doesn't run again.