blob: 780463e36b4a0ffbc9824dc2c4bdfd6ff556965f (
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
|
#!/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 --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
/etc/lighttpd/server.pem
/etc/lighttpd/chain.pem
/srv/openslx/www/boot/default/config.tgz
"
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 openslx.sql sat.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)-${RANDOM}.tgz"
if ! mv backup.tgz "$FILE"; then
echo "moving backup to $FILE failed."
exit 1
fi
echo "Location: $FILE"
exit 0
|