-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·86 lines (60 loc) · 1.48 KB
/
backup.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
die() {
echo "[-] DIE: $1"
exit 1
}
echo "ShareWhere server back up"
TMPDIR=`mktemp -d`
if [ $? != 0 ]; then
die "Failed to create the temporary directory"
fi
cleanup() {
if [ ! -z "${TMPDIR}" ]; then
rm -rf "${TMPDIR}"
fi
}
trap cleanup EXIT
BACKUP_NAME="ShareWhereBak-`date +%F-%s`"
mkdir "${TMPDIR}/${BACKUP_NAME}"
if [ $? != 0 ]; then
die "Failed to create the backup directory"
fi
if [ ! -d "images/" ]; then
read -p "[-] WARNING: failed to find an images directory. Is this okay (y/n)? " choice
case ${choice} in
Y*|y*) ;;
*) die "Not continuing due to missings images dir" ;;
esac
fi
echo "[+] Copying images (`ls images/ | wc -l` images)"
cp -r "images/" "${TMPDIR}/${BACKUP_NAME}"
if [ $? != 0 ]; then
die "Failed to copy the images"
fi
DEST_DIR="${PWD}"
#####################
# Make the tarball
#####################
cd "${TMPDIR}/${BACKUP_NAME}"
echo "[+] Dumping database. Password required"
mysqldump -u root -p ShareWhereTest > db.sql
if [ $? != 0 ]; then
die "Failed to dump the database"
fi
cd ..
TARBALL="${BACKUP_NAME}.tar.gz"
tar czf "${TARBALL}" "${BACKUP_NAME}"
if [ $? != 0 ]; then
die "Failed to create tar ball"
fi
cp "${TARBALL}" "${DEST_DIR}"
if [ $? != 0 ]; then
die "Failed to copy tar ball to ${DEST_DIR}"
fi
cd "${DEST_DIR}"
#####################
if [ ! -f "${TARBALL}" ]; then
die "The tar ball (${TARBALL}) seems to be missing from the current directory"
else
echo "[+] Your backup is ready at ${TARBALL}"
fi