blob: a95a18526599091ac81f78b4b4d90da7c5196c00 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
|