ソースを参照

Add MIN_DUMP_SIZE configuration variable to raise a warning when a backup file size is below this limit

Emmanuel Bouthenot 1 年間 前
コミット
eedfa5d1f0
3 ファイル変更15 行追加1 行削除
  1. 1 0
      Changelog.md
  2. 6 0
      Documentation.md
  3. 8 1
      autopostgresqlbackup

+ 1 - 0
Changelog.md

@@ -4,6 +4,7 @@
 
 * Variable `OPT` (used with pg_dump) is renamed to `PGDUMP_OPTS` and a new variable `PGDUMPALL_OPTS` is available (used for dump globals with pg_dumpall) (Closes: [#12](https://github.com/k0lter/autopostgresqlbackup/issues/12))
 * Fix stderr capture and check return code while running pg_dump/pg_dumpall commands
+* Add `MIN_DUMP_SIZE` configuration variable to raise a warning when a backup file size is below this limit (Closes: [#15](https://github.com/k0lter/autopostgresqlbackup/issues/15))
 
 ## Version 2.0
 

+ 6 - 0
Documentation.md

@@ -152,6 +152,12 @@ Backup files permission
 
 **default**: `600`
 
+### `MIN_DUMP_SIZE`
+
+Minimum size (in bytes) for a dump/file (compressed or not). File size below this limit will raise an warning.
+
+**default**: `256`
+
 ### `ENCRYPTION`
 
 Enable encryption (asymmetric) with GnuPG.

+ 8 - 1
autopostgresqlbackup

@@ -115,6 +115,10 @@ EXT="sql"
 # Backup files permission
 PERM=600
 
+# Minimum size (in bytes) for a dump/file (compressed or not).
+# File size below this limit will raise an warning.
+MIN_DUMP_SIZE=256
+
 # Enable encryption (asymmetric) with GnuPG.
 ENCRYPTION="no"
 
@@ -440,8 +444,11 @@ dump() {
     if [ -f "${dump_file}" ]; then
         log_debug "Fixing permissions (${PERM}) on '${dump_file}'"
         chmod "${PERM}" "${dump_file}"
+        fsize=$(stat -c '%s' "${dump_file}")
         if [ ! -s "${dump_file}" ]; then
-            log_error "Something went wrong '${dump_file}' is empty (no space left on device?)"
+            log_error "Something went wrong '${dump_file}' is empty"
+        elif [ "${fsize}" -lt "${MIN_DUMP_SIZE}" ]; then
+            log_warn "'${dump_file}' (${fsize} bytes) is below the minimum required size (${MIN_DUMP_SIZE} bytes)"
         fi
     else
         log_error "Something went wrong '${dump_file}' does not exists (error during dump?)"