This commit is contained in:
trnq1ll0 committed 2026-03-08 12:01:00 +01:00
commit 23448634c2
6 files changed
+195

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
# Remote rsync source. Example: backup@example.com:/srv/data/project/
RSYNC_SOURCE="boogie:/home/boogie/nextcloud_data/root/files/Obsidian"
# Local sync destination (must be a directory inside GIT_REPO_DIR)
RSYNC_TARGET_DIR="/mnt/bfds-nix/rob/backup/Obsidian-daily-git"
# Local monorepo path
GIT_REPO_DIR="/mnt/bfds-nix/rob/backup/Obsidian-daily-git"
# Prefix for commit message (timestamp is appended automatically)
COMMIT_MESSAGE_PREFIX="backup: rsync sync"
# Optional: custom SSH command for rsync (leave empty if not needed)
# RSYNC_RSH="ssh -i /path/to/key -o StrictHostKeyChecking=yes"
+14
View File
@@ -0,0 +1,14 @@
# Remote rsync source. Example: backup@example.com:/srv/data/project/
RSYNC_SOURCE="user@example.com:/path/to/source/"
# Local sync destination (must be a directory inside GIT_REPO_DIR)
RSYNC_TARGET_DIR="/path/to/monorepo/backups/source"
# Local monorepo path
GIT_REPO_DIR="/path/to/monorepo"
# Prefix for commit message (timestamp is appended automatically)
COMMIT_MESSAGE_PREFIX="backup: rsync sync"
# Optional: custom SSH command for rsync (leave empty if not needed)
# RSYNC_RSH="ssh -i /path/to/key -o StrictHostKeyChecking=yes"
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -gt 1 ]]; then
echo "Usage: $0 [path/to/.env]" >&2
exit 2
fi
ENV_FILE="${1:-$(dirname "$0")/.env}"
if [[ ! -f "$ENV_FILE" ]]; then
echo "Env file not found: $ENV_FILE" >&2
exit 1
fi
# shellcheck disable=SC1090
source "$ENV_FILE"
required_vars=(
RSYNC_SOURCE
RSYNC_TARGET_DIR
GIT_REPO_DIR
COMMIT_MESSAGE_PREFIX
)
for var in "${required_vars[@]}"; do
if [[ -z "${!var:-}" ]]; then
echo "Missing required env var: $var" >&2
exit 1
fi
done
mkdir -p "$RSYNC_TARGET_DIR"
repo_abs="$(cd "$GIT_REPO_DIR" && pwd)"
target_abs="$(cd "$RSYNC_TARGET_DIR" && pwd)"
case "$target_abs" in
"$repo_abs"/*) ;;
*)
echo "RSYNC_TARGET_DIR must be inside GIT_REPO_DIR" >&2
exit 1
;;
esac
rel_target="${target_abs#"$repo_abs"/}"
if [[ -n "${RSYNC_RSH:-}" ]]; then
rsync -az --delete -e "$RSYNC_RSH" "$RSYNC_SOURCE" "$RSYNC_TARGET_DIR/"
else
rsync -az --delete "$RSYNC_SOURCE" "$RSYNC_TARGET_DIR/"
fi
git -C "$GIT_REPO_DIR" add -A -- "$rel_target"
if git -C "$GIT_REPO_DIR" diff --cached --quiet -- "$rel_target"; then
exit 0
fi
timestamp="$(date '+%Y-%m-%d %H:%M:%S')"
git -C "$GIT_REPO_DIR" commit -m "$COMMIT_MESSAGE_PREFIX $timestamp" -- "$rel_target"