ctdb-scripts: Avoid shellcheck warning SC2012 (ls for file list)
[nivanova/samba-autobuild/.git] / ctdb / config / events.d / 00.ctdb
index 3649ed001d69334cf5df54a85815c0c087c42a44..d60b9aa53c30bbf308c6862ef8f7db6782ec512e 100755 (executable)
@@ -93,9 +93,12 @@ EOF
            mv "$_db" "$_backup"
 
            # Now remove excess backups
-           ls -td "${_db}."*".corrupt" |
-           tail -n +$((${CTDB_MAX_CORRUPT_DB_BACKUPS:-10} + 1)) |
-           xargs rm -f
+           _max="${CTDB_MAX_CORRUPT_DB_BACKUPS:-10}"
+           _bdb="${_db##*/}" # basename
+           find "$_dir" -name "${_bdb}.*.corrupt" |
+                   sort -r |
+                   tail -n +$((_max + 1)) |
+                   xargs rm -f
        }
     done
 }