From 0e14598d344891ad97006f3e0101be2668acadd8 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 21 Jun 2026 14:15:38 +0200 Subject: [PATCH 1/3] Remove unused job helper functions get_job_config_file, validate_job_config, get_default_job and is_multi_job have no callers anywhere in the codebase or tests. Callers build job paths inline and validation/mode-detection are never invoked. --- lib/jobs.sh | 79 ----------------------------------------------------- 1 file changed, 79 deletions(-) diff --git a/lib/jobs.sh b/lib/jobs.sh index f186fec..76ba83c 100644 --- a/lib/jobs.sh +++ b/lib/jobs.sh @@ -81,13 +81,6 @@ get_job_scripts_dir() { echo "$JOBS_DIR/$job_name/scripts" } -# Get job config file path -# Usage: config_file=$(get_job_config_file "production") -get_job_config_file() { - local job_name="$1" - echo "$JOBS_DIR/$job_name/$JOB_CONFIG_FILE" -} - # ---------- Job Listing ---------- # List all job names (one per line) @@ -236,57 +229,6 @@ save_job_config() { chmod 600 "$config_file" } -# Validate job configuration has required fields -# Usage: validate_job_config "production" || exit 1 -validate_job_config() { - local job_name="$1" - local errors=0 - - # Required fields - local required=("RCLONE_REMOTE") - local field - - for field in "${required[@]}"; do - local value - value="$(get_job_config "$job_name" "$field")" - if [[ -z "$value" ]]; then - print_error "Job '$job_name' missing required config: $field" - ((errors++)) || true - fi - done - - # At least one backup type must be enabled - local do_db do_files - do_db="$(get_job_config "$job_name" "DO_DATABASE")" - do_files="$(get_job_config "$job_name" "DO_FILES")" - - if [[ "$do_db" != "true" && "$do_files" != "true" ]]; then - print_error "Job '$job_name' must have DO_DATABASE=true or DO_FILES=true" - ((errors++)) || true - fi - - # Validate paths if specified - if [[ "$do_db" == "true" ]]; then - local db_path - db_path="$(get_job_config "$job_name" "RCLONE_DB_PATH")" - if [[ -z "$db_path" ]]; then - print_error "Job '$job_name' has DO_DATABASE=true but no RCLONE_DB_PATH" - ((errors++)) || true - fi - fi - - if [[ "$do_files" == "true" ]]; then - local files_path - files_path="$(get_job_config "$job_name" "RCLONE_FILES_PATH")" - if [[ -z "$files_path" ]]; then - print_error "Job '$job_name' has DO_FILES=true but no RCLONE_FILES_PATH" - ((errors++)) || true - fi - fi - - [[ $errors -eq 0 ]] -} - # ---------- Job CRUD Operations ---------- # Create a new job @@ -1090,24 +1032,3 @@ count_jobs() { echo "$count" } - -# Get the default job name (or first available) -# Usage: job=$(get_default_job) -get_default_job() { - # If default job exists, use it - if job_exists "$DEFAULT_JOB_NAME"; then - echo "$DEFAULT_JOB_NAME" - return 0 - fi - - # Otherwise return first job - list_jobs | head -1 -} - -# Check if we're in multi-job mode (more than one job configured) -# Usage: is_multi_job && echo "multiple jobs" -is_multi_job() { - local count - count="$(count_jobs)" - [[ $count -gt 1 ]] -} From 9214bd2ced9efec08561cbce20cd08b56f03a58f Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 21 Jun 2026 14:15:38 +0200 Subject: [PATCH 2/3] Remove unused migration helper functions rollback_migration, show_migration_status and is_multi_job_enabled have no callers: no CLI subcommand routes to rollback or status, and auto-migration is one-way. Drops the now-orphaned "Migration Status" section header too. --- lib/migration.sh | 130 ----------------------------------------------- 1 file changed, 130 deletions(-) diff --git a/lib/migration.sh b/lib/migration.sh index 1b6cf15..bbd8039 100644 --- a/lib/migration.sh +++ b/lib/migration.sh @@ -41,12 +41,6 @@ needs_migration() { return 1 } -# Check if system is using multi-job structure -is_multi_job_enabled() { - local install_dir="${INSTALL_DIR:-/etc/backupd}" - [[ -f "$MIGRATION_MARKER" || -d "$install_dir/jobs" ]] -} - # ---------- Migration Functions ---------- # Migrate legacy .config to jobs/default/ @@ -167,130 +161,6 @@ EOF return 0 } -# Rollback migration (restore single-config operation) -# Usage: rollback_migration [--force] -rollback_migration() { - local force="${1:-}" - local install_dir="${INSTALL_DIR:-/etc/backupd}" - local jobs_dir="$install_dir/jobs" - - # Check if migrated - if [[ ! -f "$MIGRATION_MARKER" ]]; then - print_warning "System was not migrated, nothing to rollback" - return 0 - fi - - # Count jobs - only allow rollback if only default job exists - local job_count=0 - local job_dir - for job_dir in "$jobs_dir"/*/; do - [[ ! -d "$job_dir" ]] && continue - [[ -f "$job_dir/job.conf" ]] && ((job_count++)) || true - done - - if [[ $job_count -gt 1 && "$force" != "--force" ]]; then - print_error "Multiple jobs exist. Remove extra jobs first or use --force" - return 1 - fi - - print_info "Rolling back to single-config mode..." - - # Stop all job-specific timers (non-default) - if [[ -d "$jobs_dir" ]]; then - for job_dir in "$jobs_dir"/*/; do - [[ ! -d "$job_dir" ]] && continue - local job_name - job_name="$(basename "$job_dir")" - [[ "$job_name" == "default" ]] && continue - - # Remove job-specific timers - local timer_type - for timer_type in db files verify verify-full; do - local timer_name="backupd-${job_name}-${timer_type}.timer" - local service_name="backupd-${job_name}-${timer_type}.service" - systemctl stop "$timer_name" 2>/dev/null || true - systemctl disable "$timer_name" 2>/dev/null || true - rm -f "/etc/systemd/system/$timer_name" 2>/dev/null || true - rm -f "/etc/systemd/system/$service_name" 2>/dev/null || true - done - done - systemctl daemon-reload 2>/dev/null || true - fi - - # Remove jobs directory - rm -rf "$jobs_dir" - - # Remove migration marker - rm -f "$MIGRATION_MARKER" - - print_success "Rollback complete" - print_info "System restored to single-config mode" - print_info "Legacy config preserved at: $install_dir/.config" - - return 0 -} - -# ---------- Migration Status ---------- - -# Show migration status -# Usage: show_migration_status -show_migration_status() { - local install_dir="${INSTALL_DIR:-/etc/backupd}" - - echo "Migration Status" - echo "================" - echo - - if [[ -f "$MIGRATION_MARKER" ]]; then - local version date from - version="$(grep "^MIGRATION_VERSION=" "$MIGRATION_MARKER" 2>/dev/null | cut -d'"' -f2)" || version="unknown" - date="$(grep "^MIGRATION_DATE=" "$MIGRATION_MARKER" 2>/dev/null | cut -d'"' -f2)" || date="unknown" - from="$(grep "^MIGRATED_FROM=" "$MIGRATION_MARKER" 2>/dev/null | cut -d'"' -f2)" || from="unknown" - - print_success "Multi-job mode: ENABLED" - echo " Version: $version" - echo " Date: $date" - echo " From: $from" - else - print_warning "Multi-job mode: NOT ENABLED" - if [[ -f "$install_dir/.config" ]]; then - echo " Legacy config exists" - if needs_migration; then - print_info "Migration available: run 'backupd' to migrate" - fi - else - echo " No configuration found" - fi - fi - - echo - - # Count jobs - local job_count=0 - if [[ -d "$install_dir/jobs" ]]; then - local job_dir - for job_dir in "$install_dir/jobs"/*/; do - [[ ! -d "$job_dir" ]] && continue - [[ -f "$job_dir/job.conf" ]] && ((job_count++)) || true - done - fi - - echo "Jobs configured: $job_count" - if [[ $job_count -gt 0 ]]; then - echo - echo "Job list:" - for job_dir in "$install_dir/jobs"/*/; do - [[ ! -d "$job_dir" ]] && continue - [[ -f "$job_dir/job.conf" ]] || continue - local job_name - job_name="$(basename "$job_dir")" - local enabled - enabled="$(grep "^JOB_ENABLED=" "$job_dir/job.conf" 2>/dev/null | cut -d'"' -f2)" || enabled="unknown" - echo " - $job_name (enabled: $enabled)" - done - fi -} - # ---------- Auto-Migration Hook ---------- # Run migration if needed (called at startup) From df7a99a90437fc8c273d82d042bc5ecf88c96221 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 21 Jun 2026 14:15:38 +0200 Subject: [PATCH 3/3] Remove unused schedule-template accessors get_template_display, get_template_description and detect_template_name have no callers. get_template_schedule and list_schedule_templates (used by the schedule CLI) are kept. --- lib/schedule.sh | 35 ----------------------------------- 1 file changed, 35 deletions(-) mode change 100755 => 100644 lib/schedule.sh diff --git a/lib/schedule.sh b/lib/schedule.sh old mode 100755 new mode 100644 index eaa35df..6aaceb9 --- a/lib/schedule.sh +++ b/lib/schedule.sh @@ -32,41 +32,6 @@ get_template_schedule() { [[ -n "$template" ]] && echo "$template" | cut -d'|' -f1 } -# BACKUPD-035: Get template display name by name -# Usage: get_template_display "daily_2am" -# Returns: Display name or empty if not found -get_template_display() { - local name="$1" - local template="${SCHEDULE_TEMPLATES[$name]}" - [[ -n "$template" ]] && echo "$template" | cut -d'|' -f2 -} - -# BACKUPD-035: Get template description by name -# Usage: get_template_description "daily_2am" -# Returns: Description or empty if not found -get_template_description() { - local name="$1" - local template="${SCHEDULE_TEMPLATES[$name]}" - [[ -n "$template" ]] && echo "$template" | cut -d'|' -f3 -} - -# BACKUPD-035: Detect template name from OnCalendar expression -# Usage: detect_template_name "*-*-* 02:00:00" -# Returns: Template name or empty if no match -detect_template_name() { - local schedule="$1" - local name oncalendar - - for name in "${!SCHEDULE_TEMPLATES[@]}"; do - oncalendar=$(echo "${SCHEDULE_TEMPLATES[$name]}" | cut -d'|' -f1) - if [[ "$oncalendar" == "$schedule" ]]; then - echo "$name" - return 0 - fi - done - return 1 -} - # BACKUPD-035: List all available templates # Usage: list_schedule_templates # Output: name|oncalendar|display|description (one per line)