From: Frank Brehm Date: Tue, 20 Apr 2021 12:36:48 +0000 (+0200) Subject: Making MySQL backup optional. X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=ec50bdc2fba4fa44759cbca2d3f8fbd930b575e3;p=pixelpark%2Fadmin-tools.git Making MySQL backup optional. --- diff --git a/bin/manual-backup b/bin/manual-backup index 225c88c..9952d8a 100755 --- a/bin/manual-backup +++ b/bin/manual-backup @@ -26,9 +26,12 @@ STARTTIME=$(date) CDATE=$(date +"%Y-%m-%d") REMOVE_DATE=$(date -d "${BACKUP_COPIES} days ago" +"%Y-%m-%d") -LOGFILE="${BACKUP_HOSTDIR}/backup.log" +LOGFILE= BACKUP_DIR="${BACKUP_HOSTDIR}/${CDATE}" +DO_MYSQL="n" +DO_POSTGRES="n" + declare -a REMOTE_HOSTS=() DESCRIPTION=$( cat <<-EOF @@ -42,12 +45,22 @@ detect_color #------------------------------------------------------------------------------ usage() { cat <<-EOF - Usage: ${BASE_NAME} [-C COPIES] [-R REMOTE_HOST [-R REMOTE_HOST ...]] [Common Options] + Usage: ${BASE_NAME} [-C COPIES] [-R REMOTE_HOST [-R REMOTE_HOST ...]] [--mysql] [--pgsql] [Common Options] ${BASE_NAME} [-h|--help] ${BASE_NAME} [-V|--version] Common Options: ${STD_USAGE_MSG} + + Backup Options: + -C|--copies COPIES + Number of old Backup sets to keep. Defaults to ${BACKUP_COPIES}. + -R|--remote REMOTE_HOST + Hostname of a remote host, where to synchronize all backup sets + in '${BACKUP_HOSTDIR}' via rsync. May be used multiple times. + -M|--mysql Perform a backup of the local MySQL/MariaDB database. + -P|--pgsql|--postgresql + Perform a backup of the local PostrgreSQL database instance. EOF } @@ -88,6 +101,14 @@ eval_my_options() { shift shift ;; + -M|--mysql) + DO_MYSQL="y" + shift + ;; + -P|--pgsql|--postgresql) + DO_POSTGRES="y" + shift + ;; --) shift break ;; @@ -122,8 +143,8 @@ get_options() { local tmp= local base_dir= - local this_short_options='C:R:' - local this_long_options='--copies:,--remote:' + local this_short_options='C:R:MP' + local this_long_options='copies:,remote:,mysql,pgsql,postgresql' set +e tmp=$( getopt -o "${STD_SHORT_OPTIONS}${this_short_options}" \ @@ -160,6 +181,9 @@ get_options() { exit 2 fi + if [[ "${SIMULATE}" != 'y' ]] ; then + LOGFILE="${BACKUP_HOSTDIR}/backup.log" + fi } #------------------------------------------------------------------------------ @@ -216,6 +240,7 @@ do_dir_backup() { local odir= local odir_base= + empty_line info "Starting directory backup ..." MKDIR -p "${BACKUP_DIR}" @@ -226,6 +251,9 @@ do_dir_backup() { dir_backup "var/lib" "var-lib" dir_backup "var/log" "var-log" dir_backup "var/spool/cron" "var-spool-cron" + if [[ -d "var/spool/postfix" ]] ; then + dir_backup "var/spool/postfix" "var-spool-postfix" + fi if [[ -d "var/vmail" ]] ; then dir_backup "var/vmail" "var-vmail" fi @@ -269,6 +297,7 @@ do_mysql_backup(){ local dumpfile="${BACKUP_DIR}/mysql.dump.all-dbs.dump.sql.gz" local errorlog="${BACKUP_DIR}/mysql.dump.error.log" + empty_line info "Dumping MySQL Datenbank -> '${CYAN}${dumpfile}${NORMAL}' ..." local cmd="mysqldump --all_databases --routines --triggers --add-drop-database" @@ -303,6 +332,7 @@ do_mysql_backup(){ #------------------------------------------------------------------------------ create_checksums() { + empty_line info "Creating checksum files ..." if [[ -d "${BACKUP_DIR}" ]] ; then @@ -330,6 +360,7 @@ create_checksums() { #------------------------------------------------------------------------------ clean_old_backups() { + empty_line info "Removing old backup sets - separation date: '${CYAN}${REMOVE_DATE}${NORMAL}'." local i=0 @@ -381,6 +412,7 @@ sync_to_remote() { for rhost in "${REMOTE_HOSTS[@]}" ; do + empty_line info "Syncing backup to '${GREEN}${rhost}${NORMAL}:${CYAN}${BACKUP_HOSTDIR}${NORMAL}' ..." cmd="rsync --archive --hard-links --delete --stats" if [[ "${VERBOSE}" == "y" ]] ; then @@ -416,7 +448,9 @@ main() { check_preferences do_dir_backup - do_mysql_backup + if [[ "${DO_MYSQL}" == "y" ]] ; then + do_mysql_backup + fi create_checksums clean_old_backups sync_to_remote