forked from loomchild/volume-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume-backup.sh
executable file
·57 lines (47 loc) · 1001 Bytes
/
volume-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
#!/bin/sh
usage() {
echo "Usage: volume-backup <backup|restore> <archive>"
exit
}
backup() {
if ! [ "$ARCHIVE" == "-" ]; then
mkdir -p `dirname /backup/$ARCHIVE`
fi
tar -cjf $ARCHIVE_PATH -C /volume ./
}
restore() {
if ! [ "$ARCHIVE" == "-" ]; then
if ! [ -e $ARCHIVE_PATH ]; then
echo "Archive file $ARCHIVE does not exist"
exit 1
fi
fi
rm -rf /volume/* /volume/..?* /volume/.[!.]*
tar -C /volume/ -xjf $ARCHIVE_PATH
}
# Needed because sometimes pty is not ready when executing docker-compose run
# See https://github.com/docker/compose/pull/4738 for more details
# TODO: remove after above pull request or equivalent is merged
sleep 1
if [ $# -ne 2 ]; then
usage
fi
OPERATION=$1
if [ "$2" == "-" ]; then
ARCHIVE=$2
ARCHIVE_PATH=$ARCHIVE
else
ARCHIVE=${2%%.tar.bz2}.tar.bz2
ARCHIVE_PATH=/backup/$ARCHIVE
fi
case "$OPERATION" in
"backup" )
backup
;;
"restore" )
restore
;;
* )
usage
;;
esac