From a95b26e598d0d41a948392588f379ee13b8dbfc2 Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 5 May 2024 17:46:16 +0200 Subject: [PATCH] Add script to check for 0 byte files --- tasks/common.yml | 6 ++++ templates/local_nextcloud_zero_bytes.j2 | 42 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 templates/local_nextcloud_zero_bytes.j2 diff --git a/tasks/common.yml b/tasks/common.yml index 278e209..9afb574 100644 --- a/tasks/common.yml +++ b/tasks/common.yml @@ -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" diff --git a/templates/local_nextcloud_zero_bytes.j2 b/templates/local_nextcloud_zero_bytes.j2 new file mode 100644 index 0000000..b2e5ba2 --- /dev/null +++ b/templates/local_nextcloud_zero_bytes.j2 @@ -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