From 61941eed22528013b24cd2845daacc0c67e8fe0c Mon Sep 17 00:00:00 2001 From: Dave lane Date: Fri, 9 Feb 2018 14:46:14 +1300 Subject: [PATCH 1/6] fixed bad config file path and reference to missing function --- dbbackup-docker-compose | 8 ++++---- default-docker-compose.conf | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dbbackup-docker-compose b/dbbackup-docker-compose index 3368463..28cc035 100755 --- a/dbbackup-docker-compose +++ b/dbbackup-docker-compose @@ -183,11 +183,11 @@ done # create the blank email report create_tmp_email # -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 # diff --git a/default-docker-compose.conf b/default-docker-compose.conf index 755faa6..ed02f86 100644 --- a/default-docker-compose.conf +++ b/default-docker-compose.conf @@ -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) From 74936e58427ed04ce1eb2e0f749d7f7f5bd0c3e3 Mon Sep 17 00:00:00 2001 From: Dave lane Date: Fri, 9 Feb 2018 15:23:05 +1300 Subject: [PATCH 2/6] fixed variable scope issue, improved email report subject --- dbbackup-docker-compose | 13 +++++++------ default-docker-compose.conf | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dbbackup-docker-compose b/dbbackup-docker-compose index 28cc035..3f300a0 100755 --- a/dbbackup-docker-compose +++ b/dbbackup-docker-compose @@ -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,13 +135,14 @@ delete_old() { # do_backup() { FILE=$1 - VER=`$DC exec $DC_CONTAINER pg_config --version` + CONTAINER=$2 + VER=`$DC exec $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 $CONTAINER $DUMP_CMD" verbose "doing database dump: $CMD" $CMD >> $FILE } @@ -181,7 +182,7 @@ done # # # create the blank email report -create_tmp_email +create_tmp_email # if test -f $MAIN_DIR/$BU_CONF ; then verbose "Reading default in $MAIN_DIR/$BU_CONF" @@ -215,7 +216,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 +227,5 @@ cd $OLD_DIR # # sent resulting email report # -send_email_report +send_email_report $TASK exit 0 diff --git a/default-docker-compose.conf b/default-docker-compose.conf index ed02f86..0e4c8d2 100644 --- a/default-docker-compose.conf +++ b/default-docker-compose.conf @@ -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" From 4c9ca12a93a0139ad3d83308ecd79cfff975f5aa Mon Sep 17 00:00:00 2001 From: Dave lane Date: Fri, 9 Feb 2018 16:28:44 +1300 Subject: [PATCH 3/6] fixed path issue and docker-compose exec TTY problem --- dbbackup-cron | 2 ++ dbbackup-docker-compose | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dbbackup-cron b/dbbackup-cron index f8dae27..ef9d0c7 100644 --- a/dbbackup-cron +++ b/dbbackup-cron @@ -1,3 +1,5 @@ +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # # run system backups # diff --git a/dbbackup-docker-compose b/dbbackup-docker-compose index 3f300a0..1d5cc13 100755 --- a/dbbackup-docker-compose +++ b/dbbackup-docker-compose @@ -136,13 +136,13 @@ delete_old() { do_backup() { FILE=$1 CONTAINER=$2 - VER=`$DC exec $CONTAINER pg_config --version` + 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 $CONTAINER $DUMP_CMD" + CMD="$DC exec -T $CONTAINER $DUMP_CMD" verbose "doing database dump: $CMD" $CMD >> $FILE } From 264656141c38630c40d54649239c89c3f9088e06 Mon Sep 17 00:00:00 2001 From: Dave lane Date: Fri, 9 Feb 2018 16:32:54 +1300 Subject: [PATCH 4/6] removing default-docker-compose.conf to avoid merge issues on other installs --- .gitignore | 1 + default-docker-compose.conf-sample | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 .gitignore create mode 100644 default-docker-compose.conf-sample diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c5ddb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +default-docker-compose.conf diff --git a/default-docker-compose.conf-sample b/default-docker-compose.conf-sample new file mode 100644 index 0000000..0e4c8d2 --- /dev/null +++ b/default-docker-compose.conf-sample @@ -0,0 +1,19 @@ +# +# SQL dump backup directory +# +BU_DIR=/home/data/mastodon/backup +# +# Docker Compose details +# +# dir containing the docker-compose.yml +DC_DIR=/home/docker/mastodon +# name of the database container +DC_CONTAINER=postgres +# Command to dump the relevant database(s) +DUMP_CMD='pg_dumpall -c -U postgres' +# +# Reporting +# +# email address to send reports to, and subject +EMAIL=webmaster@oerfoundation.org +EMAIL_SUBJ="Mastodon on OERu Open Postgres Backup Report" From 71cd801c198dc6b0b186a12aa310549f6c538863 Mon Sep 17 00:00:00 2001 From: Dave lane Date: Mon, 12 Feb 2018 11:14:38 +1300 Subject: [PATCH 5/6] no more emails for hourly backups, don't run if no task is specified --- dbbackup-docker-compose | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/dbbackup-docker-compose b/dbbackup-docker-compose index 1d5cc13..e9ec0c2 100755 --- a/dbbackup-docker-compose +++ b/dbbackup-docker-compose @@ -146,7 +146,8 @@ do_backup() { verbose "doing database dump: $CMD" $CMD >> $FILE } - +# +TASK= # # cycle through the command line options while test $# -ne 0 ; do @@ -179,10 +180,18 @@ 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 $MAIN_DIR/$BU_CONF ; then verbose "Reading default in $MAIN_DIR/$BU_CONF" @@ -227,5 +236,7 @@ cd $OLD_DIR # # sent resulting email report # -send_email_report $TASK +if ! [[ $TASK == 'HOURLY' ]] ; then + send_email_report $TASK +fi exit 0 From 57f93492aa3e29b01427acc58ab7f8f93ab31be5 Mon Sep 17 00:00:00 2001 From: Dave Lane Date: Thu, 10 Oct 2019 02:57:41 +0000 Subject: [PATCH 6/6] updated script to work in new location closer to Mastodon code --- .gitignore | 2 +- dbbackup-cron | 12 ++++++------ dbbackup-docker-compose | 2 +- default-docker-compose.conf | 19 ------------------- 4 files changed, 8 insertions(+), 27 deletions(-) delete mode 100644 default-docker-compose.conf diff --git a/.gitignore b/.gitignore index 6c5ddb6..fee9217 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -default-docker-compose.conf +*.conf diff --git a/dbbackup-cron b/dbbackup-cron index ef9d0c7..4b50a2c 100644 --- a/dbbackup-cron +++ b/dbbackup-cron @@ -1,20 +1,20 @@ -SHELL=/bin/sh +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 diff --git a/dbbackup-docker-compose b/dbbackup-docker-compose index e9ec0c2..a44cc57 100755 --- a/dbbackup-docker-compose +++ b/dbbackup-docker-compose @@ -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 diff --git a/default-docker-compose.conf b/default-docker-compose.conf deleted file mode 100644 index 0e4c8d2..0000000 --- a/default-docker-compose.conf +++ /dev/null @@ -1,19 +0,0 @@ -# -# SQL dump backup directory -# -BU_DIR=/home/data/mastodon/backup -# -# Docker Compose details -# -# dir containing the docker-compose.yml -DC_DIR=/home/docker/mastodon -# name of the database container -DC_CONTAINER=postgres -# Command to dump the relevant database(s) -DUMP_CMD='pg_dumpall -c -U postgres' -# -# Reporting -# -# email address to send reports to, and subject -EMAIL=webmaster@oerfoundation.org -EMAIL_SUBJ="Mastodon on OERu Open Postgres Backup Report"