| config/mariadb.cfg | ●●●●● patch | view | raw | blame | history | |
| dbb | ●●●●● patch | view | raw | blame | history | |
| dbb-modules/mariadb | ●●●●● patch | view | raw | blame | history | |
| dbb-modules/postgresql | ●●●●● patch | view | raw | blame | history |
config/mariadb.cfg
@@ -1,11 +1,5 @@ ################################################################################ # ToDo MYSQL_BACKUP_LOCAL=FALSE ################################################################################ # ToDo MYSQL_BACKUP_REMOTE=FALSE MARIADB_BACKUP_REMOTE=YES ################################################################################ dbb
@@ -29,13 +29,13 @@ # Check if the configuration exists and is not empty if [ -r $BACKUPCFG ] && [ -s $BACKUPCFG ]; then # If true then read it . $BACKUPCFG source $BACKUPCFG if [ -d $BACKUPCFG.d ]; then if [ ! "$(ls -A $BACKUPCFG.d)" ]; then if [ ! "$(find $BACKUPCFG.d/*.cfg | cut -d "." -f1)" ]; then echo "Configurationdirectory for modules exist but it is empty" | /usr/bin/logger -s -i -t databasebackup else echo "Read module configuration" | /usr/bin/logger -s -i -t databasebackup for MODULECFG in $(ls $BACKUPCFG.d); do . $BACKUPCFG.d/$MODULECFG; done for MODULECFG in $(find $BACKUPCFG.d/*.cfg | cut -d "/" -f4 | cut -d "." -f1); do source $BACKUPCFG.d/$MODULECFG.cfg; done fi else echo "Configurationdirectory does not exists, can't load any configurationfile" | /usr/bin/logger -s -i -t databasebackup @@ -48,15 +48,15 @@ fi if [ "$ENABLE_DEBUG" = "TRUE" ]; then # If debugoutput is enabled show the configurationfile without comments echo "####dd############################################################################" | /usr/bin/logger -s -i -t databasebackup echo "##################################################################################" | /usr/bin/logger -s -i -t databasebackup while read -r configline; do echo "$configline" | grep -v '^$' | grep -v '^#' | /usr/bin/logger -s -i -t databasebackup done <<< "$(cat $BACKUPCFG)" for MODCFGLINE in $(ls $BACKUPCFG.d); do for MODCFGLINE in $(find $BACKUPCFG.d/*.cfg | cut -d "." -f1); do echo "Debuginfo for $MODCFGLINE" | /usr/bin/logger -s -i -t databasebackup while read -r modconfigline; do echo "$modconfigline" | grep -v '^$' | grep -v '^#' | /usr/bin/logger -s -i -t databasebackup done <<< $(cat $BACKUPCFG.d/$MODCFGLINE) done <<< "$(cat $BACKUPCFG.d/$MODCFGLINE.cfg)" done echo "################################################################################" | /usr/bin/logger -s -i -t databasebackup fi @@ -99,8 +99,8 @@ if [ ! "$(ls -A $BACKUPCFG.d)" ] && [ ! "$(ls -A $INSTALLATION_PATH_PREFIX/lib/dbb-modules)" ]; then debug "Configurationdirectory or directory for modules exist but it is empty" else for MODULE in $(ls $BACKUPCFG.d | cut -d "." -f1); do . $INSTALLATION_PATH_PREFIX/lib/dbb-modules/$MODULE for MODULE in $(find $BACKUPCFG.d/*.cfg | cut -d "/" -f4 | cut -d "." -f1); do source $INSTALLATION_PATH_PREFIX/lib/dbb-modules/$MODULE debug "Load module: $INSTALLATION_PATH_PREFIX/lib/dbb-modules/$MODULE" # Check the dependenncies defined in the modulefunction -> should be defined in configfiles check-$MODULE-deps @@ -234,7 +234,7 @@ debug "Load dbb-modules" load_dbbmodules # Run modul-main-functions for MODULEMAIN in $(ls $BACKUPCFG.d | cut -d "." -f1); do for MODULEMAIN in $(find $BACKUPCFG.d/*.cfg | cut -d "/" -f4 | cut -d "." -f1); do debug "run $MODULEMAIN-main - function of module $MODULEMAIN" $MODULEMAIN-main done dbb-modules/mariadb
@@ -3,17 +3,42 @@ # MariaBD/MySQL remote # # The Information what MySQL/MariaDB - databases should be backuped are defined in ~/.my.cnf # # note:for MARIADB in $(ls .my.cnf-* | cut -d "-" -f2); do mysqldump --defaults-file="~/.my.cnf-$MARIADB" --skip-dump-date $MARIADB > $TMP_DIR/$(cat ~/.my.cnf-$DATABASE | grep host | cut -d "=" -f2); done # note: for each MySQL- or MariaDB-Database create a seperate configfile .my.cnf-dbname ind the ~ of the backupuser: # note: replase the suffixe -dbname with the name of the database. The seperating "-" can also be a ".". # [mysqldump] # host=HOSTNAME # user=DBUSERNAME # password=PASSWORD # database=DATABASENAME function run_mysql_backups { debug "Dump remote database $MYSQLDB from $MYSQLDBHOST" /usr/bin/mysqldump --skip-dump-date -h "$MYSQLDBHOST" -u "$MYSQLDBUSER" -p"$MYSQLPASSWD" "$MYSQLDB" > "$TMP_DIR"/"$MYSQLDBHOST"_"$MYSQLDB".mysql function check-mariadb-deps { if [ ! -e /usr/bin/mysqldump ]; then debug "It seems that you dont have mysqldump installed. You may have problems to backup remote databases" fi # TODO: Check for ~/.my.cnf-* } function mariadb_remote { MARIADBHOSTNAME=$(cat ~/.my.cnf-$DATABASE | grep host | cut -d "=" -f2) for MARIADB in $(ls .my.cnf-* | cut -d "-" -f2) do /usr/bin/mysqldump --defaults-file="~/.my.cnf-$MARIADB" --skip-dump-date $MARIADB > $TMP_DIR/$MARIADBHOSTNAME_$MARIADB.mysql debug "Diff MySQLDump $MYSQLDB" diff "$TMP_DIR"/"$MYSQLDBHOST"_"$MYSQLDB".mysql "$BACKUP_DIR"/"$MYSQLDBHOST"_"$MYSQLDB".mysql > /dev/null 2>&1 diff "$TMP_DIR"/"$MARIADBHOSTNAME"_"$MARIADB".mysql "$BACKUP_DIR"/"$MARIADBHOSTNAME"_"$MARIADB".mysql > /dev/null 2>&1 if [ $? -ne 0 ]; then debug "Differences found -> moving to BACKUP_DIR" mv "$TMP_DIR"/"$MYSQLDBHOST"_"$MYSQLDB".mysql "$BACKUP_DIR"/"$MYSQLDBHOST"_"$MYSQLDB".mysql mv "$TMP_DIR"/"$MARIADBHOSTNAME"_"$MARIADB".mysql "$BACKUP_DIR"/"$MARIADBHOSTNAME"_"$MARIADB".mysql else debug "No differences found an Database $MYSQLDB" debug "No differences found in Database $MARIADB" fi echo "" done } function mariadb-main { if [ "$MARIADB_BACKUP_REMOTE" = "TRUE" ]; then mariadb_remote fi } dbb-modules/postgresql
@@ -3,13 +3,19 @@ # dependencies function check-postgresql-deps { if [ ! -e /usr/bin/psql ]; then if [ ! -e /usr/bin/pg_dump ]; then debug "It seems that you dont have psql installed. You may have problems to backup remote databases" fi numberRegex='^[0-9]+$' if ! [[ $(id -u postgres 2>&1) =~ $numberRegex ]] ; then debug "It seems that you dont have the user postgres on your computer. You may have problems to backup local postgres databases" fi if [ -r ~/.pgpass ]; then debug "function check-postgresql-deps: ~/.pgpass exists, doing reomte backup." else # If the ~/.pgpass-file is missig, deactivate remote backup of postgresql. POSTGRES_BACKUP_REMOTE=FLASE fi } # PostgreSQL local @@ -57,7 +63,7 @@ echo "" | $LOGGER echo "The backupuser does not the permission to act as user postgres" | $LOGGER echo "Please add the following line to your /etc/sudoers:" | $LOGGER echo "backupuser ALL=(postgres) NOPASSWD: /usr/bin/psql,/usr/bin/pg_dump" | $LOGGER echo "backupuser ALL=(postgres) NOPASSWD:/usr/bin/psql,/usr/bin/pg_dump,/usr/bin/pg_dumpall" | $LOGGER echo "" | $LOGGER fi } @@ -136,4 +142,3 @@ run_remote_pg_backups fi }