Skip to content

Instantly share code, notes, and snippets.

@keiya
Last active January 4, 2023 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keiya/c327d34417bb97456aab20ff2dc70de6 to your computer and use it in GitHub Desktop.
Save keiya/c327d34417bb97456aab20ff2dc70de6 to your computer and use it in GitHub Desktop.
PostgreSQL in docker online remote backup script (with encryption) useful for Mastodon
#!/bin/bash
cd /home/ec2-user/mastodon
TMPFILE=$(mktemp)
PASSWORD=xxxxxxx
DAY=$(date +"%a")
docker-compose exec db pg_dump -Z1 -Fc -U postgres postgres | openssl enc -aes-128-ctr -md sha256 -e -pass pass:$PASSWORD > $TMPFILE
rsync -avc --no-compress --progress $TMPFILE lastorbit@lastorbit.sakura.ne.jp:pg-backup-$DAY.encrypted
rm -f $TMPFILE
@keiya
Copy link
Author

keiya commented Jan 4, 2023

to decrypt:

openssl enc -aes-128-ctr -md sha256 -d -in pg-backup.encrypted -out pg-backup.decrypted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment