From 590b87843d9924b6ee459561f5ba16d8fe4cd846 Mon Sep 17 00:00:00 2001 From: shuki Date: Fri, 6 Mar 2026 07:08:42 +0200 Subject: [PATCH] Add configurable disk usage threshold setting Disk usage threshold (default 95%) can now be controlled from Settings. Set to 0 to disable the check. Co-Authored-By: Claude Opus 4.6 --- lib/backup.sh | 13 ++++++++----- lib/config.sh | 3 ++- lib/constants.sh | 1 + tui/models.py | 3 +++ tui/screens/settings.py | 3 +++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/backup.sh b/lib/backup.sh index 51caded..850ce4b 100644 --- a/lib/backup.sh +++ b/lib/backup.sh @@ -78,11 +78,14 @@ _backup_target_impl() { ;; esac - # 4.5. Check remote disk space (fail if >= 95%) - check_remote_disk_space 95 || { - log_error "Remote '$remote_name' has insufficient disk space" - return 1 - } + # 4.5. Check remote disk space + local threshold="${DISK_USAGE_THRESHOLD:-$DEFAULT_DISK_USAGE_THRESHOLD}" + if [[ "$threshold" -gt 0 ]]; then + check_remote_disk_space "$threshold" || { + log_error "Remote '$remote_name' has insufficient disk space" + return 1 + } + fi local start_time; start_time=$(date +%s) diff --git a/lib/config.sh b/lib/config.sh index 8c87add..b8aa6f7 100644 --- a/lib/config.sh +++ b/lib/config.sh @@ -54,6 +54,7 @@ load_config() { SSH_TIMEOUT="${SSH_TIMEOUT:-$DEFAULT_SSH_TIMEOUT}" SSH_RETRIES="${SSH_RETRIES:-$DEFAULT_SSH_RETRIES}" RSYNC_EXTRA_OPTS="${RSYNC_EXTRA_OPTS:-}" + DISK_USAGE_THRESHOLD="${DISK_USAGE_THRESHOLD:-$DEFAULT_DISK_USAGE_THRESHOLD}" # WORK_DIR can be overridden in config; re-export if changed export WORK_DIR @@ -64,7 +65,7 @@ load_config() { export BACKUP_MODE BWLIMIT RETENTION_COUNT export LOG_LEVEL LOG_RETAIN NOTIFY_EMAIL NOTIFY_ON export SMTP_HOST SMTP_PORT SMTP_USER SMTP_FROM SMTP_SECURITY - export SSH_TIMEOUT SSH_RETRIES RSYNC_EXTRA_OPTS + export SSH_TIMEOUT SSH_RETRIES RSYNC_EXTRA_OPTS DISK_USAGE_THRESHOLD } validate_config() { diff --git a/lib/constants.sh b/lib/constants.sh index a81a308..a35307b 100644 --- a/lib/constants.sh +++ b/lib/constants.sh @@ -48,3 +48,4 @@ readonly DEFAULT_REMOTE_TYPE="ssh" readonly DEFAULT_S3_REGION="us-east-1" readonly DEFAULT_SMTP_PORT=587 readonly DEFAULT_SMTP_SECURITY="tls" +readonly DEFAULT_DISK_USAGE_THRESHOLD=95 diff --git a/tui/models.py b/tui/models.py index 405df1c..d7cd108 100644 --- a/tui/models.py +++ b/tui/models.py @@ -205,6 +205,7 @@ class AppSettings: ssh_timeout: str = "30" ssh_retries: str = "3" rsync_extra_opts: str = "" + disk_usage_threshold: str = "95" work_dir: str = "/usr/local/gniza/workdir" web_port: str = "2323" web_host: str = "0.0.0.0" @@ -229,6 +230,7 @@ class AppSettings: ssh_timeout=data.get("SSH_TIMEOUT", "30"), ssh_retries=data.get("SSH_RETRIES", "3"), rsync_extra_opts=data.get("RSYNC_EXTRA_OPTS", ""), + disk_usage_threshold=data.get("DISK_USAGE_THRESHOLD", "95"), work_dir=data.get("WORK_DIR", "/usr/local/gniza/workdir"), web_port=data.get("WEB_PORT", "8080"), web_host=data.get("WEB_HOST", "0.0.0.0"), @@ -253,6 +255,7 @@ class AppSettings: "SSH_TIMEOUT": self.ssh_timeout, "SSH_RETRIES": self.ssh_retries, "RSYNC_EXTRA_OPTS": self.rsync_extra_opts, + "DISK_USAGE_THRESHOLD": self.disk_usage_threshold, "WORK_DIR": self.work_dir, "WEB_PORT": self.web_port, "WEB_HOST": self.web_host, diff --git a/tui/screens/settings.py b/tui/screens/settings.py index 6001af9..d3baa72 100644 --- a/tui/screens/settings.py +++ b/tui/screens/settings.py @@ -29,6 +29,8 @@ class SettingsScreen(Screen): yield Input(value=settings.retention_count, id="set-retention") yield Static("Default Bandwidth Limit (KB/s, 0=unlimited):") yield Input(value=settings.bwlimit, id="set-bwlimit") + yield Static("Disk Usage Threshold (%, 0=disable):") + yield Input(value=settings.disk_usage_threshold, id="set-diskthreshold") yield Static("Notification Email:") yield Input(value=settings.notify_email, id="set-email") yield Static("Notify On:") @@ -100,6 +102,7 @@ class SettingsScreen(Screen): ssh_timeout=self.query_one("#set-sshtimeout", Input).value.strip() or "30", ssh_retries=self.query_one("#set-sshretries", Input).value.strip() or "3", rsync_extra_opts=self.query_one("#set-rsyncopts", Input).value.strip(), + disk_usage_threshold=self.query_one("#set-diskthreshold", Input).value.strip() or "95", work_dir=self.query_one("#set-workdir", Input).value.strip() or "/usr/local/gniza/workdir", web_port=self.query_one("#set-web-port", Input).value.strip() or "8080", web_host=self.query_one("#set-web-host", Input).value.strip() or "0.0.0.0",