Commit 0cd97e84 authored by Dave Lane's avatar Dave Lane
Browse files

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

parents 715b32f3 57f93492
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#
# run system backups
#
# 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
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
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
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.
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
......@@ -29,7 +29,7 @@ VERBOSE=0
#
# Stuff that should be universal for this install...
# where we can find this app...
MAIN_DIR=/etc/dbbackup
#MAIN_DIR=`pwd`
# determine today's date
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
......@@ -79,7 +79,7 @@ create_tmp_email() {
send_email_report() {
if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL"
$MAIL -s "$EMAIL_SUBJ" $EMAIL < $TMP_EMAIL
$MAIL -s "$EMAIL_SUBJ ($1)" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "failed to remove temporary email $TMP_EMAIL"
......@@ -135,17 +135,19 @@ delete_old() {
#
do_backup() {
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"
echo "--" > $FILE
echo "-- PostgreSQL Version: $VER" >> $FILE
echo "--" >> $FILE
echo "" >> $FILE
CMD="$DC exec $DC_CONTAINER $DUMP_CMD"
CMD="$DC exec -T $CONTAINER $DUMP_CMD"
verbose "doing database dump: $CMD"
$CMD >> $FILE
}
#
TASK=
#
# cycle through the command line options
while test $# -ne 0 ; do
......@@ -178,16 +180,24 @@ while test $# -ne 0 ; do
esac
shift
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_tmp_email
if ! [[ $TASK == 'HOURLY' ]] ; then
create_tmp_email
fi
#
if test -f $BU_CONF ; then
verbose "Reading default in $BU_CONF"
source $BU_CONF
if test -f $MAIN_DIR/$BU_CONF ; then
verbose "Reading default in $MAIN_DIR/$BU_CONF"
source $MAIN_DIR/$BU_CONF
else
error "Couldn't find or read $BU_CONF"
message "ERROR: Couldn't find or read $MAIN_DIR/$BU_CONF"
exit 1
fi
#
......@@ -215,7 +225,7 @@ delete_old $FILEPART ${!TO_KEEP}
message "backing up all the databases into $FILEPATH"
# dump the data into the file
#
do_backup $FILEPATH $TASK
do_backup $FILEPATH $DC_CONTAINER
#
message "completed backup"
# compress the backup
......@@ -226,5 +236,7 @@ cd $OLD_DIR
#
# sent resulting email report
#
send_email_report
if ! [[ $TASK == 'HOURLY' ]] ; then
send_email_report $TASK
fi
exit 0
......@@ -6,7 +6,7 @@ BU_DIR=/home/data/mastodon/backup
# Docker Compose details
#
# dir containing the docker-compose.yml
DC_DIR=/home/docker/mastodon-2.0.0
DC_DIR=/home/docker/mastodon
# name of the database container
DC_CONTAINER=postgres
# 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=webmaster@oerfoundation.org
EMAIL_SUBJ="Mastodon (on Open) Postgres Backup Report"
EMAIL_SUBJ="Mastodon on OERu Open Postgres Backup Report"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment