Added backup script
This commit is contained in:
parent
fe766569c3
commit
528b0ee77f
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
|
Loading…
Reference in New Issue
Block a user