Docker volumes export function

This commit is contained in:
gospodar 2023-02-10 20:40:11 +01:00
parent 234fe510db
commit c47c48ed1e
3 changed files with 19 additions and 3 deletions

1
README.MD Normal file
View File

@ -0,0 +1 @@
### TODO

View File

@ -24,10 +24,10 @@ push_clean=false # clean backup file after push
target_host="127.0.0.1" # rsync target host target_host="127.0.0.1" # rsync target host
target_user="backup" # rsync target user target_user="backup" # rsync target user
target_key='/home/xyz/.ssh/rsync' # rsync key target_key='/home/xyz/.ssh/rsync' # rsync key
#Docker
docker_enabled=false # will you use docker backup docker_enabled=false # will you use docker backup
docker_images=false # backup docker images docker_images=false # backup docker images
#Docker volumes docker_volumes=false #backup docker volumes
#Rsync #Rsync
#Daily cron #Daily cron
#Mysql dbs #Mysql dbs

15
main.sh
View File

@ -116,6 +116,21 @@ function dockerbackup {
echo "Finished" >&2 echo "Finished" >&2
done done
fi fi
if [ "docker_volumes" = true ] then
echo "Backing up Docker volumes..." >&2
for i in `docker inspect --format='{{.Name}}' $(docker ps -q) | cut -f2 -d\/`
do container_name=$i
mkdir -p $tmpdir/containers/$container_name
echo -n "$container_name - "
docker run --rm --userns=host \
--volumes-from $container_name \
-v $backup_path:/backup \
-e TAR_OPTS="$tar_opts" \
piscue/docker-backup \
backup "$tmpdir/containers/$container_name/$container_name-volume.tar.xz"
echo "Finished" >&2
done
fi
fi fi
} }