Compare commits

...

11 commits

5 changed files with 41 additions and 19 deletions

View file

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

View file

@ -22,14 +22,16 @@ BU_FROOT_WEEKLY=weekly
BU_FROOT_MONTHLY=monthly
BU_FROOT_YEARLY=yearly
#
# Set backup priority: -20 highest, 0 default, 19 lowest
NICE_VAL=0
# this can be overridden at invocation
BU_CONF=default-docker-compose.conf
# # output for debugging...
# output for debugging... 0 = false, 1 = true
VERBOSE=0
#
# Stuff that should be universal for this install...
# where we can find this app...
#MAIN_DIR=`pwd`
MAIN_DIR=/home/data/scripts/docker-compose-dbbackup
# determine today's date
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
@ -49,6 +51,8 @@ MAIL=`which mail`
# database dump utility
DC=`which docker-compose`
#DEF_ARGS="-C -d -O -x"
# nice
NICE=`which nice`
#
# pattern for "ls" command to build list of
# pruneable backup files...
@ -136,13 +140,13 @@ delete_old() {
do_backup() {
FILE=$1
CONTAINER=$2
VER=`$DC exec -T $CONTAINER pg_config --version`
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 -T $CONTAINER $DUMP_CMD"
CMD="$NICE -${NICE_VAL} $DC exec $CONTAINER $DUMP_CMD"
verbose "doing database dump: $CMD"
$CMD >> $FILE
}
@ -230,7 +234,7 @@ do_backup $FILEPATH $DC_CONTAINER
message "completed backup"
# compress the backup
message "compressing $FILEPATH"
$GZIP $FILEPATH
$NICE -${NICE_VAL} $GZIP $FILEPATH
# return to where you started from...
cd $OLD_DIR
#

View file

@ -17,3 +17,18 @@ DUMP_CMD='pg_dumpall -c -U postgres'
# email address to send reports to, and subject
EMAIL=webmaster@oerfoundation.org
EMAIL_SUBJ="Mastodon on OERu Open Postgres Backup Report"
#
# Optional overrides
#
# Default retention
#BU_TO_KEEP_HOURLY=24
#BU_TO_KEEP_DAILY=7
#BU_TO_KEEP_WEEKLY=4
#BU_TO_KEEP_MONTHLY=12
#BU_TO_KEEP_YEARLY=7
#
# Set backup priority: -20 highest, 0 default, 19 lowest
#NICE_VAL=0
#
# Verbosity 0 = false, 1 = true
#VERBOSE=0

21
mariadbbackup-docker-compose Normal file → Executable file
View file

@ -15,7 +15,7 @@ BU_TO_KEEP_WEEKLY=4
BU_TO_KEEP_MONTHLY=12
BU_TO_KEEP_YEARLY=7
#
BU_FROOT=alldbs
#BU_FROOT=alldbs
BU_FROOT_HOURLY=hourly
BU_FROOT_DAILY=daily
BU_FROOT_WEEKLY=weekly
@ -23,7 +23,7 @@ BU_FROOT_MONTHLY=monthly
BU_FROOT_YEARLY=yearly
#
# this can be overridden at invocation
BU_CONF=default-docker-compose.conf
BU_CONF=default-mariadb-docker-compose.conf
# # output for debugging...
VERBOSE=0
#
@ -135,9 +135,9 @@ delete_old() {
#
do_backup() {
FILE=$1
DATABASE="$(get_value DC_DB_NAME_VAR $DC_FILE)"
USER="$(get_value DC_DB_USER_VAR $DC_FILE)"
PASSWORD="$(get_value DC_DB_PASSWORD_VAR $DC_FILE)"
DATABASE="$(get_value $DC_DB_NAME_VAR $DC_FILE)"
USER="$(get_value $DC_DB_USER_VAR $DC_FILE)"
PASSWORD="$(get_value $DC_DB_PASSWORD_VAR $DC_FILE)"
verbose "debug - DB details: USER = $USER, PASSWORD = $PASSWORD, DB = $DATABASE"
VER=`$DC exec $DC_CONTAINER mysql --version`
verbose "MariaDB version $VER - echoing to backup: $FILE"
@ -162,7 +162,7 @@ while test $# -ne 0 ; do
case $1 in
--config|-c)
shift # shift from the flag to the value
verbose "setting configuration directory to $1"
verbose "setting configuration file to $1"
BU_CONF=$1
;;
--hourly|-h)
@ -191,13 +191,13 @@ done
#
#
# create the blank email report
create_tmp_email
#create_tmp_email
#
if test -f $BU_CONF ; then
verbose "Reading default in $BU_CONF"
source $BU_CONF
else
error "Couldn't find or read $BU_CONF"
message "Couldn't find or read $BU_CONF"
exit 1
fi
#
@ -211,6 +211,9 @@ cd $DC_DIR
#
# a timestamp for logging purposes
STAMP=`date '+%Y-%m-%d_%H-%M-%S'`
#
# set the root based on the name of the database...
BU_FROOT="$(get_value $DC_DB_NAME_VAR $DC_FILE)"
#
# generate the filename
INC="BU_FROOT_$TASK"
@ -236,5 +239,5 @@ cd $OLD_DIR
#
# sent resulting email report
#
send_email_report
#send_email_report
exit 0