Add script to check for 0 byte files

This commit is contained in:
phil 2024-05-05 17:46:16 +02:00
parent be15c36d4c
commit a95b26e598
2 changed files with 48 additions and 0 deletions

View file

@ -11,3 +11,9 @@
src: nextcloud-updater.j2
dest: "/usr/local/bin/nextcloud-updater"
mode: "0755"
- name: "Common | Kopiere 0-byte-check-script"
ansible.builtin.template:
src: local_nextcloud_zero_bytes.j2
dest: /etc/cron.hourly/local_nextcloud_zero_bytes
mode: "0755"

View file

@ -0,0 +1,42 @@
#!/bin/sh
#
# Emit a list empty files in the Nextcloud data folder which
# weren't empty the last run of this script.
set -eu
NEXTCLOUD_ROOT={{ nextcloud_root }}
STORAGE_DIR=/run/$(basename "$0")
get_nextcloud_instances() {
find "$NEXTCLOUD_ROOT" \
-maxdepth 2 \
-mindepth 2 \
-type d \
-name ocs-provider \
-print0 \
| xargs --null --max-args 1 dirname
}
emit_new_zero_byte_files() {
local old_non_empty="$1"
local new_empty="$2"
if [ -e "$old_non_empty" ]; then
cat "$old_non_empty" "$new_empty" | sort | uniq --repeated
fi
}
mkdir -p "$STORAGE_DIR"
get_nextcloud_instances | while read -r nc_path; do
nc_name=$(basename "$nc_path")
find "$nc_path"/data -type f -empty | grep -v /updater- >"$STORAGE_DIR/${nc_name}-new-empty.list"
find "$nc_path"/data -type f -not -empty | grep -v /updater- >"$STORAGE_DIR/${nc_name}-new-non-empty.list"
emit_new_zero_byte_files \
"$STORAGE_DIR/${nc_name}-old-non-empty.list" \
"$STORAGE_DIR/${nc_name}-new-empty.list"
mv "$STORAGE_DIR/${nc_name}-new-empty.list" "$STORAGE_DIR/${nc_name}-old-empty.list"
mv "$STORAGE_DIR/${nc_name}-new-non-empty.list" "$STORAGE_DIR/${nc_name}-old-non-empty.list"
done