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 @@
LOCALDUMP_LOADED=1
ARCHIVE_BASEDIR=
BACKUP_BASEDIR=
BACKUP_PLUGINDIR=
......@@ -183,7 +184,10 @@
# restore: show profiles from that exist backups
# global string BACKUP_BASEDIR base directory of all backups
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 @@
fi
# ----- db init
# ----- init vars
BACKUP_BASEDIR=$(_j_getvar "${JOBFILE}" "dir-localdumps")
# check
......@@ -350,6 +354,8 @@
echo There must be an entry dir-localdumps in ${JOBFILE}
exit 1
fi
ARCHIVE_BASEDIR=$(_j_getvar "${JOBFILE}" dir-dbarchive)
BACKUP_PLUGINDIR=$(dirname $0)/plugins/localdump
DBD_BASEDIR=$BACKUP_PLUGINDIR/profiles
......@@ -411,7 +417,7 @@
BACKUP_PARAMS=$( dbdetect.getParams )
BACKUP_TARGETDIR=${BACKUP_BASEDIR}/${PROFILENAME}
ARCHIVE_DIR=$(_j_getvar "${JOBFILE}" dir-dbarchive)/${PROFILENAME}
ARCHIVE_DIR=${ARCHIVE_BASEDIR}/${PROFILENAME}
BACKUP_SCRIPT=$( get_service_script ${SERVICENAME} )
......@@ -456,10 +462,10 @@
h1 "RESTORE DATABASE"
if ! listBackupedServices; then
color.echo error "ERROR: No database dump was found in [${BACKUP_BASEDIR}]."
exit 1
fi
if ! listBackupedServices | grep -q . ; then
color.echo error "ERROR: No database dump was found in [${BACKUP_BASEDIR}] nor [${ARCHIVE_BASEDIR}]."
exit 1
fi
if [ -z $1 ] || [ ! -f "$1" ]; then
......@@ -468,6 +474,14 @@
# ----- interactive selections
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
listBackupedServices
color.print input "Restore for profile name >"
......@@ -482,15 +496,30 @@
color.echo error "ERROR: profile [${parService}] is not known here (or database service is stopped)."
echo
echo "Existing database profiles:"
get_database_profiles
get_database_profiles | nl
echo
exit 1
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
color.echo error "ERROR: profile ${parService} has no backup yet."
exit 1
fi
BACKUP_TARGETDIR="${BACKUP_BASEDIR}/${parService}"
h2 "Select database"
......@@ -541,6 +570,7 @@
BACKUP_PARAMS=$( dbdetect.getParams )
eval $( dbdetect.setenv )
h2 $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}"
. $BACKUP_SCRIPT $mode "${sDumpfile}" "${sTargetDb}"
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