Skip to content

Commit ec41126

Browse files
committed
add postgres backups to install.sh
1 parent 12cc314 commit ec41126

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

devops/sh/install.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
apt-get update
4-
apt-get install -y wget curl git tmux postgresql build-essential libssl-dev make automake autoconf libncurses5-dev gcc default-jre certbot nginx ufw
4+
apt-get install -y wget curl git tmux postgresql build-essential libssl-dev make automake autoconf libncurses5-dev gcc default-jre certbot nginx ufw python3-pip lzop pv
55

66
# install erlang
77
curl -O https://raw.githubusercontent.com/kerl/kerl/master/kerl
@@ -28,6 +28,29 @@ sudo -u postgres psql -c "ALTER USER holiday_ping WITH PASSWORD 'holiday_ping';"
2828
cp /root/holiday_ping/priv/sql/tables.sql /tmp/
2929
sudo -u postgres psql -a -f /tmp/tables.sql
3030

31+
# setup db backups
32+
echo '
33+
wal_level = replica
34+
' >> /etc/postgresql/9.6/main/postgresql.conf
35+
service postgresql restart
36+
37+
sudo python3 -m pip install wal-e[aws]
38+
echo "cd /var/lib/postgresql/
39+
sudo -u postgres \
40+
AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY AWS_REGION=us-east-1 wal-e \
41+
-k $AWS_ACCESS_KEY_ID \
42+
--s3-prefix=s3://lambdaclass.com/holiday_ping/backups \
43+
backup-push /var/lib/postgresql/9.6/main
44+
45+
sudo -u postgres \
46+
AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY AWS_REGION=us-east-1 wal-e \
47+
-k $AWS_ACCESS_KEY_ID \
48+
--s3-prefix=s3://lambdaclass.com/holiday_ping/backups \
49+
delete --confirm retain 5
50+
" > /usr/bin/holiday-backup
51+
chmod +x /usr/bin/holiday-backup
52+
echo '0 0 * * * /usr/bin/holiday-backup > /var/log/holiday-backup.log 2>&1' | crontab
53+
3154
# get ssl certificates. issue with already running port
3255
certbot certonly --standalone -d holidayping.lambdaclass.com
3356

0 commit comments

Comments
 (0)