Create an archive of container's data

This commit is contained in:
Jeremy Gardais 2019-10-18 19:20:52 +02:00
parent 3d6dda4f9a
commit 9c88629696
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 11 additions and 2 deletions

View File

@ -4,9 +4,9 @@
## Backup data of a Docker container. ## Backup data of a Docker container.
## To do that, the script will: ## To do that, the script will:
## Try to stop the corresponding systemd unit (or docker if no related service is found) ## 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 ## Make a archive of the container's data to a backup path
## TODO: Clean old backup
## TODO: Restart the container service (or docker.service) ## TODO: Restart the container service (or docker.service)
## TODO: Clean old backup
# }}} # }}}
# How-to use {{{ # How-to use {{{
## First argument should be the absolut path to the container's data. ## First argument should be the absolut path to the container's data.
@ -49,6 +49,8 @@ HELP
esac esac
ct_name=$(basename -- "${ct_data_path}") 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 {{{ # Stop the container service {{{
systemctl stop "${ct_service_name}" 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 exit 0