forked from jazzband/django-dbbackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functional.sh
executable file
·75 lines (59 loc) · 1.86 KB
/
functional.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
#!/bin/bash
make_db_test () {
$PYTHON runtests.py migrate --noinput || exit 1
$PYTHON runtests.py feed
$PYTHON runtests.py dbbackup
count1=$($PYTHON runtests.py count)
$PYTHON runtests.py flush --noinput
$PYTHON runtests.py dbrestore --noinput
count2=$($PYTHON runtests.py count)
}
test_db_results () {
if [[ "$count1" -eq "$count2" ]] ; then
echo 'DB test succeed!'
db_success=0
else
echo 'DB test Failed!'
db_success=1
fi
}
make_media_test () {
echo foo > ${MEDIA_ROOT}foo
mkdir -p ${MEDIA_ROOT}bar
echo ham > ${MEDIA_ROOT}bar/ham
$PYTHON runtests.py mediabackup
rm -rf ${MEDIA_ROOT}*
$PYTHON runtests.py mediarestore --noinput
}
test_media_results () {
media_success=0
[[ -f ${MEDIA_ROOT}foo ]] || media_success=1
[[ $(cat ${MEDIA_ROOT}foo) -eq foo ]] || media_success=1
[[ -d ${MEDIA_ROOT}bar ]] || media_success=1
[[ $(cat ${MEDIA_ROOT}bar/ham) -eq ham ]] || media_success=1
[[ -f ${MEDIA_ROOT}bar/ham ]] || media_success=1
[[ "$media_success" -eq 0 ]] && echo "Media test succeed!" || echo "Media test failed!"
}
main () {
if [[ -z "$DATABASE_URL" ]]; then
DATABASE_FILE="$(mktemp)"
export DATABASE_URL="sqlite:///$DATABASE_FILE"
fi
export PYTHON=${PYTHON:-python}
export STORAGE="${STORAGE:-django.core.files.storage.FileSystemStorage}"
export STORAGE_LOCATION="/tmp/backups/"
export STORAGE_OPTIONS="${STORAGE_OPTIONS:-location=$STORAGE_LOCATION}"
export MEDIA_ROOT="/tmp/media/"
make_db_test
test_db_results
mkdir -p $STORAGE_LOCATION
mkdir -p $MEDIA_ROOT
make_media_test
test_media_results
[[ -n "$DATABASE_FILE" ]] && rm "$DATABASE_FILE"
rm -rf "$MEDIA_ROOT"
return $((db_success + media_success))
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main || exit 1
fi