From 9cd5e1c3251ff7df76c1f93903ee9e9f6c112945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lecour?= Date: Sat, 23 Mar 2019 10:32:29 +0100 Subject: [PATCH] improve backup detection --- evocheck.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/evocheck.sh b/evocheck.sh index 09ae844..29b461b 100755 --- a/evocheck.sh +++ b/evocheck.sh @@ -847,14 +847,21 @@ if is_debian; then # Check if files in /home/backup/ are up-to-date if [ "$IS_BACKUPUPTODATE" = 1 ]; then if [ -d /home/backup/ ]; then - for file in /home/backup/*; do - limit=$(date +"%s" -d "now - 2 day") - updated_at=$(stat -c "%Y" "$file") - if [ -f "$file" ] && [ "$limit" -gt "$updated_at" ]; then - failed "IS_BACKUPUPTODATE" "$file has not been backed up" - test "${VERBOSE}" = 1 || break; - fi - done + if [ -n "$(ls -A /home/backup/)" ]; then + for file in /home/backup/*; do + limit=$(date +"%s" -d "now - 2 day") + updated_at=$(stat -c "%Y" "$file") + + if [ -f "$file" ] && [ "$limit" -gt "$updated_at" ]; then + failed "IS_BACKUPUPTODATE" "$file has not been backed up" + test "${VERBOSE}" = 1 || break; + fi + done + else + failed "IS_BACKUPUPTODATE" "/home/backup/ is empty" + fi + else + failed "IS_BACKUPUPTODATE" "/home/backup/ is missing" fi fi