Complete Linux backup manager with Whiptail TUI and CLI interface. Adapted from gniza4cp (cPanel backup tool) with target/profile-based system replacing cPanel-specific features. - 14 core engine modules (backup, restore, targets, remotes, transfer, etc.) - 11 Whiptail TUI screens (full CRUD for targets/remotes/schedules) - CLI entrypoint with subcommands for scripting/cron - Support for SSH, local, S3, and Google Drive remotes - rsync --link-dest incremental snapshots - Root and user mode (XDG paths) - 70 passing tests - Config templates, installer, uninstaller Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
32 lines
823 B
Bash
32 lines
823 B
Bash
#!/usr/bin/env bash
|
|
# gniza4linux/lib/locking.sh — flock-based concurrency control
|
|
|
|
[[ -n "${_GNIZA4LINUX_LOCKING_LOADED:-}" ]] && return 0
|
|
_GNIZA4LINUX_LOCKING_LOADED=1
|
|
|
|
declare -g LOCK_FD=""
|
|
|
|
acquire_lock() {
|
|
local lock_file="${LOCK_FILE:-/var/run/gniza.lock}"
|
|
local lock_dir; lock_dir=$(dirname "$lock_file")
|
|
mkdir -p "$lock_dir" || die "Cannot create lock directory: $lock_dir"
|
|
|
|
exec {LOCK_FD}>"$lock_file"
|
|
|
|
if ! flock -n "$LOCK_FD"; then
|
|
die "Another gniza process is running (lock: $lock_file)" "$EXIT_LOCKED"
|
|
fi
|
|
|
|
echo $$ >&"$LOCK_FD"
|
|
log_debug "Lock acquired: $lock_file (PID $$)"
|
|
}
|
|
|
|
release_lock() {
|
|
if [[ -n "$LOCK_FD" ]]; then
|
|
flock -u "$LOCK_FD" 2>/dev/null
|
|
exec {LOCK_FD}>&- 2>/dev/null
|
|
LOCK_FD=""
|
|
log_debug "Lock released"
|
|
fi
|
|
}
|