-
-
Save mohemohe/d16c6ce4140e5ef9ad47f9bc709adfd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
DATE="$(date +%Y/%m/%d)" | |
TARGET_PATH="/host/backup/mastodon/postgres/${DATE}" | |
docker ps -a -f 'status=exited' -f 'name=mastodon-postgres-backup' -q | xargs docker rm -f | |
CONTAINER_ID="$(docker ps -f 'name=PostgreSQL_replica' -q)" | |
FILENAME="dump.$(date +%Y%m%d_%H%M%S).sql" | |
if [ "${CONTAINER_ID}" != "" ]; then | |
mkdir -p "${TARGET_PATH}" | |
docker exec -i "${CONTAINER_ID}" /usr/bin/env psql -c 'SELECT pg_xlog_replay_pause();' | |
docker exec -it "${CONTAINER_ID}" /usr/bin/env pg_dumpall > "/tmp/${FILENAME}" | |
docker exec -i "${CONTAINER_ID}" /usr/bin/env psql -c 'SELECT pg_xlog_replay_resume();' | |
mv "/tmp/${FILENAME}" "${TARGET_PATH}/${FILENAME}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment