-
Notifications
You must be signed in to change notification settings - Fork 13
/
persist.sh
executable file
·55 lines (48 loc) · 1.26 KB
/
persist.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
#!/bin/bash
set -u
set -e
dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
. ${dir}/utils
PROJECT=${PROJECT:-$(get_project_name)}
p_or_b=backup
if [ $# -lt 1 ];
then
echo "persist.sh [--restore] backupdir"
exit 2
elif [ $1 == "--restore" ];
then
p_or_b=restore
shift
fi
backup_path=$1
shift
function backup_volume {
volume_name=$1
backup_destination=$2
echo "Backup $volume_name to $backup_destination"
MSYS_NO_PATHCONV=1 docker run --rm -v $volume_name:/data -v $backup_destination:/backup ubuntu tar -zcf /backup/$volume_name.tar /data
}
function restore_volume {
volume_name=$1
backup_destination=$2
echo "Restore $volume_name from $backup_destination"
MSYS_NO_PATHCONV=1 docker run --rm -v $volume_name:/data ubuntu find /data -mindepth 1 -delete
MSYS_NO_PATHCONV=1 docker run --rm -v $volume_name:/data -v $backup_destination:/backup ubuntu tar -xf /backup/$volume_name.tar -C .
}
function main {
echo "Mounting volumes and performing $p_or_b"
for v in ${PROJECT}_dbdata ${PROJECT}_omerodata
do
if [ "$p_or_b" == "backup" ]
then
backup_volume $v $backup_path
elif [ "$p_or_b" == "restore" ]
then
restore_volume $v $backup_path
else
echo "Unknown command: $p_or_b"
exit 2
fi
done
}
main