From a9e5968f2aeb5abbc4be3624061e2e86d0ccba71 Mon Sep 17 00:00:00 2001 From: psy <psy@darmstadt.ccc.de> Date: Sat, 1 May 2021 12:14:26 +0200 Subject: [PATCH] do not backup or mail emtpy pads --- files/hedgedoc-retention-cron.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/files/hedgedoc-retention-cron.sh b/files/hedgedoc-retention-cron.sh index 108dab6..7c07092 100644 --- a/files/hedgedoc-retention-cron.sh +++ b/files/hedgedoc-retention-cron.sh @@ -24,18 +24,23 @@ while read -r pad owner; do continue fi - logger -t hedgedoc-util "Processing pad $pad"; + logger -t hedgedoc-util "Processing pad $pad" - if [ "$BACKUP_ENABLED" = true ]; then - hedgedoc-util pad get-content $pad > $BACKUP_PATH/$(date +"%Y%m%d")_$pad.md && logger -t hedgedoc-util "backup successfull" - fi + content=$(hedgedoc-util pad get-content $pad) + + if [ -z $(sed 's/[[:blank:]]//g' <<< "$content") ]; then + logger -t hedgedoc-util "pad is empty" + else + if [ "$BACKUP_ENABLED" = true ]; then + printf "%s" "$content" > $BACKUP_PATH/$(date +"%Y%m%d")_$pad.md && logger -t hedgedoc-util "backup successfull" + fi - if [ "$MAIL_ENABLED" = true ]; then - hedgedoc-util pad mail --convert dokuwiki --convert markdown --template $MAIL_TEMPLATE $pad && logger -t hedgedoc-util "mailed successfull" + if [ "$MAIL_ENABLED" = true ]; then + hedgedoc-util pad mail --convert dokuwiki --convert markdown --template $MAIL_TEMPLATE $pad && logger -t hedgedoc-util "mailed successfull" + fi fi - hedgedoc-util pad delete $pad && \ - logger -t hedgedoc-util "Pad $pad deleted"; + hedgedoc-util pad delete $pad && logger -t hedgedoc-util "Pad $pad deleted" done < <(hedgedoc-util --output tsv-noheader pad list -c id -c ownerId --last-change-older $RETENTION_DAYS) if [ "$BACKUP_ENABLED" = true ]; then -- GitLab