Skip to content

Instantly share code, notes, and snippets.

@Geesu
Created January 17, 2014 16:27
Show Gist options
  • Save Geesu/8476386 to your computer and use it in GitHub Desktop.
Save Geesu/8476386 to your computer and use it in GitHub Desktop.
Example of a archive_command bash script to replication to 2 different servers. Like the local_backup_script.sh referenced here: http://www.postgresql.org/docs/current/static/continuous-archiving.html#BACKUP-SCRIPTS
#!/bin/bash
FAIL=0
job_1 = `rsync -aq $1 postgres@server1:/var/lib/postgresql/9.2/archive/$2`
job_2 = `rsync -aq $1 postgres@server2:/var/lib/postgresql/9.2/archive/$2`
$job_1 & pid_1=$! ; $job_2 & pid_2=$!
echo "Spawned replication processes $pid_1 AND $pid_2"
wait $pid_1 || let "FAIL+=1"
wait $pid_2|| let "FAIL+=1"
if [ "$FAIL" == "0" ];
then
echo "Replication success $1 $2"
else
echo "Replication failed $1 $2"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment