I want to be able to customize the rsync options Hyper Backup uses, when the backup option Data Backup Task
> Remote Data Copy
is selected, but Hyper Backup options are limited and somewhat blury.
DSM 版本: DSM 6.0.2-8451 更新 9
我实际上会给出我自己的解决方案作为答案,但如果出现更好的解决方案,我会验证它。为了对有需要的人有所帮助,我还将在这里写下我对这个主题的结论。
与 rsync 选项相比,Hyper Backup 参数意味着什么
默认
默认情况下,当任务的设置选项卡中没有勾选以下选项时,rsync 使用这些选项:
--chmod=ugo=rwx -W -H -rlt -p --delete --exclude-from=/tmp/RSYNC_RULE_xxxxxx
Run Code Online (Sandbox Code Playgroud)
笔记:
启用传输压缩
添加 rsync 选项: --compress
启用块级备份
删除 rsync 选项: -W
在目的地保留备份文件
删除 rsync 选项: --delete
启用元数据备份
没有 rsync 选项修改
在远程备份存储库上创建一个附加文件夹:@app/@metadata。
启动更多 rsync 命令来管理新文件夹,据称包含备份文件的权限和所有者数据。
启用缩略图备份
没有 rsync 选项修改
我认为(还没有)它改变了临时排除文件的内容。
复制@eaDir 文件夹,存在于每个包含图片的文件夹中,@eaDir 包含由 DSM 生成的图片的一个或多个大小的缩略图。
这是我提出的解决方案(截至 2017 年 2 月),能够完全自定义 Hyper Backup 任务使用的 rsync 选项。
调整 DiskStation 的 rsync 可执行文件
很难说是否可以调整 HyperBackup 配置和任务文件,但我可以得出结论,它使用的是/usr/bin/
. 剩下的就是设置一个中间脚本来调整传递的选项。
sudo -i
输入与“admin”用户相同的密码mv /usr/bin/rsync /usr/bin/rsync.orig
touch /usr/bin/rsync
chmod 4755 /usr/bin/rsync
echo '#!/bin/sh
exec /usr/bin/rsync.orig "$@" --option-you-want-to-add' > /usr/bin/rsync
欢迎任何其他更温和的解决方案。
确保修改会阻止更新
我不确定 DSM 是否管理系统的 rsync 可执行文件,如果是的话,DSM 更新可能会导致我们所做的修改消失殆尽。谁能证实这一点吗?如果是这样,我会想出一个脚本,我将通过Control Panel
>Task Scheduler
定期(例如每天午夜)进行编程,以确保修改在更新中持续存在,并且 rsync 二进制文件本身的更新将被考虑在内。
首先,我将修改后的 rsync 脚本设置为可以使其演变的路径(如果我的修改必须随着时间的推移而改变):
/usr/local/bin/rsync_modified.sh :
#!/bin/sh
# This script is a custom modification script
# It calls the original binary rsync with modified options
# ordering to kill all child processes if receiving term signal
trap 'pkill -P $$' EXIT
# args to array
args2array () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
ARGS=$(args2array "$@")
# ...whatever modification you want to make on $ARGS...
# setting arguments again, from $ARGS
eval "set -- ${ARGS[@]}"
/usr/bin/rsync.orig "$@"
# Notes: the args2array call and the arguments setting in the end helps
# giving rsync.orig the arguments as they would be passed through direct
# call. Adding string or expanded arrays during the call of rsync.orig has
# revealed to fail in some cases, where rsync would ignore some of the
# added parameters.
Run Code Online (Sandbox Code Playgroud)
然后我将创建这个脚本,我可以在计划任务中对其进行编程(使用用户“root”)
/usr/local/bin/rsyncUpdateManager.sh :
#!/bin/sh
# Make sure the modified version of rsync is not overwritten
# and that updates of the original rsync binary are taken into account.
# init
usageFile="/usr/bin/rsync"
origFile="/usr/bin/rsync.orig"
backupFile="/usr/bin/rsync.orig"
modificationScript="/usr/local/bin/rsync_modified.sh"
# check if usage file is a binary
grep -qI . $usageFile && TYPE="TEXT" || TYPE="BINARY"
if [ $TYPE == "BINARY" ]
then
# 1st installation or DSM updated rsync
if [ -f $origFile ]
then
# a original file already exists (probably created by this script)
# we back it up
NOW=$(date +"%Y%m%d_%H%M%S")
mv $origFile "${backupFile}.$NOW.bak"
fi
# rename binary file as original file
mv $usageFile $origFile
fi
# copy modification script in the place of usage file
cp $modificationScript $usageFile
# giving it the same rights as original file (on DiskStation server)
chmod 4755 $usageFile
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7766 次 |
最近记录: |