Skip to content
Snippets Groups Projects

shorten output if no service is available

Merged Hahn Axel (hahn) requested to merge limit-backup-count into master
1 file
+ 133
119
Compare changes
  • Side-by-side
  • Inline
+ 133
119
@@ -68,8 +68,9 @@
@@ -68,8 +68,9 @@
# ------------------------------------------------------------
# ------------------------------------------------------------
# cleanup a backup dir: remove old files and delete empty dirs
# cleanup a backup dir: remove old files and delete empty dirs
function cleanup_backup_target(){
function cleanup_backup_target(){
h3 "CLEANUP ${BACKUP_TARGETDIR} older $BACKUP_KEEP_DAYS days ..."
if [ -d "${BACKUP_TARGETDIR}" ]; then
if [ -d "${BACKUP_TARGETDIR}" ]; then
 
h3 "CLEANUP ${BACKUP_TARGETDIR} older $BACKUP_KEEP_DAYS days ..."
 
echo find "${BACKUP_TARGETDIR}" -mtime +$BACKUP_KEEP_DAYS -delete -print
echo find "${BACKUP_TARGETDIR}" -mtime +$BACKUP_KEEP_DAYS -delete -print
color cmd
color cmd
find "${BACKUP_TARGETDIR}" -mtime +$BACKUP_KEEP_DAYS -delete -print
find "${BACKUP_TARGETDIR}" -mtime +$BACKUP_KEEP_DAYS -delete -print
@@ -79,8 +80,6 @@
@@ -79,8 +80,6 @@
echo "INFO: the directory is empty - deleting it"
echo "INFO: the directory is empty - deleting it"
rm -rf "${BACKUP_TARGETDIR}"
rm -rf "${BACKUP_TARGETDIR}"
fi
fi
else
echo "SKIP: directory does not exist (no error)"
fi
fi
}
}
@@ -137,9 +136,9 @@
@@ -137,9 +136,9 @@
# show used space and count of files and dirs
# show used space and count of files and dirs
function show_info_backup_target(){
function show_info_backup_target(){
h3 "INFO about backup target ${BACKUP_TARGETDIR}"
if [ -d "${BACKUP_TARGETDIR}" ]; then
if [ -d "${BACKUP_TARGETDIR}" ]; then
 
h3 "INFO about backup target ${BACKUP_TARGETDIR}"
 
echo -n "used space: "
echo -n "used space: "
du -hs "${BACKUP_TARGETDIR}"
du -hs "${BACKUP_TARGETDIR}"
@@ -151,11 +150,8 @@
@@ -151,11 +150,8 @@
echo -n "free space: "
echo -n "free space: "
df -h "${BACKUP_TARGETDIR}" | tail -1 | awk '{ print $4 }'
df -h "${BACKUP_TARGETDIR}" | tail -1 | awk '{ print $4 }'
else
echo
echo "SKIP: directory does not exist (no error)"
fi
fi
echo
}
}
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
@@ -225,11 +221,15 @@
@@ -225,11 +221,15 @@
echo "`basename $0` [[operation]] [Name_of_service] [[more services]]"
echo "`basename $0` [[operation]] [Name_of_service] [[more services]]"
echo "`basename $0` restore [Name_of_service] [file-to-restore]"
echo "`basename $0` restore [Name_of_service] [file-to-restore]"
echo
echo
echo " operation - one of backup|restore; optional parameter; default is backup"
echo " operation - one of check|backup|restore; optional parameter; default is backup"
 
echo " check show info only if the service is available"
 
echo " backup dump all databases/ schemes of a given service"
 
echo " restore import a dump into same or new database"
 
echo " Without a filename it starts an interactive mode"
echo " Name_of_service - name of database service"
echo " Name_of_service - name of database service"
echo " You get a list of all available services without parameter"
echo " You get a list of all available services without parameter"
echo " Use ALL for bulk command"
echo " Use ALL for bulk command"
echo " file - filename of db dump to restore"
echo " file - filename of db dump to restore to origin database scheme"
}
}
@@ -237,12 +237,12 @@
@@ -237,12 +237,12 @@
# INIT
# INIT
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
 
# ----- checks
 
# . /usr/local/bin/inc_cronfunctions.sh
# . /usr/local/bin/inc_cronfunctions.sh
j_requireUser "root"
j_requireUser "root"
h1 `date` IML BACKUP :: LOCALDUMP :: $*
h1 `date` IML BACKUP :: LOCALDUMP :: $*
echo Start `date`
echo
if [ $# -eq 0 ]; then
if [ $# -eq 0 ]; then
color error
color error
@@ -257,126 +257,140 @@
@@ -257,126 +257,140 @@
fi
fi
mode="backup"
mode="backup"
if [ "$1" = "backup" -o "$1" = "restore" ]; then
case "$1" in
mode=$1
backup|check|restore|shell)
shift 1
mode=$1
fi
shift 1
;;
esac
if [ "$mode" = "backup" ]; then
export SERVICENAME=$1
if [ "$1" = "ALL" ]; then
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${SERVICENAME}
services=`get_services`
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
echo AUTO: calling local backup scripts for all known services
echo $services
case "$mode" in
echo
# ------------------------------------------------------------
else
check)
services=$*
. $BACKUP_SCRIPT $mode
fi
;;
# ------------------------------------------------------------
# ----- check all params
backup)
for SERVICENAME in $services
if [ "$SERVICENAME" = "ALL" ]; then
do
services=$(get_services)
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
echo AUTO: calling local backup scripts for all known services
if [ ! -f $BACKUP_SCRIPT ]; then
echo $services
color error
echo ERROR: parameter $SERVICENAME seems to be wrong.
echo The backup script does not exist: $BACKUP_SCRIPT
color reset
echo
echo
echo services in this folder are:
else
get_services
services=$*
exit 2
fi
fi
done
# ----- GO
for SERVICENAME in $services
do
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${SERVICENAME}
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
# show_info_backup_target
# ----- start service specific script
echo
h2 "START SCRIPT FOR ${SERVICENAME} - $BACKUP_SCRIPT"
. $BACKUP_SCRIPT $mode
# ----- post jobs: cleanup
cleanup_backup_target
show_info_backup_target
done
# ----- check all params
fi
for SERVICENAME in $services
do
if [ "$mode" = "restore" ]; then
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
SERVICENAME=$1
if [ ! -f $BACKUP_SCRIPT ]; then
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${SERVICENAME}
color error
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
echo ERROR: parameter $SERVICENAME seems to be wrong.
echo The backup script does not exist: $BACKUP_SCRIPT
h1 "RESTORE DATABASE"
color reset
if [ -z $2 ]; then
echo
echo services in this folder are:
# ----- file selection
get_services
exit 2
h2 "select database"
fi
listBackupedDBs
done
color input
echo -n "name of db to restore >"
# ----- GO
color reset
for SERVICENAME in $services
read fileprefix
do
echo
 
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${SERVICENAME}
 
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
 
 
# ----- start service specific script
 
h2 "START SCRIPT FOR ${SERVICENAME} - $BACKUP_SCRIPT"
 
 
. $BACKUP_SCRIPT $mode
 
 
# ----- post jobs: cleanup
 
cleanup_backup_target
 
show_info_backup_target
 
 
done
 
;;
 
 
# ------------------------------------------------------------
 
restore)
 
 
h1 "RESTORE DATABASE"
 
if [ -z $2 ]; then
 
 
# ----- file selection
 
 
h2 "select database"
 
listBackupedDBs
 
color input
 
echo -n "name of db to restore >"
 
color reset
 
read fileprefix
 
echo
h2 "select a specific dump for that database"
h2 "select a specific dump for that database"
listBackupedDBs $fileprefix
listBackupedDBs $fileprefix
color input
color input
echo -n "backupset to import >"
echo -n "backupset to import >"
color reset
color reset
read dbfile
read dbfile
echo
echo
color input
color input
sTargetDb=`guessDB ${dbfile}`
echo -n "new database name [$sTargetDb] >"
color reset
read sTargetDb
if [ -z $sTargetDb ]; then
sTargetDb=`guessDB ${dbfile}`
sTargetDb=`guessDB ${dbfile}`
 
echo -n "new database name [$sTargetDb] >"
 
color reset
 
read sTargetDb
 
if [ -z $sTargetDb ]; then
 
sTargetDb=`guessDB ${dbfile}`
 
fi
 
echo
 
 
sDumpfile="${BACKUP_TARGETDIR}/${dbfile}"
 
else
 
sDumpfile=$2
 
sTargetDb=$3
fi
fi
echo
shift 2
sDumpfile="${BACKUP_TARGETDIR}/${dbfile}"
# ----- start restore
else
sDumpfile=$2
sTargetDb=$3
fi
shift 2
if [ ! -f "${sDumpfile}" ]; then
color error
echo ERROR: ${sDumpfile} is not a file
color reset
rc=$rc+1
else
. $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}"
if [ ! -f "${sDumpfile}" ]; then
if [ $? -ne 0 -o $rc -ne 0 ]; then
color error
color error
echo ERROR: $mode failed. See ouput above. :-/
echo ERROR: ${sDumpfile} is not a file
color reset
color reset
 
rc=$rc+1
else
else
color ok
echo OK, $mode was successful.
color reset
fi
fi
. $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}"
fi
if [ $? -ne 0 -o $rc -ne 0 ]; then
 
color error
 
echo ERROR: $mode failed. See ouput above. :-/
 
color reset
 
else
 
color ok
 
echo OK, $mode was successful.
 
color reset
 
fi
 
fi
 
;;
 
# ------------------------------------------------------------
 
# shell)
 
# . $BACKUP_SCRIPT $mode
 
# myshell=$( grep "^$USER" /etc/passwd | cut -f 7 -d ":" )
 
# echo "TYPE EXIT ... to leave $myshell"
 
# $myshell -i
 
# echo "Subshell was closed."
 
# ;;
 
esac
echo _______________________________________________________________________________
echo _______________________________________________________________________________
Loading