56 lines
1.3 KiB
Bash
Executable File
56 lines
1.3 KiB
Bash
Executable File
#!/bin/bash -e
|
|
|
|
[ $# -lt 2 ] && { echo "Usage: $0 {backup|restore} BACKUP_FILENAME"; exit 1; }
|
|
|
|
DOCKER_COMPOSE=/usr/bin/docker-compose
|
|
|
|
backup_file=$2
|
|
|
|
project_subscriber_volume_name=client_data
|
|
project_tor_volume_name=tor_config
|
|
tor_service=tor
|
|
|
|
$DOCKER_COMPOSE --log-level WARNING up --no-start
|
|
|
|
project_name=$(docker ps -a --no-trunc | grep $($DOCKER_COMPOSE ps -q ${tor_service}) | awk '{ print $2; }' | awk -F "_" '{ print $1; }')
|
|
|
|
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 {
|
|
|
|
$DOCKER_COMPOSE stop $tor_service
|
|
|
|
cp $backup_file backup.tar.gz
|
|
|
|
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
|
|
|
|
$DOCKER_COMPOSE start $tor_service
|
|
|
|
rm backup.tar.gz
|
|
}
|
|
|
|
$1
|