From 4ab4fbeef3e75c295ff36667e66c19733945d7c4 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Sun, 11 Oct 2020 18:39:06 +0200 Subject: [PATCH] Implemented draft --- README.md | 4 +++- scripts/backup.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 scripts/backup.sh diff --git a/README.md b/README.md index ea023d0..c04d3f8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # docker-manager -contains scripts to manage docker +contains scripts to manage docker. + +See https://blog.ssdnodes.com/blog/docker-backup-volumes/. diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100644 index 0000000..68cfdd5 --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,18 @@ +#!/bin/bash +host_backup_folder_path="$HOME/Backup/docker/" +docker_backup_folder_path="/Backup/docker/" +mkdir -p "$backup_folder_path" +docker_container_ids="$(docker ps)"; +backup_folders=("/var/www/html/" "/var/lib/mysql/"); +for docker_container_id in "${docker_container_ids[@]}"; +do + #backup_dir_base_path="$docker_backup_folder_path""archive/$(date '+%Y%m%d%H%M%S')/""$docker_container_id/" + docker stop "$docker_container_id" + for rsync_source_path in "${backup_folders[@]}"; + do + rsync_destination_path="$docker_backup_folder_path""last/""$docker_container_id/$rsync_source_path"; + #backup_dir_path="$backup_dir_base_path$rsync_source_path"; + docker run --rm --volumes-from "$docker_container_id" -v "$host_backup_folder_path:$docker_backup_folder_path" ubuntu bash -c “test -e $rsync_source_path && rsync -a --delete $rsync_source_path $rsync_destination_path” + done + docker start "$docker_container_id" +done