Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions restic-backup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ NICE_LEVEL="19"
# IOnice class (1=real-time, 2=best-effort, 3=idle)
IONICE_CLASS="3"

# Limit the number of concurrent file-reading threads (I/O). Leave blank to disable.
LIMIT_THREADS=""

# Limit the upload speed in KiB/s (e.g., 5000 for ~5MB/s). Leave blank to disable.
LIMIT_UPLOAD=""

Expand All @@ -61,6 +58,10 @@ GOMAXPROCS_LIMIT=""
# Limit the number of concurrent SFTP connections (e.g., 5). Leave blank for default.
SFTP_CONNECTIONS=""

# Limit how many files are read at the same time during a backup (e.g., 2).
# This is the --read-concurrency flag. Leave blank for default.
READ_CONCURRENCY=""

# --- Logging ---
LOG_FILE="/var/log/restic-backup.log"
LOG_LEVEL="1" # 0=quiet, 1=normal, 2=verbose, 3=very verbose
Expand Down
29 changes: 21 additions & 8 deletions restic-backup.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env bash

# =================================================================
# Restic Backup Script v0.34 - 2025.09.27
# Restic Backup Script v0.35 - 2025.09.28
# =================================================================

set -euo pipefail
umask 077

# --- Script Constants ---
SCRIPT_VERSION="0.34"
SCRIPT_VERSION="0.35"
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CONFIG_FILE="${SCRIPT_DIR}/restic-backup.conf"
LOCK_FILE="/tmp/restic-backup.lock"
Expand Down Expand Up @@ -298,15 +298,13 @@ handle_crash() {

build_backup_command() {
local cmd=(restic)
[ "${LOG_LEVEL:-1}" -le 0 ] && cmd+=(--quiet)
[ "${LOG_LEVEL:-1}" -ge 2 ] && cmd+=(--verbose)
[ "${LOG_LEVEL:-1}" -ge 3 ] && cmd+=(--verbose)
cmd+=($(get_verbosity_flags))
if [ -n "${SFTP_CONNECTIONS:-}" ]; then
cmd+=(-o "sftp.connections=${SFTP_CONNECTIONS}")
fi
cmd+=(backup)
[ -n "${LIMIT_THREADS:-}" ] && cmd+=(--limit-threads "${LIMIT_THREADS}")
[ -n "${LIMIT_UPLOAD:-}" ] && cmd+=(--limit-upload "${LIMIT_UPLOAD}")
cmd+=(backup)
[ -n "${READ_CONCURRENCY:-}" ] && cmd+=(--read-concurrency "${READ_CONCURRENCY}")
[ -n "${BACKUP_TAG:-}" ] && cmd+=(--tag "$BACKUP_TAG")
[ -n "${COMPRESSION:-}" ] && cmd+=(--compression "$COMPRESSION")
[ -n "${PACK_SIZE:-}" ] && cmd+=(--pack-size "$PACK_SIZE")
Expand Down Expand Up @@ -1021,6 +1019,19 @@ run_uninstall_scheduler() {
fi
}

get_verbosity_flags() {
local effective_log_level="${LOG_LEVEL:-1}"
if [[ "${VERBOSE_MODE}" == "true" ]]; then
effective_log_level=2 # Force verbose level 2 when --verbose is used
fi
local flags=()
[ "$effective_log_level" -le 0 ] && flags+=(--quiet)
[ "$effective_log_level" -ge 2 ] && flags+=(--verbose)
[ "$effective_log_level" -ge 3 ] && flags+=(--verbose)

echo "${flags[@]}"
}

# =================================================================
# MAIN OPERATIONS
# =================================================================
Expand Down Expand Up @@ -1120,7 +1131,9 @@ run_backup() {
run_forget() {
echo -e "${C_BOLD}--- Cleaning Old Snapshots ---${C_RESET}"
log_message "Running retention policy"
local forget_cmd=(restic forget)
local forget_cmd=(restic)
forget_cmd+=($(get_verbosity_flags))
forget_cmd+=(forget)
[ -n "${KEEP_LAST:-}" ] && forget_cmd+=(--keep-last "$KEEP_LAST")
[ -n "${KEEP_DAILY:-}" ] && forget_cmd+=(--keep-daily "$KEEP_DAILY")
[ -n "${KEEP_WEEKLY:-}" ] && forget_cmd+=(--keep-weekly "$KEEP_WEEKLY")
Expand Down
2 changes: 1 addition & 1 deletion restic-backup.sh.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76b6f327716705777a04e4fe784fcdc5b9f125dcc302753aa08d871c28254435 restic-backup.sh
c81e8a05b96574f64acccf3860163e5b15e27d1c264c8ef0d6f98caf80f81af7 restic-backup.sh