Skip to content

Instantly share code, notes, and snippets.

@sandsu
Last active September 23, 2015 14:15
Show Gist options
  • Save sandsu/2aeab3e71100d58e48b7 to your computer and use it in GitHub Desktop.
Save sandsu/2aeab3e71100d58e48b7 to your computer and use it in GitHub Desktop.
WAL-E and Cloud66
# WAL-E (https://github.com/wal-e/wal-e) install
sudo su
source /var/.cloud66_env
sudo apt-get install daemontools
sudo apt-get install -y python-virtualenv python-dev git libevent-dev pv lzop vim
sudo pip install git+https://github.com/wal-e/wal-e
umask u=rwx,g=rx,o=
mkdir -p /etc/wal-e.d/env
echo $AWS_SECRET_ACCESS_KEY > /etc/wal-e.d/env/AWS_SECRET_ACCESS_KEY
echo $AWS_ACCESS_KEY_ID > /etc/wal-e.d/env/AWS_ACCESS_KEY_ID
echo $WALE_S3_PREFIX > /etc/wal-e.d/env/WALE_S3_PREFIX
chown -R root:postgres /etc/wal-e.d
# Postgresql config to enable wal backup
wal_level = archive
archive_mode = on
archive_command = 'envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push %p'
archive_timeout = 60
sudo /etc/init.d/postgresql restart
# First base backup. You should do this periodically with cron.
sudo -u postgres bash -c "cd ;envdir /etc/wal-e.d/env /usr/local/bin/wal-e backup-push /usr/local/pgsql/data"
#RECOVERY
# On new postgresql server run this script
sudo /etc/init.d/postgresql stop
cp /usr/local/pgsql/data/postgresql.conf ~
cp /usr/local/pgsql/data/pg_ident.conf ~
cp /usr/local/pgsql/data/pg_hba.conf ~
rm -rf /usr/local/pgsql/data
sudo -u postgres bash -c "cd ; envdir /etc/wal-e.d/env /usr/local/bin/wal-e backup-fetch /usr/local/pgsql/data LATEST"
echo "restore_command = '/usr/bin/envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-fetch %f %p'\n recovery_target_time = '2014-10-07 16:58:00'" > /usr/local/pgsql/data/recovery.conf
cp ~/postgresql.conf /usr/local/pgsql/data/
cp ~/pg_ident.conf /usr/local/pgsql/data/
cp ~/pg_hba.conf /usr/local/pgsql/data/
sudo chown -Rf postgres:postgres /usr/local/pgsql/data/
sudo chmod 700 /usr/local/pgsql/data/
sudo /etc/init.d/postgresql start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment