Compare commits
2 Commits
8c02e4f231
...
528b0ee77f
Author | SHA1 | Date | |
---|---|---|---|
528b0ee77f | |||
fe766569c3 |
49
scripts/backup.sh
Executable file
49
scripts/backup.sh
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
[ $# -lt 2 ] && { echo "Usage: $0 {backup|restore} BACKUP_FILENAME"; exit 1; }
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
$1
|
|
@ -1,25 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Script to migrate from volume-less tor instance to one that retains
|
|
||||||
# tor hidden service state (onion url, etc.)
|
|
||||||
|
|
||||||
mkdir -p backup/tor
|
|
||||||
docker cp torch-subscriber-docker_tor_1:/var/lib/tor/svc backup/tor/
|
|
||||||
|
|
||||||
docker-compose down
|
|
||||||
docker-compose up --no-start
|
|
||||||
|
|
||||||
docker run --rm \
|
|
||||||
-v $(pwd)/backup/tor:/backup \
|
|
||||||
-v torch-subscriber-docker_tor_config:/tor \
|
|
||||||
ubuntu \
|
|
||||||
cp -r /backup/svc /tor/
|
|
||||||
|
|
||||||
docker run --rm \
|
|
||||||
-v torch-subscriber-docker_tor_config:/tor \
|
|
||||||
ubuntu \
|
|
||||||
chown -R 0:0 /tor
|
|
||||||
|
|
||||||
rm -rf backup
|
|
||||||
|
|
||||||
docker-compose up -d
|
|
Loading…
Reference in New Issue
Block a user