WIP: Script to backup Docker container data

This commit is contained in:
Jeremy Gardais 2019-10-17 15:26:31 +02:00
parent 7b3c343ee7
commit 72b4db9a20
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 66 additions and 0 deletions

66
docker/container.backup Executable file
View File

@ -0,0 +1,66 @@
#!/bin/sh
# Purpose {{{
## Backup data of a Docker container.
## To do that, the script will:
## Stop the corresponding container (or docker if no related service is found)
## Make a archive of the container's data to a backup path
## Clean old backup
## Restart the container service (or docker.service)
# }}}
# How-to use {{{
## The container and it's data directory should have the same name.
# }}}
# Vars {{{
DEBUG=0
# }}}
# Tests {{{
# Expect at least 1 argument and 3 maximum {{{
case $# in
1 )
ct_name="${1}"
## Absolut path to the container data
docker_data_path="/srv/docker"
## Absolut path to store the archives.
## A sub-directory will be created for the container
docker_backup_path="/mnt/backup/docker"
;;
2 )
ct_name="${1}"
docker_data_path="${2}"
docker_backup_path="/mnt/backup/docker"
;;
3 )
ct_name="${1}"
docker_data_path="${2}"
docker_backup_path="${3}"
;;
* )
cat << HELP
container.backup --
Backup data of a given Docker container.
EXAMPLE:
- Backup data of FIRST_DOCK container
container.backup FIRST_DOCK
HELP
exit 1
;;
esac
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Args management — Container name to backup: ${ct_name} ."
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Args management — Path to Docker data: ${docker_data_path} ."
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Args management — Path to store the backup: ${docker_backup_path} ."
# }}}
# }}}
exit 0