diff --git a/docker/--directory b/docker/--directory deleted file mode 100644 index cab6ce6..0000000 Binary files a/docker/--directory and /dev/null differ diff --git a/docker/container.backup.all b/docker/container.backup.all new file mode 100755 index 0000000..cd2b5ff --- /dev/null +++ b/docker/container.backup.all @@ -0,0 +1,90 @@ +#!/bin/sh + +# Purpose {{{ +## Ask to backup data of all Docker containers with a second script. +# }}} +# How-to use {{{ +## 1. Needs container.backup script, in the same directory +## cf. https://git.ipr.univ-rennes1.fr/cellinfo/scripts/src/master/docker/container.backup +# wget https://git.ipr.univ-rennes1.fr/cellinfo/scripts/src/master/docker/container.backup +## First argument should be the path to store the backup. +## Second argument can be the absolut path to the Docker directory for containers. +# }}} + +# Vars {{{ +DEBUG=0 + +script_wd=$(dirname "${0}") + +## Manage arguments {{{ +## Expect at least 1 argument and 2 maximum +case $# in + 1 ) + ## Absolut path to store the archives. + ## A sub-directory will be created for each container + docker_backup_path="${1}" + ## Absolut path to Docker containers + docker_ct_path="/srv/dock" + ;; + 2 ) + docker_backup_path="${1}" + docker_ct_path="${2}" + ;; + * ) + cat << HELP + +container.backup.all -- +Backup all data of all Docker's containers. + +EXAMPLE : + - Backup all data of default Docker path (/srv/dock) to /media/usb/docker.backup + container.backup.all /media/usb/docker.backup + - Choose a specific path where containers are stored + container.backup.all /media/usb/docker.backup /my/path/to/docker + +HELP + + exit 1 + ;; +esac +## }}} + +temp_ct_list_file="/tmp/container.list" + +# }}} + +# Tests {{{ + +## Ensure backup directory exists {{{ +if [ ! -d "${docker_backup_path}" ]; then + printf '\e[0;31m%-6s\e[m\n' "Backup directory doesn't seems available : ${docker_backup_path} ." + exit 1 +else + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test arg — Path to store the backup : ${docker_backup_path} ." +fi +## }}} +## Ensure Docker directory exists {{{ +if [ ! -d "${docker_ct_path}" ]; then + printf '\e[0;31m%-6s\e[m\n' "Docker data directory doesn't seems available : ${docker_ct_path} ." + exit 1 +else + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test arg — Path to Docker data : ${docker_ct_path} ." +fi +## }}} +# }}} + +# Get the list of containers name to backup +find "${docker_ct_path}" -mindepth 1 -maxdepth 1 -type d > "${temp_ct_list_file}" + +# For each container in the list +while IFS= read -r ct_path +do + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : While loop — The data of ${ct_path} container will be backup." + "${script_wd}/container.backup" "${ct_path}" "${docker_backup_path}" +done < "${temp_ct_list_file}" + +# Clean temp file +rm -f -- "${temp_ct_list_file}" +# }}} + +exit 0