2025-01-21
·
Cristian Jesus Alvarez Hernandez
It is a simple docker container running a postgres server in a aws ec2 instance with a cron job for backups stored in s3, nothing else, that's it. Just run a command and you will have your boring database.
It is a simple docker container running a postgres server in a aws ec2 instance with a cron job for backups stored in s3, nothing else, that's it.
Just run a command and you will have your boring database.
You need to have aws cli installed in your machine and configured with your aws credentials with enough permissions to create the stack in cloudformation.
You need to specify the s3 bucket for backups in a .env file in the project root folder, the rest of the variables are optional and will use the default values, use .env.example as a reference, example:
BACKUP_CRON_EXPRESSION="0 2 * * *"
S3_BUCKET=just-a-db-backups
AWS_REGION=us-east-1
Run the following command
make setup
That's all, it will create the following infrastructure in you aws account:

just-a-db/database-logs and just-a-db/backup-logs.backup_<database_name>_<timestamp>.sql.gz. Only the 3 most recent backups are kept, the oldest ones are deleted.just-a-db.make credentials, it will store the credentials in the credentials.txt file.just-a-db.pem file, that is the private key for the ec2 instance, you need to keep it safe and secure.make connect Connect to the ec2 instance using the private key via ssh.make credentials Get the credentials for the database and store them in the credentials.txt file.make destroy Destroy the infrastructure (aws cloudformation stack).Comments
Cristian Jesus Alvarez Hernandez
2025-01-21, 2:46 a.m.
Hi
Cristian Jesus Alvarez Hernandez
2025-01-21, 2:41 a.m.
Nice, brou