-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from SUNET/jocar-mastodon-backup
Backup Mastodon to baas2
- Loading branch information
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
set -eou pipefail | ||
|
||
backupdir=/opt/backups | ||
backuptime=$(date +%Y-%m-%d.%H) | ||
localretentiondays=15 | ||
|
||
# Steal credentials of off docker containers env, used in connection string below | ||
# DOCKER_PG_LLVM_DEPS contains multiple values with tab(?) as delimiter… | ||
# shellcheck disable=SC1090 | ||
source <(docker exec -u postgres postgres env | grep -v DOCKER_PG_LLVM_DEPS) | ||
|
||
mkdir -p "${backupdir}"/{postgres,redis} | ||
|
||
docker exec postgres pg_dumpall --clean --if-exists --no-password \ | ||
--dbname "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost" \ | ||
| gzip > "${backupdir}/postgres/postgres-${backuptime}.sql.gz" | ||
|
||
cp /opt/mastodon_backend/redis/dump.rdb "${backupdir}/redis/redis-${backuptime}.rdb" | ||
|
||
# Send away the dumped files | ||
/usr/bin/dsmc backup | ||
|
||
find "${backupdir}/postgres" -mtime +${localretentiondays} -exec rm {} \; | ||
find "${backupdir}/redis" -mtime +${localretentiondays} -exec rm {} \; | ||
|
||
# Only store one dump per day for files older then yesterday | ||
while IFS= read -r -d '' file | ||
do | ||
oclock=$(echo "$file" | cut -d . -f 2) | ||
if [ "${oclock}x" != "00x" ]; then | ||
rm "$file" | ||
fi | ||
|
||
done < <(find /opt/backups/ -type -f -mtime +1 -name -print0) |