diff options
author | doc <doc@filenotfound.org> | 2025-06-30 20:11:52 +0000 |
---|---|---|
committer | doc <doc@filenotfound.org> | 2025-06-30 20:11:52 +0000 |
commit | 41e897f4945aaf8fbcdf0b12ac2f08c5e6ae0458 (patch) | |
tree | db7c3520fd91abc3cf56b1a52095d23f3a80d059 /rsync_zfs_sync_helper.sh |
Diffstat (limited to 'rsync_zfs_sync_helper.sh')
-rwxr-xr-x | rsync_zfs_sync_helper.sh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/rsync_zfs_sync_helper.sh b/rsync_zfs_sync_helper.sh new file mode 100755 index 0000000..685eb88 --- /dev/null +++ b/rsync_zfs_sync_helper.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# sync_to_vault.sh +# Rsync + ZFS sanity tool with built-in slash wisdom + +set -euo pipefail + +# === CONFIG === +VAULT_HOST="thevault.sshjunkie.com" +BASE_TARGET="/nexus/miniodata/assets" + +# === USAGE === +if [[ $# -lt 2 ]]; then + echo "Usage: $0 <source_dir> <bucket_name>" + echo "Example: $0 /mnt/backup3/tempshit/genesisassets/ genesisassets-secure" + exit 1 +fi + +SRC="$1" +BUCKET="$2" +DST="${BASE_TARGET}/${BUCKET}/" + +# === WISDOM === +echo "🧘 Trailing slashes, my friend. — John Northrup" +echo + +if [[ "$SRC" != */ ]]; then + echo "⚠️ Warning: Source path does not end in a slash." + echo " You may be copying the folder itself instead of its contents." + echo " You probably want: ${SRC}/" + echo +fi + +# === VERIFY SOURCE === +if [[ ! -d "$SRC" ]]; then + echo "❌ Source directory does not exist: $SRC" + exit 1 +fi + +# === CREATE ZFS DATASET ON REMOTE IF MISSING === +echo "🔍 Ensuring dataset exists on $VAULT_HOST..." +ssh root@$VAULT_HOST "zfs list nexus/miniodata/assets/$BUCKET" >/dev/null 2>&1 || { + echo "📁 Creating dataset nexus/miniodata/assets/$BUCKET on $VAULT_HOST" + ssh root@$VAULT_HOST "zfs create nexus/miniodata/assets/$BUCKET" +} + +# === RSYNC === +echo "🚀 Starting rsync from $SRC to $VAULT_HOST:$DST" +rsync -avhP "$SRC" root@$VAULT_HOST:"$DST" + +# === SNAPSHOT === +SNAPNAME="rsync_$(date +%Y%m%d_%H%M%S)" +echo "📸 Creating post-sync snapshot: $SNAPNAME" +ssh root@$VAULT_HOST "zfs snapshot nexus/miniodata/assets/$BUCKET@$SNAPNAME" + +# === DONE === +echo "✅ Sync and snapshot complete: $BUCKET@$SNAPNAME" |