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
12 changes: 12 additions & 0 deletions restic-backup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ 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=""

# Limit the number of CPU cores Restic can use (e.g., 2). Leave blank for default (all cores).
GOMAXPROCS_LIMIT=""

# Limit the number of concurrent SFTP connections (e.g., 5). Leave blank for default.
SFTP_CONNECTIONS=""

# --- Logging ---
LOG_FILE="/var/log/restic-backup.log"
LOG_LEVEL="1" # 0=quiet, 1=normal, 2=verbose, 3=very verbose
Expand Down
32 changes: 26 additions & 6 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.33 - 2025.09.27
# Restic Backup Script v0.34 - 2025.09.27
# =================================================================

set -euo pipefail
umask 077

# --- Script Constants ---
SCRIPT_VERSION="0.33"
SCRIPT_VERSION="0.34"
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 @@ -195,9 +195,9 @@ check_for_script_update() {
return 1
fi
echo -e "${C_GREEN}✅ Checksum verified successfully.${C_RESET}"
if ! grep -q "#!/bin/bash" "$temp_script"; then
echo -e "${C_RED}Downloaded file does not appear to be a valid script. Aborting update.${C_RESET}" >&2
return 1
if ! grep -q -E "^#!/(usr/)?bin/(env )?bash" "$temp_script"; then
echo -e "${C_RED}Downloaded file does not appear to be a valid script. Aborting update.${C_RESET}" >&2
return 1
fi
chmod +x "$temp_script"
mv "$temp_script" "$0"
Expand Down Expand Up @@ -301,7 +301,12 @@ build_backup_command() {
[ "${LOG_LEVEL:-1}" -le 0 ] && cmd+=(--quiet)
[ "${LOG_LEVEL:-1}" -ge 2 ] && cmd+=(--verbose)
[ "${LOG_LEVEL:-1}" -ge 3 ] && cmd+=(--verbose)
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}")
[ -n "${BACKUP_TAG:-}" ] && cmd+=(--tag "$BACKUP_TAG")
[ -n "${COMPRESSION:-}" ] && cmd+=(--compression "$COMPRESSION")
[ -n "${PACK_SIZE:-}" ] && cmd+=(--pack-size "$PACK_SIZE")
Expand Down Expand Up @@ -583,6 +588,9 @@ send_notification() {
setup_environment() {
export RESTIC_REPOSITORY
export RESTIC_PASSWORD_FILE
if [ -n "${GOMAXPROCS_LIMIT:-}" ]; then
export GOMAXPROCS="${GOMAXPROCS_LIMIT}"
fi
if [ -n "${RESTIC_CACHE_DIR:-}" ]; then
export RESTIC_CACHE_DIR
mkdir -p "$RESTIC_CACHE_DIR"
Expand Down Expand Up @@ -638,7 +646,19 @@ run_preflight_checks() {
fi
if [[ "$verbosity" == "verbose" ]]; then echo -e "[${C_GREEN} OK ${C_RESET}]"; fi
fi

# --- Performance Settings Validation ---
if [[ "$verbosity" == "verbose" ]]; then echo -e "\n ${C_DIM}- Checking Performance Settings${C_RESET}"; fi
local numeric_vars=("GOMAXPROCS_LIMIT" "LIMIT_THREADS" "LIMIT_UPLOAD" "SFTP_CONNECTIONS")
for var in "${numeric_vars[@]}"; do
local value="${!var:-}"
if [[ -n "$value" ]]; then
if [[ "$verbosity" == "verbose" ]]; then printf " %-65s" "Validating ${var} ('${value}')..."; fi
if ! [[ "$value" =~ ^[0-9]+$ ]]; then
handle_failure "${var} must be a positive integer, but got: '${value}'"
fi
if [[ "$verbosity" == "verbose" ]]; then echo -e "[${C_GREEN} OK ${C_RESET}]"; fi
fi
done
# --- Config Files Existence & Permissions Check ---
if [[ "$verbosity" == "verbose" ]]; then echo -e "\n ${C_DIM}- Checking Configuration Files${C_RESET}"; fi
if [[ "$verbosity" == "verbose" ]]; then printf " %-65s" "Secure permissions on config file (600)..."; fi
Expand Down
2 changes: 1 addition & 1 deletion restic-backup.sh.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3834308a4d720a8a18e68f85f759817e2748919fe8bbd7eddbab35c52c850c8a restic-backup.sh
76b6f327716705777a04e4fe784fcdc5b9f125dcc302753aa08d871c28254435 restic-backup.sh