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
#------------------------------------------------------------------------------
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
}
shift
shift
;;
+ -M|--mysql)
+ DO_MYSQL="y"
+ shift
+ ;;
+ -P|--pgsql|--postgresql)
+ DO_POSTGRES="y"
+ shift
+ ;;
--) shift
break
;;
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}" \
exit 2
fi
+ if [[ "${SIMULATE}" != 'y' ]] ; then
+ LOGFILE="${BACKUP_HOSTDIR}/backup.log"
+ fi
}
#------------------------------------------------------------------------------
local odir=
local odir_base=
+ empty_line
info "Starting directory backup ..."
MKDIR -p "${BACKUP_DIR}"
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
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"
#------------------------------------------------------------------------------
create_checksums() {
+ empty_line
info "Creating checksum files ..."
if [[ -d "${BACKUP_DIR}" ]] ; then
#------------------------------------------------------------------------------
clean_old_backups() {
+ empty_line
info "Removing old backup sets - separation date: '${CYAN}${REMOVE_DATE}${NORMAL}'."
local i=0
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
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