Skip to content

Instantly share code, notes, and snippets.

@gamma
Created June 13, 2023 06:12
Show Gist options
  • Select an option

  • Save gamma/b7fe73ddd037779b48d59c03781021c5 to your computer and use it in GitHub Desktop.

Select an option

Save gamma/b7fe73ddd037779b48d59c03781021c5 to your computer and use it in GitHub Desktop.

Revisions

  1. gamma created this gist Jun 13, 2023.
    47 changes: 47 additions & 0 deletions rsync
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/bin/bash

    # Backing up a Hetzner Storage box TO the Synology DSM does not work easily due to
    # the special rsync paths requhired by Hetzner which is /home as root. However, Synology
    # does not allow the and requests the path // - which is basically the root. Hetzner
    # not allow that in turn. This script solves the issue by being a wrapper to rsync,
    # which modifies the command to reflect that change.
    #
    # Script is provided as is, for free, no guarantees given. Use at your own risk.
    #
    ########################################################################################
    # SETUP
    # -----
    # This script has to be placed into the /bin directory to work as drop-in-replacement
    # For that you have to:
    # cp -a /bin/rsync /bin/rsync_
    # cat > /bin/rsync
    # <CAT THE SCRIPT>
    # chmod go+rx /bin/rsync
    ########################################################################################

    pattern="^\w+@.*://.*$"

    if [ $# -lt 1 ]; then
    echo "Error: No source path provided."
    echo "Usage: rsync_wrapper.sh <rsync arguments>"
    exit 1
    fi

    modified_args=("$@") # Initialize with original arguments

    for ((i=1; i<=$#; i++)); do
    source="${modified_args[i]}"

    if [[ $source =~ $pattern ]]; then
    modified_args[i]="${source//:\/\//:\/home}"
    fi

    # Optional debug: Print each parameter
    # echo "Parameter $i: ${modified_args[i]}"
    done

    # Print modified arguments
    # echo "Modified arguments: ${modified_args[@]}"

    # Execute the rsync_ command
    /bin/rsync_ "${modified_args[@]}"