crunchbang/scripts/rclone-sync.sh

26 lines
729 B
Bash
Executable file

#!/bin/bash
# Set timezone to US Eastern (handles both EST and EDT correctly)
export TZ="America/New_York"
# Define source and destination
SOURCE="$HOME/files/media"
DEST="goji-hetzner:"
# Create timestamped log file
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
LOGFILE="$HOME/logs/rclone-sync-$TIMESTAMP.log"
LOCKFILE="/tmp/rclone-sync.lock"
exec 9>"$LOCKFILE"
if ! flock -n 9; then
echo "rclone sync is already running. exiting...." | tee "$LOGFILE" >&2
exit 1
fi
# Run rclone and log output to both screen and file using tee (no --log-file!)
{
echo "=== rclone sync started at $(date) ==="
/usr/bin/rclone sync "$SOURCE" "$DEST" --log-level=INFO
echo "=== rclone sync finished at $(date) ==="
} 2>&1 | tee "$LOGFILE"