#!/bin/sh #------------------------------------------------------------------------------ # /var/install/bin/subversion-tools-restore - restore repository from backup # # Creation : 2018-07-11 daniel # Last Update: 2023-07-23 09:11:10 # # Copyright (c) 2024 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #------------------------------------------------------------------------------ #include eislib . /var/install/include/eislib . /etc/config.d/subversion PATH='/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin' PROG=svnadmin UNZIPPROG=bunzip2 show_wait() { mecho -n "wait [ " colpos=1 while [ -n "$(ps --no-headers $!)" ] do mecho -info -n "." sleep 1 colpos=$((${colpos} + 1)) if [ "${colpos}" -ge 55 ] then mecho " ]" mecho -n "wait [ " colpos=1 fi done mecho " ] done" } clrhome # Mount backup media if [ ! -z "${SVN_BACKUP_MOUNT}" ] then eval ${SVN_BACKUP_MOUNT} 2>&1 if [ "$?" != "0" ] then echo "unable to execute: ${SVN_BACKUP_MOUNT}" anykey exit 1 fi fi # select backup file mecho -info "Select backup file:" backup_files=$(/bin/ls -t "$SVN_BACKUP_TARGET/"*.backup.bz2 2>/dev/null) c="1" for file in ${backup_files} do mecho -info -n "${c} " mecho "${file}" c=$((${c} + 1)) done result=1 if [ "${c}" -le "1" ] then mecho "No backup files found!" result=0 else c=$((${c} + 1)) idx="1" mecho idx=$(/var/install/bin/ask "Select (0 = cancel)" "${idx}" "0-${c}") if [ "${idx}" = "0" ] then mecho -info "command canceled" result=0 else c="1" backupfile="" for file in ${backup_files} do if [ "${c}" -eq "${idx}" ] then backupfile="${file}" fi c=$((${c} + 1)) done echo "File selected: ${backupfile}" # select repository mecho "" mecho -info "Select repository to restore to:" techo begin 4 12 52 techo row -info No -info Name -info Path idx="1" while [ "${idx}" -le "${SVN_REPOS_N}" ] do eval repodir='${SVN_REPOS_'${idx}'_DIR}' eval reponame='${SVN_REPOS_'${idx}'_NAME}' techo row "${idx}" "${reponame}" "${repodir}" idx=$((${idx} + 1)) done techo end mecho "" sel_repo=$(/var/install/bin/ask "Select (0 = cancel)" "${sel_repo}" "0-${SVN_REPOS_N}") if [ "${sel_repo}" = "0" ] then mecho -info "command canceled" result=0 else mecho "" mecho "Going to restore the repository right now. Especially on big" mecho "repositories this could take a while. Please be patient and " mecho "don't interrupt the process! You will be notified when the " mecho "restore is done." mecho "" # extract backup file mecho -info "Extracting file '${backupfile}': " ${UNZIPPROG} "${backupfile}" -c > "/tmp/svn_backup$$" & # entertain the user show_wait # evaluate exit code wait $! if [ "$?" = "0" ] then mecho "" mecho -info "Restoring to repository ${sel_repo}: " # reload repository eval repodir='${SVN_REPOS_'${sel_repo}'_DIR}' svnadmin load -q "${repodir}" < "/tmp/svn_backup$$" & # entertain the user show_wait # evaluate exit code wait $! if [ "$?" = "0" ] then echo "" echo "Repository restored successfully!" echo "" result=0 else echo "" echo "Some errors occured!" echo "" fi # set file permissions chmod a+rw ${repodir}/db/log.* 2> /dev/null else echo "" echo "Error extracting archive!" echo "" fi rm -f "/tmp/svn_backup$$" # Unount if [ ! -z "${SVN_BACKUP_UMOUNT}" ] then eval ${SVN_BACKUP_UMOUNT} 2>&1 if [ "$?" != "0" ] then echo "unable to execute: ${SVN_BACKUP_UMOUNT}" fi fi fi fi fi anykey exit ${result}