Something went wrong. Try again.
Docker files for the TLE Community deployment
Something went wrong. Try again.
deployment mysql-dump.sh
1.3 kB · 34 lines
Shell
at main
1234567891011121314151617181920212223242526272829303132333435#!/bin/sh# Nightly logical backup of the lacuna database.## Runs *inside* the mysql container, invoked on a schedule by Ofelia# (see the [job-exec "mysql-dump"] block in schedule.ini). Output and retention# live on the host-mounted ./data/backups tree.## /bin/sh in the mysql:5.5 image is dash, which has no `set -o pipefail`, so the# dump is written to disk first and only compressed/published once mysqldump has# exited 0 -- a failed run never leaves a half-written .sql.gz under the real name.set -eu
BACKUP_DIR=/backupsKEEP_DAYS=7STAMP=$(date +%Y%m%d-%H%M%S)RAW="$BACKUP_DIR/.lacuna-$STAMP.sql"DEST="$BACKUP_DIR/lacuna-$STAMP.sql.gz"
mkdir -p "$BACKUP_DIR"
mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" \ --single-transaction --quick \ --routines --triggers --events \ --add-drop-database --databases lacuna > "$RAW"
gzip "$RAW" # -> $RAW.gz (still hidden)mv "$RAW.gz" "$DEST" # publish atomically under the real name
# Retention: drop published backups older than KEEP_DAYS, plus any stale work# files left behind by an interrupted run.find "$BACKUP_DIR" -maxdepth 1 -name 'lacuna-*.sql.gz' -type f -mtime "+$KEEP_DAYS" -deletefind "$BACKUP_DIR" -maxdepth 1 -name '.lacuna-*.sql*' -type f -mtime +1 -delete
echo "mysql-dump: wrote $DEST ($(du -h "$DEST" | cut -f1))"