Back up your hobbyist postgres cluster so when your Spot instance terminates you aren't sad

By Ryan Romanchuk

Not that this didn't just happen to me, but If you're feeling folksy and don't want to fork over that t3.micro RDS cash, you should probably backup your db so you don't lose all the drafts you wrote since your last AMI image[1].

Like to a mounted EFS[2] drive
sudo -i -u postgres
pg_dumpall > /home/ubuntu/efs/${date "+%Y-%m-%d"}_backup.sql"
Or on a cron
sudo -i -u postgres && crontab -e
0 0 * * * pg_dumpall > /home/ubuntu/efs/${date +\%Y\%m\%d}_backup.sql
And since you probably forgot
groupadd efs
usermod -a -G efs ubuntu
usermod -a -G efs postgres
chgrp mygroup /home/ubuntu/efs
chmod g+rwx /home/ubuntu/efs

  1. ↩︎

  2. ↩︎