Enhanced rclone container with inotifywait to sync scrolls, hedgedoc uploads, ghost, and trilium to Google Drive, Internet Archive, Web3.storage, and local NAS

This commit is contained in:
2025-05-26 20:12:25 -05:00
parent 5c9950ad4f
commit 24114f762c
5 changed files with 104 additions and 73 deletions
+62
View File
@@ -0,0 +1,62 @@
#!/bin/bash
set -e
echo "Starting rclone synchronization at $(date)"
# Function to sync to Google Drive
sync_to_gdrive() {
local src=$1
local dest=$2
echo "Syncing $src to Google Drive (gdrive:$dest)"
rclone sync "$src" "gdrive:$dest" --progress --transfers=4 --checkers=8 --exclude "*.{db,db-shm,db-wal}" --log-level INFO
}
# Function to sync to Internet Archive (only .scroll and .seal files)
sync_to_ia() {
local src=$1
local dest=$2
echo "Syncing $src to Internet Archive (ia:$dest)"
rclone sync "$src" "ia:$dest" --progress --transfers=4 --checkers=8 --wait-archive=1h --include "*.{scroll,seal}" --log-level INFO
}
# Function to sync to Web3.storage
sync_to_web3() {
local src=$1
local dest=$2
if [ -d "$src" ]; then
echo "Syncing $src to Web3.storage (web3:$dest)"
rclone sync "$src" "web3:$dest" --progress --transfers=4 --checkers=8 --log-level INFO
else
echo "$src directory not found, skipping Web3.storage sync"
fi
}
# Function to sync to NAS
sync_to_nas() {
local src=$1
local dest=$2
if [ -d "/nas" ]; then
echo "Syncing $src to NAS (/nas/$dest)"
rclone sync "$src" "/nas/$dest" --progress --transfers=4 --checkers=8 --exclude "*.{db,db-shm,db-wal}" --log-level INFO
else
echo "NAS mount not found at /nas, skipping NAS sync"
fi
}
# Sync working drafts to Google Drive
sync_to_gdrive "/data/scrolls" "fold-stack/scrolls"
sync_to_gdrive "/data/hedgedoc/uploads" "fold-stack/hedgedoc_uploads"
# Sync scrolls/seals to Internet Archive
sync_to_ia "/data/scrolls" "fold-stack-scrolls"
# Sync Trilium backups to Web3.storage
sync_to_web3 "/data/trilium-backup" "fold-stack-trilium"
# Sync all directories to NAS
sync_to_nas "/data/scrolls" "fold-stack/scrolls"
sync_to_nas "/data/hedgedoc/uploads" "fold-stack/hedgedoc_uploads"
sync_to_nas "/data/ghost" "fold-stack/ghost"
sync_to_nas "/data/trilium" "fold-stack/trilium"
echo "Synchronization completed at $(date)"
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
set -e
echo "Starting rclone watch at $(date)"
# Directories to monitor
WATCH_DIRS="/data/scrolls /data/hedgedoc/uploads /data/ghost /data/trilium /data/trilium-backup"
# Initial sync on startup
/rclone-sync.sh
# Monitor directories for changes using inotifywait
echo "Monitoring directories for changes: $WATCH_DIRS"
/usr/bin/inotifywait -m $WATCH_DIRS -e modify -e create -e delete -e move -r |
while read -r directory events filename; do
echo "Detected change in $directory: $events $filename"
# Debounce: Wait 10 seconds to avoid multiple syncs for rapid changes
sleep 10
# Check if there are more events in the queue; if so, skip to avoid redundant syncs
if [ -z "$(/usr/bin/inotifywait -t 1 $WATCH_DIRS -e modify -e create -e delete -e move -r 2>/dev/null)" ]; then
echo "No more events detected, triggering sync at $(date)"
/rclone-sync.sh
else
echo "More events detected, skipping sync to debounce"
fi
done
echo "rclone watch stopped at $(date)"