如何编写 rsync 命令来备份除硬件特定文件之外的所有内容

Xou*_*boy 2 rsync incremental-backup

我有一个 VPS 生产服务器,它为我为客户制作的 Web 应用程序提供服务。我有一个 rsync cron 作业在我的开发服务器上运行,它每天对整个生产服务器进行备份。

#!/bin/sh

RSYNC=/usr/bin/rsync
SSH=/usr/bin/ssh
KEY=/root/backup-rsync-key
RUSER=root
RHOST=xxx.xxx.xxx.xxx
LPATH=/home/backup
RPATH=/

$RSYNC -avz -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH
Run Code Online (Sandbox Code Playgroud)

它工作正常,但会出现以下类型的错误:

...
rsync: read errors mapping "/sys/module/yenta_socket/parameters/disable_clkrun": No data available (61)
ERROR: sys/module/yenta_socket/parameters/isa_probe failed verification -- update discarded.
rsync: read errors mapping "/sys/module/yenta_socket/parameters/isa_probe": No data available (61)
ERROR: sys/module/yenta_socket/parameters/pwr_irqs_off failed verification -- update discarded.
rsync: read errors mapping "/sys/module/yenta_socket/parameters/pwr_irqs_off": No data available (61)
ERROR: sys/power/state failed verification -- update discarded.
rsync: read errors mapping "/sys/power/state": No data available (61)
rsync error: some files could not be transferred (code 23) at main.c(1298) [generator=2.6.8]
Run Code Online (Sandbox Code Playgroud)

(这只是错误的一小部分)

除了无法备份的内容之外,我如何备份所有内容?

谢谢

Oll*_*lli 7

您必须排除不必要的文件。

好的开始是 -x

-x, --one-file-system       don't cross filesystem boundaries
Run Code Online (Sandbox Code Playgroud)

(来自 man rsync(1))。这不包括您没有明确指定的文件系统。请记住,您必须列出要包含的所有挂载点。mount给你清单。

另一个有用的选项是--exclude

--exclude=PATTERN       exclude files matching PATTERN
--exclude-from=FILE     read exclude patterns from FILE
Run Code Online (Sandbox Code Playgroud)

您的命令将类似于

rsync -avzx --exclude=/tmp --exclude=/var/cache -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH
Run Code Online (Sandbox Code Playgroud)