#!/bin/sh #------------------------------------------------------------------------------ # /var/install/bin/subversion-tools-backup - backup repository # # 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 ZIPPROG=bzip2 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" } if [ "$1" = "-auto" ] then MANUAL="false" else MANUAL="true" fi if [ "${MANUAL}" = "true" ] then 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 repository mecho -info "Select repository for backup:" 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" anykey exit 0 fi # make sure backup dir exists mkdir -p "${SVN_BACKUP_TARGET}" 2>&1 >/dev/null mecho "" mecho "Going to backup 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 "backup is completed." mecho "" # perform backup eval repodir='${SVN_REPOS_'${sel_repo}'_DIR}' eval reponame='${SVN_REPOS_'${sel_repo}'_NAME}' mecho -n -info "Backup of repository: " mecho "${reponame}" # create new filename backupfile="${reponame}-$(/bin/date +%Y-%m-%d-%H%M%S).backup.bz2" backupfile="${SVN_BACKUP_TARGET}/${backupfile}" ${PROG} dump -q ${repodir} > /tmp/svn_backup$$ & # entertain the user show_wait # evaluate exit code wait $! if [ "$?" = "0" ] then mecho mecho -info "Compression of the backup file:" ${ZIPPROG} "/tmp/svn_backup$$" -c > "${backupfile}" & # entertain the user show_wait # evaluate exit code wait $! if [ "$?" = "0" ] then ${ZIPPROG} --test "${backupfile}" if [ "$?" = "0" ] then mecho "" mecho "Backup completed successfully!" mecho "The backup file is: " mecho -info " ${backupfile}" mecho "" else echo "" echo "Compression of backup file failed!" echo "" fi else echo "" echo "Compression of backup file failed!" echo "" fi else echo "" echo "Backup failed!" 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 anykey exit 0 else # initialize error counter errcount=0 maxfiles="${SVN_BACKUP_MAXFILES}" { # Mount if [ ! -z "${SVN_BACKUP_MOUNT}" ] then eval ${SVN_BACKUP_MOUNT} 2>&1 if [ "$?" != "0" ] then errcount=$((${errcount} + 1)) fi fi if [ "${errcount}" -eq "0" ] then # make sure backup dir exists mkdir -p "${SVN_BACKUP_TARGET}" 2>&1 >/dev/null # perform all backups idx=1 while [ "${idx}" -le "${SVN_REPOS_N}" ] do eval dobackup='${SVN_REPOS_'${idx}'_BACKUP}' eval repodir='${SVN_REPOS_'${idx}'_DIR}' eval reponame='${SVN_REPOS_'${idx}'_NAME}' if [ "${dobackup}" = "yes" ] then # reduce backup files to configured limit if [ "${maxfiles}" -lt "1" ] then maxfiles='1' fi backup_files=$(/bin/ls -t "${SVN_BACKUP_TARGET}/"${reponame}-*.backup.bz2 2>/dev/null) c='1' for file in ${backup_files} do if [ "$c" -ge "${maxfiles}" ] then rm "${file}" fi c=$(($c + 1)) done # create new filename backupfile="${reponame}-$(/bin/date +%Y-%m-%d-%H%M%S).backup.bz2" backupfile="${SVN_BACKUP_TARGET}/${backupfile}" # perform backup echo -n "Backup of repository \"${reponame}\": " state='failed'; ${PROG} dump ${repodir} > /tmp/svn_backup$$ 2> /tmp/svnadmin$$.log if [ "$?" = "0" ] then ${ZIPPROG} "/tmp/svn_backup$$" -c > "${backupfile}" 2> /tmp/svnadmin$$.log if [ "$?" = "0" ] then ${ZIPPROG} --test "${backupfile}" 2> /tmp/svnadmin$$.log if [ "$?" = "0" ] then state='success' fi fi fi rm -f /tmp/svn_backup$$ if [ "$state" = "success" ] then echo "ok" else echo "failed" echo echo "Error report:" cat /tmp/svnadmin$$.log echo errcount=$((${errcount} + 1)) fi rm -f /tmp/svnadmin$$.log fi # count idx=$((${idx} + 1)) done # Unount if [ ! -z "${SVN_BACKUP_UMOUNT}" ] then eval ${SVN_BACKUP_UMOUNT} 2>&1 if [ "$?" != "0" ] then errcount=$((${errcount} + 1)) fi fi fi } > /tmp/backup-$$.log if [ -f "/tmp/backup-$$.log" ] then if [ "${SVN_BACKUP_NOTIFY}" != "" ] && [ "${errcount}" -gt "0" ] then /usr/bin/mail -s "Subversion repository backup service on \"${HOSTNAME}\"" \ ${SVN_BACKUP_NOTIFY} < /tmp/backup-$$.log fi rm /tmp/backup-$$.log fi fi