diff --git a/docker/--directory b/docker/--directory new file mode 100644 index 0000000..cab6ce6 Binary files /dev/null and b/docker/--directory differ diff --git a/docker/container.backup b/docker/container.backup index 5c8bdaf..f0bd3a9 100755 --- a/docker/container.backup +++ b/docker/container.backup @@ -6,7 +6,7 @@ ## 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 ## Restart the container service (or docker.service) -## TODO : Clean old backup +## Clean old backup # }}} # How-to use {{{ ## First argument should be the absolut path to the container's data. @@ -16,6 +16,9 @@ # Vars {{{ DEBUG=0 +## Nomber of backup to keep +keep_backup="3" + ## Manage arguments {{{ ## Expect at least 1 argument and 2 maximum 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}" [ "${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