From a1064caf77f75c3e4397068a12f9b7d735092c31 Mon Sep 17 00:00:00 2001 From: Nicolas Thauvin Date: Thu, 12 May 2016 16:41:26 +0200 Subject: [PATCH] compatibility fixes for older bash versions --- archive_xlog.bash | 2 +- backup_pitr.bash | 8 +++++--- configure_pitr.bash | 8 ++++---- list_pitr.bash | 2 +- purge_pitr.bash | 4 ++-- restore_pitr.bash | 12 ++++++------ restore_xlog.bash | 2 +- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/archive_xlog.bash b/archive_xlog.bash index 71b5ad6..29936c1 100755 --- a/archive_xlog.bash +++ b/archive_xlog.bash @@ -225,7 +225,7 @@ if [ "$ARCHIVE_LOCAL" = "yes" ]; then fi else # Compress and copy with rsync - [[ $ARCHIVE_HOST == *([^][]):*([^][]) ]] && ARCHIVE_HOST="[${ARCHIVE_HOST}]" # Dummy test for IPv6 + echo $ARCHIVE_HOST | grep -qi '^[0123456789abcdef:]*:[0123456789abcdef:]*$' && ARCHIVE_HOST="[${ARCHIVE_HOST}]" # Dummy test for IPv6 dest_host=${ARCHIVE_USER:+$ARCHIVE_USER@}${ARCHIVE_HOST} diff --git a/backup_pitr.bash b/backup_pitr.bash index 814a8dc..87365e7 100755 --- a/backup_pitr.bash +++ b/backup_pitr.bash @@ -163,7 +163,7 @@ fi current_time=`date +%Y.%m.%d-%H.%M.%S` # scp needs IPv6 between brackets -[[ $target == *([^][]):*([^][]) ]] && target="[${target}]" +echo $target | grep -qi '^[0123456789abcdef:]*:[0123456789abcdef:]*$' && target="[${target}]" ssh_target=${ssh_user:+$ssh_user@}$target # Ensure failed globs will be empty, not left containing the literal glob pattern @@ -477,9 +477,11 @@ case $storage in if [ -n "$prev_backup" ]; then # Link previous backup of the tablespace if [ "$local_backup" = "yes" ]; then - rsync_link=( '--link-dest' "$prev_backup/tblspc/$_name" ) + [ -d "$prev_backup/tblspc/$_name" ] && rsync_link=( '--link-dest' "$prev_backup/tblspc/$_name" ) else - rsync_link=( '--link-dest' "$(qw "$prev_backup/tblspc/$_name")" ) + if ssh -n -- "$ssh_target" "test -d $(qw "$prev_backup/tblspc/$_name")" 2>/dev/null; then + rsync_link=( '--link-dest' "$(qw "$prev_backup/tblspc/$_name")" ) + fi fi fi diff --git a/configure_pitr.bash b/configure_pitr.bash index 7a7e374..06b63a2 100644 --- a/configure_pitr.bash +++ b/configure_pitr.bash @@ -135,8 +135,8 @@ fi # Parse the target into user, host and path, deduce if backup is local backup_user="$(echo $target | grep '@' | cut -d'@' -f1 )" -backup_host="$(echo $target | grep ':' | sed -Ee 's/(.*):(.*)/\1/' | cut -d'@' -f2 )" -backup_dir="$(echo $target | sed -Ee 's/(.*):(.*)/\2/')" +backup_host="$(echo $target | grep ':' | sed -re 's/(.*):(.*)/\1/' | cut -d'@' -f2 )" +backup_dir="$(echo $target | sed -re 's/(.*):(.*)/\2/')" if [ -z "$backup_host" ]; then backup_local="yes" else @@ -148,8 +148,8 @@ fi # Parse archive target the same way if [ -n "$archive_target" ]; then archive_user="$(echo $archive_target | grep '@' | cut -d'@' -f1 )" - archive_host="$(echo $archive_target | grep ':' | sed -Ee 's/(.*):(.*)/\1/' | cut -d'@' -f2 )" - archive_dir="$(echo $archive_target | sed -Ee 's/(.*):(.*)/\2/')" + archive_host="$(echo $archive_target | grep ':' | sed -re 's/(.*):(.*)/\1/' | cut -d'@' -f2 )" + archive_dir="$(echo $archive_target | sed -re 's/(.*):(.*)/\2/')" if [ -z "$archive_host" ]; then archive_local="yes" else diff --git a/list_pitr.bash b/list_pitr.bash index 2a1408a..f9f111e 100755 --- a/list_pitr.bash +++ b/list_pitr.bash @@ -89,7 +89,7 @@ if [ -n "$host" ] && [ "$local_backup" = "yes" ]; then error "BACKUP_HOST and BACKUP_IS_LOCAL are set, it can't be both" fi -[[ $host == *([^][]):*([^][]) ]] && host="[${host}]" +echo $host | grep -qi '^[0123456789abcdef:]*:[0123456789abcdef:]*$' && host="[${host}]" ssh_target=${ssh_user:+$ssh_user@}$host diff --git a/purge_pitr.bash b/purge_pitr.bash index 9d393d2..f84ee45 100755 --- a/purge_pitr.bash +++ b/purge_pitr.bash @@ -135,8 +135,8 @@ fi # Prepare the IPv6 address for use with SSH -[[ $target == *([^][]):*([^][]) ]] && target="[${target}]" -[[ $xlog_host == *([^][]):*([^][]) ]] && xlog_host="[${xlog_host}]" +echo $target | grep -qi '^[0123456789abcdef:]*:[0123456789abcdef:]*$' && target="[${target}]" +echo $xlog_host | grep -qi '^[0123456789abcdef:]*:[0123456789abcdef:]*$' && xlog_host="[${xlog_host}]" ssh_target=${ssh_user:+$ssh_user@}$target xlog_ssh_target=${xlog_ssh_user:+$xlog_ssh_user@}$xlog_host diff --git a/restore_pitr.bash b/restore_pitr.bash index 4ecf9f2..80b8270 100755 --- a/restore_pitr.bash +++ b/restore_pitr.bash @@ -199,7 +199,7 @@ if [ -n "$source" ] && [ "$local_backup" = "yes" ]; then error "BACKUP_HOST and BACKUP_IS_LOCAL are set, it can't be both" fi -[[ $source == *([^][]):*([^][]) ]] && source="[${source}]" +echo $source | grep -qi '^[0123456789abcdef:]*:[0123456789abcdef:]*$' && source="[${source}]" ssh_target=${ssh_user:+$ssh_user@}$source # Ensure failed globs will be empty, not left containing the literal glob pattern @@ -336,13 +336,13 @@ info " PGDATA -> $pgdata" [ -n "$pgxlog" ] && info " PGDATA/pg_xlog -> $pgxlog" -# Populate an associative array with the tablespace directory names. -# We'll use this to check if any of them appear more than once after relocations are applied. -declare -A tspc_dedup +# Populate an array with tablespace directory to check we have duplicates +declare -a tspc_dedup +# Print the tablespace relocation information for (( i=0; i<$tspc_count; ++i )); do info " tablespace \"${tspc_name[$i]}\" (${tspc_oid[$i]}) -> ${tspc_dir[$i]} (relocated: ${tspc_reloc[$i]})" - tspc_dedup[${tspc_dir[$i]}]=1 + tspc_dedup+=( ${tspc_dir[$i]} ) done info @@ -353,7 +353,7 @@ info " restore_command = '$restore_command'" info # Check if tablespace relocation list have duplicates -if (( ${#tspc_dedup[@]} < $tspc_count )); then +if (( $(for o in "${tspc_dedup[@]}"; do echo $o; done | sort -u | wc -l) < $tspc_count )); then error "found duplicates in tablespace relocations. Check options and the list of tablespaces of the backup" fi diff --git a/restore_xlog.bash b/restore_xlog.bash index 6e2b42e..6d9d8f3 100755 --- a/restore_xlog.bash +++ b/restore_xlog.bash @@ -191,7 +191,7 @@ if [ "$ARCHIVE_LOCAL" = "yes" ]; then fi else # check if we have a IPv6, and put brackets for scp - [[ $ARCHIVE_HOST == *([^][]):*([^][]) ]] && ARCHIVE_HOST="[${ARCHIVE_HOST}]" + echo $ARCHIVE_HOST | grep -qi '^[0123456789abcdef:]*:[0123456789abcdef:]*$' && ARCHIVE_HOST="[${ARCHIVE_HOST}]" if ! scp -- "${ARCHIVE_USER:+$ARCHIVE_USER@}$ARCHIVE_HOST:$(qw "$ARCHIVE_DIR/$xlog_file")" "$target_file" >/dev/null; then error "could not copy $ARCHIVE_HOST:$ARCHIVE_DIR/$xlog_file to $target_file"