diff --git a/docker/container.backup b/docker/container.backup index 9bcb87e..363e671 100755 --- a/docker/container.backup +++ b/docker/container.backup @@ -4,9 +4,9 @@ ## Backup data of a Docker container. ## To do that, the script will : ## Try to stop the corresponding systemd unit (or docker if no related service is found) -## TODO : Make a archive of the container's data to a backup path -## TODO : Clean old backup +## Make a archive of the container's data to a backup path ## TODO : Restart the container service (or docker.service) +## TODO : Clean old backup # }}} # How-to use {{{ ## First argument should be the absolut path to the container's data. @@ -49,6 +49,8 @@ HELP esac ct_name=$(basename -- "${ct_data_path}") +docker_data_path=$(dirname -- "${ct_data_path}") +ct_backup_path="${docker_backup_path}/${ct_name}" ## }}} # }}} @@ -87,5 +89,12 @@ fi # Stop the container service {{{ systemctl stop "${ct_service_name}" # }}} +# Backup container data {{{ +## Create the directory to store archive if doesn't already exist +[ -d "${ct_backup_path}" ] || mkdir -p -- "${ct_backup_path}" + +## Backup container data +tar czf "${ct_backup_path}/${ct_name}-backup.$(date '+%Y%m%d-%H%M').tar.gz" --directory "${docker_data_path}" "${ct_name}" +# }}} exit 0