Skip to content

Commit

Permalink
feat(backups): create weekly partial backup for RISM
Browse files Browse the repository at this point in the history
Adds functionality to `db_backup.sh` and `postgres_backup.sh`
to create a weekly backup of some tables in the database for RISM's
use. user, auth, and reversion tables are not included.

The backup is added to the backup directory (defined in ansible
deployment) in the `rism` subdirectory.
  • Loading branch information
dchiller committed Aug 21, 2024
1 parent 1645e51 commit ce71776
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cron/postgres/db_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BACKUP_FILENAME=$(date "+%Y-%m-%dT%H:%M:%S").sql.gz # This is th


# Create the backup and copy it to the daily backup directory
mkdir -p $BACKUP_DIR/daily $BACKUP_DIR/weekly $BACKUP_DIR/monthly $BACKUP_DIR/yearly
mkdir -p $BACKUP_DIR/daily $BACKUP_DIR/weekly $BACKUP_DIR/monthly $BACKUP_DIR/yearly $BACKUP_DIR/rism
/usr/bin/docker exec cantusdb-postgres-1 /usr/local/bin/postgres_backup.sh $BACKUP_FILENAME
/usr/bin/docker cp cantusdb-postgres-1:/var/lib/postgresql/backups/$BACKUP_FILENAME $BACKUP_DIR/daily
/usr/bin/docker exec cantusdb-postgres-1 rm /var/lib/postgresql/backups/$BACKUP_FILENAME
Expand All @@ -34,10 +34,14 @@ MONTH_OF_YEAR=$(date "+%m")

# Retain weekly backups on Mondays
# Manage retention of weekly backups
# Copy the partial export for RISM purposes (created weekly on Mondays)
if [ $DAY_OF_WEEK -eq 1 ]; then
cp $BACKUP_DIR/daily/$BACKUP_FILENAME $BACKUP_DIR/weekly
FILES_TO_REMOVE=$(ls -td $BACKUP_DIR/weekly/* | tail -n +9)
[[ ! -z "$FILES_TO_REMOVE" ]] && rm $FILES_TO_REMOVE
# Copy the partial DB backup for RISM purposes to $BACKUP_DIR/rism
/usr/bin/docker cp cantusdb-postgres-1:/var/lib/postgresql/backups/cantusdb_rism_export.sql.gz $BACKUP_DIR/rism
/usr/bin/docker exec cantusdb-postgres-1 rm /var/lib/postgresql/backups/cantusdb_rism_export.sql.gz
fi

# Retain a monthly backup on the first day of the month
Expand Down
10 changes: 9 additions & 1 deletion postgres/postgres_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
# Script backs up the Cantus Database in a compressed SQL file

mkdir -p /var/lib/postgresql/backups
pg_dump cantusdb -U cantusdb | gzip > /var/lib/postgresql/backups/$1
# Create a full DB backup for recovery purposes
pg_dump cantusdb -U cantusdb | gzip > /var/lib/postgresql/backups/$1


# Create a partial DB backup for RISM purposes on Mondays
DAY_OF_WEEK=$(date "+%u")
if [ $DAY_OF_WEEK -eq 1 ]; then
pg_dump -U cantusdb -d cantusdb -T 'auth*' -T 'users*' -T 'reversion*' | gzip > /var/lib/postgresql/backups/cantusdb_rism_export.sql.gz
fi

0 comments on commit ce71776

Please sign in to comment.