Skip to content

Commit

Permalink
Merge 94a58fb into 1a8eaf8
Browse files Browse the repository at this point in the history
  • Loading branch information
feikesteenbergen committed Feb 2, 2016
2 parents 1a8eaf8 + 94a58fb commit 5ca326b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
71 changes: 71 additions & 0 deletions patroni/scripts/restore_example.sh
@@ -0,0 +1,71 @@
#!/bin/bash

function usage()
{
cat <<__EOT__
Usage: $0 --scope=SCOPE --datadir=DATADIR --backup_directory=BACKUPDIR
__EOT__
}

optspec=":-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
help)
usage
exit 0
;;
scope)
PATRONI_SCOPE="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
scope=*)
PATRONI_SCOPE="${OPTARG#*=}"
;;
datadir)
PGDATA="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
datadir=*)
PGDATA="${OPTARG#*=}"
;;
backup_directory)
BACKUPDIR="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
backup_directory=*)
BACKUPDIR="${OPTARG#*=}"
;;
*)
true
;;
esac;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
usage
exit 1
fi
;;
esac
done


function die()
{
echo "$1"
exit 1
}

[[ -z ${PATRONI_SCOPE} ]] && usage && exit 1
[[ -z ${PGDATA} ]] && usage && exit 1
[[ -z ${BACKUPDIR} ]] && usage && exit 1

[[ -d "${PGDATA}" ]] && die "Will not overwrite existing PGDATA directory, stopping example restore"

LATESTBACKUP="$(ls -tr "${BACKUPDIR}/${PATRONI_SCOPE}/basebackup_"*.tar.gz | tail -n 1)"
[[ ! -f "${LATESTBACKUP}" ]] && die "Can not find the backup, stopping example restore"

mkdir -p "${PGDATA}"
tar xzfp "${LATESTBACKUP}" -C "${PGDATA}"
chmod 0700 "${PGDATA}"

echo "Restored ${LATESTBACKUP} into PGDATA=${PGDATA}"
6 changes: 6 additions & 0 deletions postgres2.yml
Expand Up @@ -72,6 +72,7 @@ postgresql:
create_replica_method:
- basebackup
# - wal_e
# - restore_example
# commented-out example for wal-e provisioning
#wal_e:
#command: /patroni/scripts/wale_restore.py
Expand All @@ -80,6 +81,11 @@ postgresql:
#threshold_backup_size_percentage: 30
#retries: 2
#use_iam: 1
# commented-out example for restore from file
#restore_example:
#command: patroni/scripts/restore_example.sh
#no_master: true
#backup_directory: /tmp/backup/
#recovery_conf:
#restore_command: envdir /etc/wal-e.d/env wal-e wal-fetch "%f" "%p" -p 1
recovery_conf:
Expand Down

0 comments on commit 5ca326b

Please sign in to comment.