Clean the old backups of the container's data

This commit is contained in:
Jeremy Gardais 2019-10-19 19:18:29 +02:00
parent d187a5d568
commit b7ac722068
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
2 changed files with 10 additions and 1 deletions

BIN
docker/--directory Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
## 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)
## Make a archive of the container's data to a backup path ## Make a archive of the container's data to a backup path
## Restart the container service (or docker.service) ## Restart the container service (or docker.service)
## TODO: Clean old backup ## 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.
@ -16,6 +16,9 @@
# Vars {{{ # Vars {{{
DEBUG=0 DEBUG=0
## Nomber of backup to keep
keep_backup="3"
## Manage arguments {{{ ## Manage arguments {{{
## Expect at least 1 argument and 2 maximum ## Expect at least 1 argument and 2 maximum
case $# in case $# in
@ -105,5 +108,11 @@ tar czf "${ct_backup_path}/${ct_name}-backup.$(date '+%Y%m%d-%H%M').tar.gz" --di
systemctl start "${ct_service_name}" systemctl start "${ct_service_name}"
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Service management — Service ${ct_service_name} was started." [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Service management — Service ${ct_service_name} was started."
# }}} # }}}
# Remove old backups {{{
cd -- "${ct_backup_path}" || exit 1
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Cleaning — Keep only the ${keep_backup} newest backups."
find . -type f | sort | head -n -"${keep_backup}" | xargs -d '\n' rm -f --
cd -- - > /dev/null || exit 1
# }}}
exit 0 exit 0