Skip to content
Snippets Groups Projects
Commit ccd2f6fc authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add selector fore restore

parent f3c8405d
Branches
No related tags found
1 merge request!129Db Profiles
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
LOCALDUMP_LOADED=1 LOCALDUMP_LOADED=1
ARCHIVE_BASEDIR=
BACKUP_BASEDIR= BACKUP_BASEDIR=
BACKUP_PLUGINDIR= BACKUP_PLUGINDIR=
...@@ -183,7 +184,10 @@ ...@@ -183,7 +184,10 @@
# restore: show profiles from that exist backups # restore: show profiles from that exist backups
# global string BACKUP_BASEDIR base directory of all backups # global string BACKUP_BASEDIR base directory of all backups
function listBackupedServices(){ function listBackupedServices(){
find "${BACKUP_BASEDIR}" -mindepth 1 -maxdepth 1 -type d | sed "s#^${BACKUP_BASEDIR}/##g" | sort | grep "^[a-z]" (
find "${BACKUP_BASEDIR}" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;
test -n "${ARCHIVE_BASEDIR}" && find "${ARCHIVE_BASEDIR}" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;
) | sort -u
} }
# ------------------------------------------------------------ # ------------------------------------------------------------
...@@ -341,7 +345,7 @@ ...@@ -341,7 +345,7 @@
fi fi
# ----- db init # ----- init vars
BACKUP_BASEDIR=$(_j_getvar "${JOBFILE}" "dir-localdumps") BACKUP_BASEDIR=$(_j_getvar "${JOBFILE}" "dir-localdumps")
# check # check
...@@ -350,6 +354,8 @@ ...@@ -350,6 +354,8 @@
echo There must be an entry dir-localdumps in ${JOBFILE} echo There must be an entry dir-localdumps in ${JOBFILE}
exit 1 exit 1
fi fi
ARCHIVE_BASEDIR=$(_j_getvar "${JOBFILE}" dir-dbarchive)
BACKUP_PLUGINDIR=$(dirname $0)/plugins/localdump BACKUP_PLUGINDIR=$(dirname $0)/plugins/localdump
DBD_BASEDIR=$BACKUP_PLUGINDIR/profiles DBD_BASEDIR=$BACKUP_PLUGINDIR/profiles
...@@ -411,7 +417,7 @@ ...@@ -411,7 +417,7 @@
BACKUP_PARAMS=$( dbdetect.getParams ) BACKUP_PARAMS=$( dbdetect.getParams )
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${PROFILENAME} BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${PROFILENAME}
ARCHIVE_DIR=$(_j_getvar "${JOBFILE}" dir-dbarchive)/${PROFILENAME} ARCHIVE_DIR=${ARCHIVE_BASEDIR}/${PROFILENAME}
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} ) BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
...@@ -456,10 +462,10 @@ ...@@ -456,10 +462,10 @@
h1 "RESTORE DATABASE" h1 "RESTORE DATABASE"
if ! listBackupedServices; then if ! listBackupedServices | grep -q . ; then
color.echo error "ERROR: No database dump was found in [${BACKUP_BASEDIR}]." color.echo error "ERROR: No database dump was found in [${BACKUP_BASEDIR}] nor [${ARCHIVE_BASEDIR}]."
exit 1 exit 1
fi fi
if [ -z $1 ] || [ ! -f "$1" ]; then if [ -z $1 ] || [ ! -f "$1" ]; then
...@@ -468,6 +474,14 @@ ...@@ -468,6 +474,14 @@
# ----- interactive selections # ----- interactive selections
h2 "Select profile that has a dump" h2 "Select profile that has a dump"
if [ -z "${parService}" ]; then
if [ "$( listBackupedServices | wc -l )" -eq 1 ]; then
parService="$( listBackupedServices )"
echo "Selecting the only existing profile: $parService"
fi
fi
if [ -z "${parService}" ]; then if [ -z "${parService}" ]; then
listBackupedServices listBackupedServices
color.print input "Restore for profile name >" color.print input "Restore for profile name >"
...@@ -482,15 +496,30 @@ ...@@ -482,15 +496,30 @@
color.echo error "ERROR: profile [${parService}] is not known here (or database service is stopped)." color.echo error "ERROR: profile [${parService}] is not known here (or database service is stopped)."
echo echo
echo "Existing database profiles:" echo "Existing database profiles:"
get_database_profiles get_database_profiles | nl
echo
exit 1 exit 1
fi fi
# ----- check if dump exists in archive and in backup
if [ -d "${BACKUP_BASEDIR}/${parService}" ] && [ -d "${ARCHIVE_BASEDIR}/${parService}" ]; then
echo
echo "Backup ${BACKUP_BASEDIR}"
echo "Archive ${ARCHIVE_BASEDIR}"
color.print input "Select a source directory >"
read -r backupsource
test -z "$backupsource" && exit 1
BACKUP_BASEDIR="${backupsource}"
else
# just one test needed because BACKUP_BASEDIR is BACKUP_BASEDIR
test -d "${ARCHIVE_BASEDIR}/${parService}" && BACKUP_BASEDIR="${ARCHIVE_BASEDIR}/${parService}"
fi
if [ ! -d "${BACKUP_BASEDIR}/${parService}" ]; then if [ ! -d "${BACKUP_BASEDIR}/${parService}" ]; then
color.echo error "ERROR: profile ${parService} has no backup yet." color.echo error "ERROR: profile ${parService} has no backup yet."
exit 1 exit 1
fi fi
BACKUP_TARGETDIR="${BACKUP_BASEDIR}/${parService}" BACKUP_TARGETDIR="${BACKUP_BASEDIR}/${parService}"
h2 "Select database" h2 "Select database"
...@@ -541,6 +570,7 @@ ...@@ -541,6 +570,7 @@
BACKUP_PARAMS=$( dbdetect.getParams ) BACKUP_PARAMS=$( dbdetect.getParams )
eval $( dbdetect.setenv ) eval $( dbdetect.setenv )
h2 $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}"
. $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}" . $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}"
if [ $? -ne 0 -o $rc -ne 0 ]; then if [ $? -ne 0 -o $rc -ne 0 ]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment