mirror of
https://github.com/acedanger/shell.git
synced 2026-03-27 06:16:09 -07:00
fix(backup-calibre): use SCRIPT_DIR log path, fix rsync exit code capture, add set -e
This commit is contained in:
@@ -3,10 +3,17 @@
|
|||||||
# Calibre Library Backup Script
|
# Calibre Library Backup Script
|
||||||
# This script backs up the Calibre Library to a network share
|
# This script backs up the Calibre Library to a network share
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
SOURCE_DIR="/home/acedanger/Calibre Library/"
|
SOURCE_DIR="/home/acedanger/Calibre Library/"
|
||||||
DEST_DIR="/mnt/share/media/books/"
|
DEST_DIR="/mnt/share/media/books/"
|
||||||
LOG_FILE="/var/log/calibre-backup.log"
|
LOG_DIR="$SCRIPT_DIR/logs"
|
||||||
|
LOG_FILE="$LOG_DIR/calibre-backup.log"
|
||||||
|
|
||||||
|
# Ensure log directory exists
|
||||||
|
mkdir -p "$LOG_DIR"
|
||||||
|
|
||||||
# Function to log messages with timestamp
|
# Function to log messages with timestamp
|
||||||
log_message() {
|
log_message() {
|
||||||
@@ -32,10 +39,17 @@ log_message "Source: $SOURCE_DIR"
|
|||||||
log_message "Destination: $DEST_DIR"
|
log_message "Destination: $DEST_DIR"
|
||||||
|
|
||||||
# Perform the backup using rsync
|
# Perform the backup using rsync
|
||||||
if rsync -rtvp --delete --exclude="*.tmp" "$SOURCE_DIR" "$DEST_DIR" 2>&1 | tee -a "$LOG_FILE"; then
|
# Use a temp file to capture output while preserving rsync's exit code
|
||||||
|
RSYNC_TMP=$(mktemp)
|
||||||
|
if rsync -rtvp --delete --exclude="*.tmp" "$SOURCE_DIR" "$DEST_DIR" > "$RSYNC_TMP" 2>&1; then
|
||||||
|
cat "$RSYNC_TMP" | tee -a "$LOG_FILE"
|
||||||
log_message "Backup completed successfully"
|
log_message "Backup completed successfully"
|
||||||
|
rm -f "$RSYNC_TMP"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
log_message "ERROR: Backup failed with exit code $?"
|
RSYNC_EXIT=$?
|
||||||
exit 1
|
cat "$RSYNC_TMP" | tee -a "$LOG_FILE"
|
||||||
|
log_message "ERROR: Backup failed with exit code $RSYNC_EXIT"
|
||||||
|
rm -f "$RSYNC_TMP"
|
||||||
|
exit $RSYNC_EXIT
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user