From 4a307a4edd987a5663467ffb499a744094807530 Mon Sep 17 00:00:00 2001 From: TechHome Date: Thu, 28 May 2020 11:41:38 +0200 Subject: [PATCH] Update prox_config_backup.sh --- prox_config_backup.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/prox_config_backup.sh b/prox_config_backup.sh index 8daf789..31d86d1 100644 --- a/prox_config_backup.sh +++ b/prox_config_backup.sh @@ -1,7 +1,8 @@ #!/bin/bash -# Version 0.0.1 - BETA!!! -# Date 27.02.2020 -# Author TechHome +# Version 0.2.2 - BETA ! ! +# Date 02.20.2020 +# Author DerDanilo +# Contributors aboutte, xmirakulix, bootsie123 # set vars @@ -10,8 +11,11 @@ set -e # permanent backups directory # default value can be overridden by setting environment variable before running prox_config_backup.sh -# example: export BACKUP_DIR="/mnt/pve/media/backup" -_bdir=${BACKUP_DIR:-/mnt/backups/proxmox} +# example: export BACKUP_DIR="/mnt/pve/media/backup +_bdir=${BACK_DIR:-/mnt/backups/proxmox} + +# number of backups to keep before overriding the oldest one +MAX_BACKUPS=5 # temporary storage directory _tdir=${TMP_DIR:-/var/tmp} @@ -57,7 +61,7 @@ function description { your instances. For questions or suggestions please contact me at - https://github.com/marrobHD/proxmox-tools + https://github.com/DerDanilo/proxmox-stuff ----------------------------------------------------------------- Hit return to proceed or CTRL-C to abort. @@ -73,6 +77,14 @@ function are-we-root-abort-if-not { fi } +function check-num-backups { + if [[ $(ls ${_bdir} -l | grep ^- | wc -l) -ge $MAX_BACKUPS ]]; then + local oldbackup="$(ls ${_bdir} -t | tail -1)" + echo "${_bdir}/${oldbackup}" + rm "${_bdir}/${oldbackup}" + fi +} + function copyfilesystem { echo "Tar files" # copy key system files @@ -110,6 +122,7 @@ function startservices { description are-we-root-abort-if-not +check-num-backups # We don't need to stop services, but you can do that if you wish #stopservices