summaryrefslogtreecommitdiffstats
path: root/scripts/system-restore
diff options
context:
space:
mode:
authorSimon Rettberg2014-11-18 18:40:49 +0100
committerSimon Rettberg2014-11-18 18:40:49 +0100
commitecb072b02e1a70555db0fdf4ed47375d3080a074 (patch)
tree75db05621458eee14a96ff2d825a30072eb06e40 /scripts/system-restore
parentAdded class ProxyHandler for for configuring proxy settings system wide once ... (diff)
downloadtmlite-bwlp-ecb072b02e1a70555db0fdf4ed47375d3080a074.tar.gz
tmlite-bwlp-ecb072b02e1a70555db0fdf4ed47375d3080a074.tar.xz
tmlite-bwlp-ecb072b02e1a70555db0fdf4ed47375d3080a074.zip
Many improvements and additions:
- Added task+script for lighttpd https config - Added task for reloading proxy config - ldapsearch now supports searching for specific user - DownloadFile now supports checking file integrity through optional gpg signature
Diffstat (limited to 'scripts/system-restore')
-rwxr-xr-xscripts/system-restore62
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/system-restore b/scripts/system-restore
new file mode 100755
index 0000000..a95a185
--- /dev/null
+++ b/scripts/system-restore
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+BACKUP="$1"
+if [ -z "$BACKUP" ] || [ ! -f "$BACKUP" ]; then
+ echo "Backup file not found: $BACKUP"
+ exit 1
+fi
+
+if [ "$(whoami)" != "root" ]; then
+ echo "Must be running as root!"
+ exit 1
+fi
+
+DIR="/root/restore/$(date +%s)"
+
+if [ -d "$DIR" ]; then
+ echo "Restore already running!?"
+ exit 1
+fi
+
+mkdir -p "$DIR"
+if ! cd "$DIR"; then
+ echo "Could not cd to $DIR"
+ exit 1
+fi
+
+if ! tar --ignore-failed-read -x -f "$BACKUP"; then
+ echo "Could not extract $BACKUP - make sure it's a valid .tar.gz / .tgz"
+ exit 1
+fi
+
+if [ ! -f db.sql ]; then
+ echo "Error: database dump not found in backup - are you sure this is a valid backup?"
+ exit 1
+fi
+
+if [ ! -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 [ $RET -ne 0 ]; then
+ echo "Error: Restoring database contents failed with exit code $RET"
+ exit 1
+fi
+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
+
+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
+
+rm -rf -- "$DIR"
+rm -f -- "$BACKUP"
+
+echo "Success."
+
+exit 0
+