summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-14 22:06:20 +0200
committerSimon Rettberg2014-10-14 22:06:20 +0200
commit9df40ea18b63c0f7b2adbb3404a6b5d77528ee05 (patch)
tree19242cb93c143e0a984bacf22ddb9e97fc2be273 /scripts
parentAdded Dozmod and Syncdaemon launcher (diff)
downloadtmlite-bwlp-9df40ea18b63c0f7b2adbb3404a6b5d77528ee05.tar.gz
tmlite-bwlp-9df40ea18b63c0f7b2adbb3404a6b5d77528ee05.tar.xz
tmlite-bwlp-9df40ea18b63c0f7b2adbb3404a6b5d77528ee05.zip
Started work on backup script
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/system-backup57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/system-backup b/scripts/system-backup
new file mode 100755
index 0000000..666180b
--- /dev/null
+++ b/scripts/system-backup
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+if [ "$(whoami)" != "root" ]; then
+ echo "Must be running as root!"
+ exit 1
+fi
+
+DIR="/root/backup/$(date +%s)"
+
+if [ -d "$DIR" ]; then
+ echo "Backup already running!?"
+ exit 1
+fi
+
+mkdir -p "$DIR"
+cd "$DIR" || exit 1
+
+mysqldump --add-locks --defaults-extra-file=/etc/mysql/debian.cnf --default-character-set=utf8 --databases openslx bwLehrpool > db.sql
+RET=$?
+if [ $RET -ne 0 ]; then
+ echo "Database dump failed with exit code $RET"
+ exit 1
+fi
+
+FILELIST="
+ /opt/openslx/configs
+ /opt/syncdaemon/config/identity.properties
+"
+
+tar --ignore-failed-read -k -c -p -z -f files.tgz $FILELIST # no quotes here!
+RET=$?
+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
+RET=$?
+if [ ! -f backup.tgz ]; then
+ echo "Creating backup.tgz failed!"
+ exit 1
+fi
+if [ $RET -ne 0 ]; then
+ echo "WARNING: final tar exited with code $RET - backup might be incomplete!"
+fi
+
+chown www-data backup.tgz
+chmod 0600 backup.tgz
+
+FILE="/tmp/bwlp-backup-$(date +%s).tgz"
+if ! mv backup.tgz "$FILE"; then
+ echo "moving backup to $FILE failed."
+ exit 1
+fi
+
+echo "Location: $FILE"
+exit 0
+