Merge branch 'master' of git.oeru.org:oeru/docker-compose-dbbackup

This commit is contained in:
Dave Lane 2022-06-09 15:31:57 +12:00
commit 0cd97e84f9
4 changed files with 34 additions and 19 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.conf

View file

@ -1,18 +1,20 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# #
# run system backups # run system backups
# #
# hourly - at 5 minutes past mon-sat # hourly - at 5 minutes past mon-sat
05 * * * * root /etc/dbbackup/dbbackup-docker-compose --hourly 25 * * * * root /home/data/mastodon.oeru.org/scripts/dbbackup/dbbackup-docker-compose -c /home/data/mastodon.oeru.org/scripts/dbbackup/mastodon.conf --hourly
# #
# daily - at 7:30 pm, mon-sat # daily - at 7:30 pm, mon-sat
30 19 * * * root /etc/dbbackup/dbbackup-docker-compose --daily 30 19 * * * root /home/data/mastodon.oeru.org/scripts/dbbackup/dbbackup-docker-compose -c /home/data/mastodon.oeru.org/scripts/dbbackup/mastodon.conf --daily
# #
# weekly - at 7:30 pm, sun # weekly - at 7:30 pm, sun
30 19 * * sun root /etc/dbbackup/dbbackup-docker-compose --weekly 30 19 * * sun root /home/data/mastodon.oeru.org/scripts/dbbackup/dbbackup-docker-compose -c /home/data/mastodon.oeru.org/scripts/dbbackup/mastodon.conf --weekly
# #
# monthly - at 8:30 pm, on the first of the last of the month # monthly - at 8:30 pm, on the first of the last of the month
30 20 1 * * root /etc/dbbackup/dbbackup-docker-compose --monthly 30 20 1 * * root /home/data/mastodon.oeru.org/scripts/dbbackup/dbbackup-docker-compose -c /home/data/mastodon.oeru.org/scripts/dbbackup/mastodon.conf --monthly
# #
# yearly - at 8:30 pm, on the first of January. # yearly - at 8:30 pm, on the first of January.
30 20 1 1 * root /etc/dbbackup/dbbackup-docker-compose --yearly 30 20 1 1 * root /home/data/mastodon.oeru.org/scripts/dbbackup/dbbackup-docker-compose -c /home/data/mastodon.oeru.org/scripts/dbbackup/mastodon.conf--yearly

View file

@ -29,7 +29,7 @@ VERBOSE=0
# #
# Stuff that should be universal for this install... # Stuff that should be universal for this install...
# where we can find this app... # where we can find this app...
MAIN_DIR=/etc/dbbackup #MAIN_DIR=`pwd`
# determine today's date # determine today's date
DATE=`date '+%Y-%m-%d-%a'` DATE=`date '+%Y-%m-%d-%a'`
# determine today's date # determine today's date
@ -79,7 +79,7 @@ create_tmp_email() {
send_email_report() { send_email_report() {
if test -f $TMP_EMAIL ; then if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL" message "sending email report to $EMAIL"
$MAIL -s "$EMAIL_SUBJ" $EMAIL < $TMP_EMAIL $MAIL -s "$EMAIL_SUBJ ($1)" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then if test -f $TMP_EMAIL ; then
message "failed to remove temporary email $TMP_EMAIL" message "failed to remove temporary email $TMP_EMAIL"
@ -135,17 +135,19 @@ delete_old() {
# #
do_backup() { do_backup() {
FILE=$1 FILE=$1
VER=`$DC exec $DC_CONTAINER pg_config --version` CONTAINER=$2
VER=`$DC exec -T $CONTAINER pg_config --version`
verbose "Postgres version $VER - echoing to backup: $FILE" verbose "Postgres version $VER - echoing to backup: $FILE"
echo "--" > $FILE echo "--" > $FILE
echo "-- PostgreSQL Version: $VER" >> $FILE echo "-- PostgreSQL Version: $VER" >> $FILE
echo "--" >> $FILE echo "--" >> $FILE
echo "" >> $FILE echo "" >> $FILE
CMD="$DC exec $DC_CONTAINER $DUMP_CMD" CMD="$DC exec -T $CONTAINER $DUMP_CMD"
verbose "doing database dump: $CMD" verbose "doing database dump: $CMD"
$CMD >> $FILE $CMD >> $FILE
} }
#
TASK=
# #
# cycle through the command line options # cycle through the command line options
while test $# -ne 0 ; do while test $# -ne 0 ; do
@ -178,16 +180,24 @@ while test $# -ne 0 ; do
esac esac
shift shift
done done
#
# we must have *some* task specified
if [[ $TASK == '' ]] ; then
message "No TASK specified! Pick --hourly, --daily, --weekly, --monthly, --yearly..."
exit 1
fi
# #
# #
# create the blank email report # create the blank email report
create_tmp_email if ! [[ $TASK == 'HOURLY' ]] ; then
create_tmp_email
fi
# #
if test -f $BU_CONF ; then if test -f $MAIN_DIR/$BU_CONF ; then
verbose "Reading default in $BU_CONF" verbose "Reading default in $MAIN_DIR/$BU_CONF"
source $BU_CONF source $MAIN_DIR/$BU_CONF
else else
error "Couldn't find or read $BU_CONF" message "ERROR: Couldn't find or read $MAIN_DIR/$BU_CONF"
exit 1 exit 1
fi fi
# #
@ -215,7 +225,7 @@ delete_old $FILEPART ${!TO_KEEP}
message "backing up all the databases into $FILEPATH" message "backing up all the databases into $FILEPATH"
# dump the data into the file # dump the data into the file
# #
do_backup $FILEPATH $TASK do_backup $FILEPATH $DC_CONTAINER
# #
message "completed backup" message "completed backup"
# compress the backup # compress the backup
@ -226,5 +236,7 @@ cd $OLD_DIR
# #
# sent resulting email report # sent resulting email report
# #
send_email_report if ! [[ $TASK == 'HOURLY' ]] ; then
send_email_report $TASK
fi
exit 0 exit 0

View file

@ -6,7 +6,7 @@ BU_DIR=/home/data/mastodon/backup
# Docker Compose details # Docker Compose details
# #
# dir containing the docker-compose.yml # dir containing the docker-compose.yml
DC_DIR=/home/docker/mastodon-2.0.0 DC_DIR=/home/docker/mastodon
# name of the database container # name of the database container
DC_CONTAINER=postgres DC_CONTAINER=postgres
# Command to dump the relevant database(s) # Command to dump the relevant database(s)
@ -16,4 +16,4 @@ DUMP_CMD='pg_dumpall -c -U postgres'
# #
# email address to send reports to, and subject # email address to send reports to, and subject
EMAIL=webmaster@oerfoundation.org EMAIL=webmaster@oerfoundation.org
EMAIL_SUBJ="Mastodon (on Open) Postgres Backup Report" EMAIL_SUBJ="Mastodon on OERu Open Postgres Backup Report"