Files
Varaverk/user_script_pluin.sh
T

173 lines
11 KiB
Bash

#!/bin/bash
# ==============================================================================================
# ================================= User Script Template =======================================
# ==============================================================================================
#
# This file is the master template for all scripts run via the unRAID User Scripts plugin.
# Copy and paste the contents of this file into a new User Script entry in the plugin,
# then uncomment the script you want to run and set your schedule.
#
# All scripts in this ecosystem live at:
# /mnt/user/appdata/unraid_scripts/
#
# Configuration for all scripts is managed in one place:
# /mnt/user/appdata/unraid_scripts/Master.conf
#
# Shared runtime functions used by all scripts:
# /mnt/user/appdata/unraid_scripts/common.sh
#
# For full setup instructions see:
# /mnt/user/appdata/unraid_scripts/README.md
#
# ==============================================================================================
# Changelog:
# v1.0 — Initial template
# v1.1 — MAX_RSYNC_PROCS removed — bandwidth limiting handles concurrency
# Typo fixes Master.cong → Master.conf
# Added --status flag to arguments section
# Added full directory tree
# All script calls pre-written and grouped by type
# Changelog added
# ==============================================================================================
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ 📂 Repository Structure ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# /mnt/user/appdata/unraid_scripts/
# ├── Master.conf # All user configuration — edit this file only
# ├── common.sh # Shared library — functions used by all scripts
# ├── README.md # Project overview and quick start
# ├── User_Script_Template.sh # This file — copy into User Scripts plugin
# │
# ├── Orchestrators/
# │ └── daily_sync.sh # Runs all daily media share syncs sequentially
# │ # add shares to master.conf, for seqential syncs
# ├── Rsync/
# │ ├── rsync.sh # Core rsync script — called per share or profile
# │ └── README_Rsync_Setup.md # Rsync-specific setup guide
# │
# ├── Tools/
# │ └── recreate_shares.sh # Recreates share dirs from .cfg files after incident
# │
# └── unRAID_Essentials/
# ├── clear_logs.sh # Clears unRAID log files
# ├── docker_syslog_filter.sh # Filters docker veth noise from syslog
# ├── mover_stop.sh # Safely stops the unRAID mover
# ├── php_fpm_max_children.sh # Sets php-fpm max children value
# ├── rsync_stop.sh # Cleanly stops all running rsync processes
# ├── server_reboot.sh # Graceful server reboot with user warning
# ├── user_script_stop.sh # Stops a running User Scripts job
# └── zfs_memory_snapshot.sh # Creates a ZFS memory snapshot
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ 🚀 Script Commands — Uncomment the one you want to run ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# ━━━ Orchestrators (README) ━━━
# The daily orchestrator runs all bulk media shares sequentially in a single scheduled job.
# Instead of creating a User Script entry per share, add the share path to DAILY_SYNC_SHARES
# in Master.conf and the orchestrator handles it automatically at 1am.
#
# Media shares are nothing special — they carry no profile and fall through to global defaults
# in Master.conf. Sequential execution means one share finishes before the next starts,
# no concurrency needed, bandwidth limiting keeps things sane if appdata jobs overlap.
#
# This is where 80% of your rsync shares should live. Only create individual scheduled
# entries for shares that need their own timing — like appdata profiles below.
#
# ━━━ Orchestrators ━━━
#/mnt/user/appdata/unraid_scripts/Orchestrators/daily_sync.sh
#
# ━━━ Rsync — Appdata Profiles (scheduled individually) ━━━
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Arrs_Stack
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Critical-Data
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Important-Data
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Emby
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Gmer4Lfe
#
# ━━━ Rsync — Individual Media Share (ad hoc use) ━━━
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Movies
#/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Tv_Shows
#
# ━━━ Tools ━━━
#/mnt/user/appdata/unraid_scripts/Tools/recreate_shares.sh
#
# ━━━ unRAID Essentials ━━━
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/clear_logs.sh
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/docker_syslog_filter.sh
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/mover_stop.sh
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/php_fpm_max_children.sh
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/rsync_stop.sh
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/server_reboot.sh
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/user_script_stop.sh
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/zfs_memory_snapshot.sh
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ ⚙️ Arguments — Add after the script path ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# ━━━ Rsync / Orchestrators ━━━
#
# --dry-run Preview what would be transferred — no changes made
# --log Enable verbose logging output
# --no-log Disable logging (overrides Master.conf setting)
# --status Print resolved profile and configuration then exit
# --help Show usage information
#
# KEY=VALUE Override any Master.conf variable for this run only
# Better to add a profile in Master.conf for permanent changes
#
# ━━━ unRAID Essentials ━━━
#
# Arguments vary per script — see comments inside each script for details
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ 📋 Profile System ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# Profiles are defined in Master.conf and matched automatically by the
# basename of the directory path passed to rsync.sh (lowercased).
#
# Example:
# /mnt/user/appdata-Failover/Arrs_Stack → matches profile key [arrs_stack]
# /mnt/user/Movies → no match, uses global defaults
#
# If a profile match is found — profile settings are used for that run
# If no profile match is found — global defaults from Master.conf are used
#
# Profile settings control:
# - rsync options PROFILE_RSYNC_OPTS
# - bandwidth limit PROFILE_BW_LIMIT
# - retry count PROFILE_RETRY_COUNT
# - sleep between retry PROFILE_SLEEP
# - containers to stop PROFILE_CRITICAL_CONTAINER_NAMES
# - delayed containers PROFILE_DELAYED_CONTAINERS
# - container delay PROFILE_CONTAINER_DELAY
# - excluded dirs PROFILE_EXCLUDE_DIRS
#
# To add a new profile — add a key to each array in Master.conf
# For permanent changes — always use Master.conf
# For one-off overrides — use KEY=VALUE arguments (see above)
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ 💡 Examples ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# Run arrs_stack profile sync:
# /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Arrs_Stack
#
# Dry run with logging enabled:
# /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Arrs_Stack --dry-run --log
#
# Check what profile and settings resolved before running:
# /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Arrs_Stack --status
#
# Override bandwidth limit for this run only:
# /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Movies BW_LIMIT=5000
#
# Run daily orchestrator:
# /mnt/user/appdata/unraid_scripts/Orchestrators/daily_sync.sh
#
# ==============================================================================================