Skip to content

Commit

Permalink
compatibility fixes for older bash versions
Browse files Browse the repository at this point in the history
  • Loading branch information
orgrim committed May 12, 2016
1 parent 0690047 commit a1064ca
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion archive_xlog.bash
Expand Up @@ -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}

Expand Down
8 changes: 5 additions & 3 deletions backup_pitr.bash
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions configure_pitr.bash
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion list_pitr.bash
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions purge_pitr.bash
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions restore_pitr.bash
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion restore_xlog.bash
Expand Up @@ -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"
Expand Down

0 comments on commit a1064ca

Please sign in to comment.