diff options
author | Simon Rettberg | 2015-09-05 20:48:22 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-09-05 20:48:22 +0200 |
commit | 8edc84bb2fd77c40b4e47fc64d1c6045b6b4aa5f (patch) | |
tree | 0763b3f42876f207cea5aeb741cb063578f7d5f7 /scripts | |
parent | [tmlite-bwlp] mount-store script: corr. var $RANDOM (diff) | |
download | tmlite-bwlp-8edc84bb2fd77c40b4e47fc64d1c6045b6b4aa5f.tar.gz tmlite-bwlp-8edc84bb2fd77c40b4e47fc64d1c6045b6b4aa5f.tar.xz tmlite-bwlp-8edc84bb2fd77c40b4e47fc64d1c6045b6b4aa5f.zip |
Refine mount script, updater backup/restore to handle new dozmod db
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mount-store | 34 | ||||
-rwxr-xr-x | scripts/system-backup | 13 | ||||
-rwxr-xr-x | scripts/system-restore | 86 |
3 files changed, 102 insertions, 31 deletions
diff --git a/scripts/mount-store b/scripts/mount-store index 51080fa..cd777a8 100755 --- a/scripts/mount-store +++ b/scripts/mount-store @@ -23,6 +23,9 @@ images) ;; esac +FLAG="${DEST}/.notmounted" +SUBDIR="${DEST}/bwlehrpool_store" + # Sanity checks: Destination exists? if [ ! -d "$DEST" ]; then mkdir -p "$DEST" @@ -44,24 +47,26 @@ if awk '{print $2}' "/proc/mounts" | grep -q "^${DEST}\$"; then RET=$? if [ "$RET" -ne "0" ]; then echo "Cannot unmount '$DEST'!" >&2 + echo "Storage might be in use (running VM upload etc.)" >&2 + echo "Try stopping DMSD first" >&2 exit "$RET" fi fi # Unmount and not requested to mount (local mode) if [[ "${SOURCE}" == "null" ]]; then - rm -f "${DEST}/.notmounted" + rm -f "${FLAG}" exit 0 fi -touch "${DEST}/.notmounted" +touch "${FLAG}" # Mount! if grep -E -q '^[^/].+:.+' <<<$SOURCE; then # seems to be NFS - for i in 1 2 3; do - mount -v -t nfs -o rw,async,nolock,vers=3,fg,ac,retry=1,timeo=100,sec=sys "$SOURCE" "$DEST" + for opt in vers=4 vers=3; do + mount -v -t nfs -o rw,noatime,noexec,nodev,async,nolock,$opt,fg,ac,retry=1,timeo=150,sec=sys "$SOURCE" "$DEST" RET=$? [ "$RET" -eq "0" ] && break done @@ -84,10 +89,25 @@ else exit 1 fi +echo "----------------------------------" + if [ "$RET" == "0" ]; then - chgrp -R images "$DEST" 2>/dev/null - chmod -R ug+rwX "$DEST" 2>/dev/null - TEST="$DEST/.test-$RANDOM-$RANDOM" + rm -f "${FLAG}" + if [ -e "${FLAG}" ]; then + echo "Error: File '.notmounted' exists on remote storage. Delete first!" >&2 + umount -v "$DEST" + exit 5 + fi + chgrp images "${DEST}" 2>/dev/null + mkdir -p "${SUBDIR}" + if [ ! -d "${SUBDIR}" ]; then + echo "Error: Could not create $(basename "$SUBDIR")! Storage not writable!" >&2 + umount -v "$DEST" + exit 6 + fi + chgrp -R images "${SUBDIR}" 2>/dev/null & + chmod -R ug+rwX "${SUBDIR}" 2>/dev/null & + TEST="${SUBDIR}/.deleteme-$RANDOM-$RANDOM" sudo -n -u dmsd touch "$TEST" RET=$? if [ -e "$TEST" ]; then diff --git a/scripts/system-backup b/scripts/system-backup index d4b9ebe..780463e 100755 --- a/scripts/system-backup +++ b/scripts/system-backup @@ -15,16 +15,17 @@ fi mkdir -p "$DIR" cd "$DIR" || exit 1 -mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --add-locks --add-drop-database --default-character-set=utf8 --databases openslx bwLehrpool > db.sql -RET=$? -if [ $RET -ne 0 ]; then - echo "Database dump failed with exit code $RET" +mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --add-locks --add-drop-database --default-character-set=utf8 --databases openslx > openslx.sql +RET1=$? +mysqldump --defaults-extra-file=/etc/mysql/debian.cnf --add-locks --add-drop-database --default-character-set=utf8 --databases sat > sat.sql +RET2=$? +if [ $RET1 -ne 0 ] || [ $RET2 -ne 0 ]; then + echo "Database dump failed with exit code $RET1/$RET2" exit 1 fi FILELIST=" /opt/openslx/configs - /opt/syncdaemon/config/identity.properties /etc/lighttpd/server.pem /etc/lighttpd/chain.pem /srv/openslx/www/boot/default/config.tgz @@ -36,7 +37,7 @@ if [ $RET -ne 0 ]; then echo "WARNING: filesystem-tar exited with code $RET - backup might be incomplete!" fi -tar -k -c -z -f backup.tgz files.tgz db.sql +tar -k -c -z -f backup.tgz files.tgz openslx.sql sat.sql RET=$? if [ ! -f backup.tgz ]; then echo "Creating backup.tgz failed!" diff --git a/scripts/system-restore b/scripts/system-restore index dfc5c3a..8a66558 100755 --- a/scripts/system-restore +++ b/scripts/system-restore @@ -1,5 +1,24 @@ #!/bin/bash +RES_OPENSLX=0 +RES_SAT=0 +case "$1" in + both) + RES_OPENSLX=1 + RES_SAT=1 + ;; + openslx) + RES_OPENSLX=1 + ;; + sat) + RES_SAT=1 + ;; + *) + echo "Error: Restore mode must be one of both, openslx, sat" + exit 1 + ;; +esac + BACKUP="$1" if [ -z "$BACKUP" ] || [ ! -f "$BACKUP" ]; then echo "Backup file not found: $BACKUP" @@ -29,37 +48,68 @@ if ! tar --ignore-failed-read -x -f "$BACKUP"; then exit 1 fi -if [ ! -f db.sql ]; then +if [ -f db.sql ]; then + DB_OLD=1 +elif [ -f openslx.sql ] || [ -f sat.sql ]; then + DB_OLD=0 +else echo "Error: database dump not found in backup - are you sure this is a valid backup?" exit 1 fi -if [ ! -f files.tgz ]; then +if [ $RES_SAT -eq 1 -a $DB_OLD -eq 0 -a ! -f sat.sql ]; then + echo "Error: this backup does not contain the DozMod database" + echo "Error: cannot restore VM/lecture information" + exit 1 +fi +if [ $RES_OPENSLX -eq 1 -a $DB_OLD -eq 0 -a ! -f openslx.sql ]; then + echo "Error: this backup does not contain the OpenSLX database" + echo "Error: cannot restore satellite configuration" + exit 1 +fi + +if [ $RES_OPENSLX -eq 1 -a ! -f files.tgz ]; then echo "Error: files.tgz not found in backup - are your sure this is a valid backup?" exit 1 fi -mysql --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 < db.sql -RET=$? +if [ $DB_OLD -eq 1 ]; then + mysql --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 < db.sql + RET=$? +else + RET=0 + if [ $RES_SAT -eq 1 ]; then + mysql --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 < sat.sql + RET=$? + fi + if [ $RET -eq 0 -a $RES_OPENSLX -eq 1 ]; then + mysql --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 < openslx.sql + RET=$? + fi +fi + if [ $RET -ne 0 ]; then echo "Error: Restoring database contents failed with exit code $RET" exit 1 fi -# Since we came that far we'll delete some old configs (if existent) -rm -rf /opt/ldadp/{configs,pid,logs}/* /opt/openslx/configs/* /srv/openslx/www/boot/default/config.tgz 2> /dev/null -# Force triggering IP detection/setting, which should in turn regenerate ldadp configs and launch ldadp instances if applicable -echo "UPDATE openslx.property SET value = 'invalid' WHERE name = 'server-ip' LIMIT 1" | mysql --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 -# Try to update the db (if required) -curl -s 'http://localhost/slx-admin/api.php?do=update' - -tar --ignore-failed-read -x -f files.tgz -C / -RET=$? -if [ $RET -ne 0 ]; then - echo "WARNING: Restoring filesystem contents failed with exit code $RET - backup might be incomplete!" + +if [ $RES_OPENSLX -eq 1 ]; then + # Since we came that far we'll delete some old configs (if existent) + rm -rf /opt/ldadp/{configs,pid,logs}/* /opt/openslx/configs/* /srv/openslx/www/boot/default/config.tgz 2> /dev/null + # Force triggering IP detection/setting, which should in turn regenerate ldadp configs and launch ldadp instances if applicable + echo "UPDATE openslx.property SET value = 'invalid' WHERE name = 'server-ip' LIMIT 1" | mysql --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 + # Try to update the db (if required) + curl -s 'http://localhost/slx-admin/api.php?do=update' + + tar --ignore-failed-read -x -f files.tgz -C / + RET=$? + if [ $RET -ne 0 ]; then + echo "WARNING: Restoring filesystem contents failed with exit code $RET - backup might be incomplete!" + fi + # Make sure the directory tree is owned by taskmanager, as tar will create intermediate + # directories as owned by root if they do not exist. + chown -R taskmanager /srv/openslx/www/boot /opt/openslx/configs fi -# Make sure the directory tree is owned by taskmanager, as tar will create intermediate -# directories as owned by root if they do not exist. -chown -R taskmanager /srv/openslx/www/boot /opt/openslx/configs rm -rf -- "$DIR" rm -f -- "$BACKUP" |