mirror of
https://github.com/laurent22/rsync-time-backup
synced 2024-11-10 14:14:16 +00:00
Updated rsync_tmbackup.sh to allow remote source
Changes to allow rsync_tmbackup.sh to pull files from remote server.
This commit is contained in:
parent
9a5afa66f4
commit
88dce0e3f9
1 changed files with 22 additions and 8 deletions
|
@ -32,7 +32,7 @@ trap 'fn_terminate_script' SIGINT
|
||||||
# Small utility functions for reducing code duplication
|
# Small utility functions for reducing code duplication
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
fn_display_usage() {
|
fn_display_usage() {
|
||||||
echo "Usage: $(basename $0) [OPTION]... <SOURCE> <[USER@HOST:]DESTINATION> [exclude-pattern-file]"
|
echo "Usage: $(basename $0) [OPTION]... <[USER@HOST:]SOURCE> <[USER@HOST:]DESTINATION> [exclude-pattern-file]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Options"
|
echo "Options"
|
||||||
echo " -p, --port SSH port."
|
echo " -p, --port SSH port."
|
||||||
|
@ -82,7 +82,15 @@ fn_parse_ssh() {
|
||||||
SSH_HOST=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\2/')
|
SSH_HOST=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\2/')
|
||||||
SSH_DEST_FOLDER=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\3/')
|
SSH_DEST_FOLDER=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\3/')
|
||||||
SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
|
SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
|
||||||
SSH_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
|
SSH_DEST_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
|
||||||
|
|
||||||
|
elif [[ "$SRC_FOLDER" =~ ^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$ ]]
|
||||||
|
then
|
||||||
|
SSH_USER=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\1/')
|
||||||
|
SSH_HOST=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\2/')
|
||||||
|
SSH_SRC_FOLDER=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\3/')
|
||||||
|
SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}"
|
||||||
|
SSH_SRC_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,8 +138,10 @@ fn_ln() {
|
||||||
SSH_USER=""
|
SSH_USER=""
|
||||||
SSH_HOST=""
|
SSH_HOST=""
|
||||||
SSH_DEST_FOLDER=""
|
SSH_DEST_FOLDER=""
|
||||||
|
SSH_SRC_FOLDER=""
|
||||||
SSH_CMD=""
|
SSH_CMD=""
|
||||||
SSH_FOLDER_PREFIX=""
|
SSH_DEST_FOLDER_PREFIX=""
|
||||||
|
SSH_SRC_FOLDER_PREFIX=""
|
||||||
SSH_PORT="22"
|
SSH_PORT="22"
|
||||||
|
|
||||||
SRC_FOLDER=""
|
SRC_FOLDER=""
|
||||||
|
@ -210,6 +220,10 @@ if [ -n "$SSH_DEST_FOLDER" ]; then
|
||||||
DEST_FOLDER="$SSH_DEST_FOLDER"
|
DEST_FOLDER="$SSH_DEST_FOLDER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$SSH_SRC_FOLDER" ]; then
|
||||||
|
SRC_FOLDER="$SSH_SRC_FOLDER"
|
||||||
|
fi
|
||||||
|
|
||||||
for ARG in "$SRC_FOLDER" "$DEST_FOLDER" "$EXCLUSION_FILE"; do
|
for ARG in "$SRC_FOLDER" "$DEST_FOLDER" "$EXCLUSION_FILE"; do
|
||||||
if [[ "$ARG" == *"'"* ]]; then
|
if [[ "$ARG" == *"'"* ]]; then
|
||||||
fn_log_error 'Source and destination directories may not contain single quote characters.'
|
fn_log_error 'Source and destination directories may not contain single quote characters.'
|
||||||
|
@ -291,7 +305,7 @@ if [ -n "$(fn_find "$INPROGRESS_FILE")" ]; then
|
||||||
if [ -n "$PREVIOUS_DEST" ]; then
|
if [ -n "$PREVIOUS_DEST" ]; then
|
||||||
# - Last backup is moved to current backup folder so that it can be resumed.
|
# - Last backup is moved to current backup folder so that it can be resumed.
|
||||||
# - 2nd to last backup becomes last backup.
|
# - 2nd to last backup becomes last backup.
|
||||||
fn_log_info "$SSH_FOLDER_PREFIX$INPROGRESS_FILE already exists - the previous backup failed or was interrupted. Backup will resume from there."
|
fn_log_info "$SSH_DEST_FOLDER_PREFIX$INPROGRESS_FILE already exists - the previous backup failed or was interrupted. Backup will resume from there."
|
||||||
fn_run_cmd "mv -- $PREVIOUS_DEST $DEST"
|
fn_run_cmd "mv -- $PREVIOUS_DEST $DEST"
|
||||||
if [ "$(fn_find_backups | wc -l)" -gt 1 ]; then
|
if [ "$(fn_find_backups | wc -l)" -gt 1 ]; then
|
||||||
PREVIOUS_DEST="$(fn_find_backups | sed -n '2p')"
|
PREVIOUS_DEST="$(fn_find_backups | sed -n '2p')"
|
||||||
|
@ -317,7 +331,7 @@ while : ; do
|
||||||
# If the path is relative, it needs to be relative to the destination. To keep
|
# If the path is relative, it needs to be relative to the destination. To keep
|
||||||
# it simple, just use an absolute path. See http://serverfault.com/a/210058/118679
|
# it simple, just use an absolute path. See http://serverfault.com/a/210058/118679
|
||||||
PREVIOUS_DEST="$(fn_get_absolute_path "$PREVIOUS_DEST")"
|
PREVIOUS_DEST="$(fn_get_absolute_path "$PREVIOUS_DEST")"
|
||||||
fn_log_info "Previous backup found - doing incremental backup from $SSH_FOLDER_PREFIX$PREVIOUS_DEST"
|
fn_log_info "Previous backup found - doing incremental backup from $SSH_DEST_FOLDER_PREFIX$PREVIOUS_DEST"
|
||||||
LINK_DEST_OPTION="--link-dest='$PREVIOUS_DEST'"
|
LINK_DEST_OPTION="--link-dest='$PREVIOUS_DEST'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -326,7 +340,7 @@ while : ; do
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
if [ -z "$(fn_find "$DEST -type d" 2>/dev/null)" ]; then
|
if [ -z "$(fn_find "$DEST -type d" 2>/dev/null)" ]; then
|
||||||
fn_log_info "Creating destination $SSH_FOLDER_PREFIX$DEST"
|
fn_log_info "Creating destination $SSH_DEST_FOLDER_PREFIX$DEST"
|
||||||
fn_mkdir "$DEST"
|
fn_mkdir "$DEST"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -367,7 +381,7 @@ while : ; do
|
||||||
|
|
||||||
fn_log_info "Starting backup..."
|
fn_log_info "Starting backup..."
|
||||||
fn_log_info "From: $SRC_FOLDER/"
|
fn_log_info "From: $SRC_FOLDER/"
|
||||||
fn_log_info "To: $SSH_FOLDER_PREFIX$DEST/"
|
fn_log_info "To: $SSH_DEST_FOLDER_PREFIX$DEST/"
|
||||||
|
|
||||||
CMD="rsync"
|
CMD="rsync"
|
||||||
if [ -n "$SSH_CMD" ]; then
|
if [ -n "$SSH_CMD" ]; then
|
||||||
|
@ -380,7 +394,7 @@ while : ; do
|
||||||
CMD="$CMD --exclude-from '$EXCLUSION_FILE'"
|
CMD="$CMD --exclude-from '$EXCLUSION_FILE'"
|
||||||
fi
|
fi
|
||||||
CMD="$CMD $LINK_DEST_OPTION"
|
CMD="$CMD $LINK_DEST_OPTION"
|
||||||
CMD="$CMD -- '$SRC_FOLDER/' '$SSH_FOLDER_PREFIX$DEST/'"
|
CMD="$CMD -- '$SRC_FOLDER/' '$SSH_DEST_FOLDER_PREFIX$DEST/'"
|
||||||
|
|
||||||
fn_log_info "Running command:"
|
fn_log_info "Running command:"
|
||||||
fn_log_info "$CMD"
|
fn_log_info "$CMD"
|
||||||
|
|
Loading…
Reference in a new issue