3

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 version: DSM 6.0.2-8451 Update 9

I will actually give my own solution as an answer, but if any better solution shows up, I'll validate it. For this to be helpful to people in need, I'll also write down here my conclusions on the subject.


What Hyper Backup parameters mean vis-a-vis rsync options

Default

By default, when no following option is ticked in the task's Settings tab, rsync uses those options:

--chmod=ugo=rwx -W -H -rlt -p --delete --exclude-from=/tmp/RSYNC_RULE_xxxxxx

Notes:

  • any configuration will lead to create extra files and folders on your remote backup repository: @app, _Syno_TaskConfig and synobkpinfo.db, managed by Hyper Backup for its own use
  • many rsync commands are launched to manage Hyper Backup files and for integrity checking; rsync options vary for those commands: I'm only talking about the options used when backuping your actual data here
  • the exclude-from file is created temporarily to reflect some checked options (see below)

Enable transfert compression

adds rsync option: --compress

Enable block-level backup

removes rsync option: -W

Reserve the backed up files at the destination

removes rsync option: --delete

Enable metadata backup

no rsync option modification

Creates an additional folder on remote backup repositories: @app/@metadata.
Launches more rsync commands to manage the new folder, supposedly containing backuped files' permission and owner data.

Enable thumbnails backup

no rsync option modification

I THINK (not been there yet) that it changes the content of the temporary exclude-from files.
Copies the @eaDir folder, present in each folder containing a picture, @eaDir containing one or more sized thumbnails of the picture, generated by DSM.

0

Here's the solution I came up to (as of Feb 2017), to be able to fully customize rsync options used by Hyper Backup's tasks.

Tweaking DiskStation's rsync executable

Difficult to say if tweaking HyperBackup configuration and tasks files is possible, but I could come to the conclusion that it was using the rsync binary present in /usr/bin/. The rest is to set an intermediate script that tweaks the passed options up.

  • connect to DiskStation server via SSH with the 'admin' user
  • sudo -i et enter the same password as the 'admin' user
  • 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

Any other softer solution is welcome.

Making sure the modification will resist updates

I am not sure whether or not DSM manages the system's rsync executable, and if so, a DSM update could occur the modification we made to vanish into the void. Can anyone confirm that? If so, I would then come up with a script, which I would program via Control Panel > Task Scheduler regularly (everyday at midnight for example), to ensure the modification will persist over updates, and that updates of the rsync binary itself will be taken into account.

First, I would set my modified rsync script to a path where I can make it evolve (if my modifications have to change over time):

/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.

then I would create this script which I could program in the Scheduled Tasks (with user '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
  • the problem I see with this: it modifies the general rsync command. so if there's any other system relying on rsync to contain exactly the options passed this could break that behavior. – Andre Baumeier Aug 1 '17 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.