2020-11-02 17:23:01 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
[ $# -lt 2 ] && { echo "Usage: $0 {backup|restore} BACKUP_FILENAME"; exit 1; }
|
|
|
|
|
2020-11-09 12:25:54 +00:00
|
|
|
DOCKER_COMPOSE=/usr/bin/docker-compose
|
|
|
|
|
2020-11-02 17:23:01 +00:00
|
|
|
backup_file=$2
|
|
|
|
|
|
|
|
project_subscriber_volume_name=client_data
|
|
|
|
project_tor_volume_name=tor_config
|
|
|
|
tor_service=tor
|
|
|
|
|
2020-11-09 12:25:54 +00:00
|
|
|
$DOCKER_COMPOSE --log-level WARNING up --no-start
|
2020-11-02 17:23:01 +00:00
|
|
|
|
2020-11-09 12:25:54 +00:00
|
|
|
project_name=$(docker ps -a --no-trunc | grep $($DOCKER_COMPOSE ps -q ${tor_service}) | awk '{ print $2; }' | awk -F "_" '{ print $1; }')
|
2020-11-02 17:23:01 +00:00
|
|
|
|
|
|
|
project_volumes=$(docker volume ls -f name=$project_name | awk '{if (NR > 1) print $2"\n";}')
|
|
|
|
|
|
|
|
subscriber_volume=$(echo "$project_volumes" | grep ${project_subscriber_volume_name} | xargs)
|
|
|
|
tor_volume=$(echo "$project_volumes" | grep ${project_tor_volume_name} | xargs)
|
|
|
|
|
|
|
|
function backup {
|
|
|
|
|
|
|
|
docker run --rm \
|
|
|
|
-v $subscriber_volume:/data/subscriber \
|
|
|
|
-v $tor_volume:/data/tor \
|
|
|
|
-v $(pwd):/backup \
|
|
|
|
ubuntu \
|
|
|
|
tar -C / -czvf /backup/$backup_file data
|
|
|
|
|
|
|
|
docker run --rm \
|
|
|
|
-v $(pwd):/backup \
|
|
|
|
ubuntu \
|
|
|
|
chown $UID:$UID /backup/$backup_file
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore {
|
|
|
|
|
2020-11-09 12:25:54 +00:00
|
|
|
$DOCKER_COMPOSE stop $tor_service
|
2020-11-02 17:23:01 +00:00
|
|
|
|
2021-02-07 10:03:36 +00:00
|
|
|
cp $backup_file backup.tar.gz
|
|
|
|
|
2020-11-02 17:23:01 +00:00
|
|
|
docker run --rm \
|
|
|
|
-v $subscriber_volume:/data/subscriber \
|
|
|
|
-v $tor_volume:/data/tor \
|
|
|
|
-v $(pwd)/$backup_file:/backup/backup.tar.gz \
|
|
|
|
ubuntu \
|
|
|
|
tar -C / -xzvf /backup/backup.tar.gz
|
|
|
|
|
2020-11-09 12:25:54 +00:00
|
|
|
$DOCKER_COMPOSE start $tor_service
|
2021-02-07 10:03:36 +00:00
|
|
|
|
|
|
|
rm backup.tar.gz
|
2020-11-02 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 12:25:54 +00:00
|
|
|
$1
|