diff --git a/21-Server Reference/homelab/stacks/n8n/JW_Backup/JW Backup.md b/21-Server Reference/homelab/stacks/n8n/JW_Backup/JW Backup.md index 6b9fea4..a0d8fde 100644 --- a/21-Server Reference/homelab/stacks/n8n/JW_Backup/JW Backup.md +++ b/21-Server Reference/homelab/stacks/n8n/JW_Backup/JW Backup.md @@ -114,9 +114,53 @@ Syncs JW Library backups (`.jwlibrary`) across multiple Android devices via a ce --- +## Adding a New Device + +All task files for a new device are in `stacks/n8n/JW_Backup/` — the `(1)` suffixed files are the phone templates. + +### 1. Install Apps +- **Tasker** (Play Store) +- **AutoInput** (Play Store — same source as Tasker) +- **GitSync** (Play Store) +- **JW Library** (Play Store) + +### 2. Configure GitSync +1. Open GitSync → add a new repository +2. Clone URL: `https://gitea.bunny-wyvern.ts.net/artanis/Inanis_Vault` +3. Local path: `/storage/emulated/0/vault` +4. Credentials: Gitea username + password (see `credentials.gpg`) +5. Do an initial sync to confirm the repo clones correctly — `JW_Backups/` folder should appear at `/storage/emulated/0/vault/JW_Backups/` + +### 3. Import Tasker Tasks +Import the following files from `stacks/n8n/JW_Backup/` into Tasker (long-press task list → Import): +- `JWL_Backup_To_Git.tsk(1).xml` +- `Git_Sync.tsk(1).xml` +- `JWL_Merge.tsk(1).xml` +- `JWL_Restore_From_Git.tsk(1).xml` + +### 4. Update Device Name +In `JWL_Merge`, find the HTTP POST body and update the device identifier: +```json +{"device": "YOUR-DEVICE-NAME-HERE"} +``` +This is only used for logging — set it to something recognizable (e.g., `Samsung-Phone-A55`). + +### 5. Grant Permissions +- **Tasker:** grant accessibility service, notification access, and storage permissions +- **AutoInput:** grant accessibility service +- **GitSync:** grant storage permissions +- **JW Library:** grant storage permissions + +### 6. Set Up Tasker Profile +Create a **Time** profile to trigger `JWL_Backup_To_Git` at the device's scheduled time (e.g., 04:35 for phone). The task chain handles everything from there: backup → git push → n8n merge → git pull → restore. + +### 7. Test +Run `JWL_Backup_To_Git` manually and verify each step completes. Check n8n Executions tab to confirm the webhook fired and the SSH script succeeded. + +--- + ## Open Items - [ ] **Screen-off handling** — verify AutoInput sequence works when device screen is off (may need `Turn On Display` + `Dismiss Keyguard` actions before AutoInput steps) - [ ] **Phone e2e test** — tablet verified, phone not yet tested end-to-end - [ ] **Stagger validation** — confirm 5-min gap between phone push (04:35) and tablet n8n trigger (04:45) is sufficient on slow networks -- [ ] **`.gitignore`** — verify temp `.tmp` files from JW Library export are ignored in the vault repo diff --git a/21-Server Reference/homelab/stacks/n8n/JW_Backup/JW_Backup_Sync_Engine.sh b/21-Server Reference/homelab/stacks/n8n/JW_Backup/JW_Backup_Sync_Engine.sh new file mode 100644 index 0000000..79c4a0b --- /dev/null +++ b/21-Server Reference/homelab/stacks/n8n/JW_Backup/JW_Backup_Sync_Engine.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# --- CONFIG --- +TARGET_DIR="/home/artanis/Inanis_Vault/JW_Backups" +MASTER_NAME="master.jwlibrary" +LIB_SOURCE="/usr/local/lib/libjwlCore.so" + +# 1. Environment & Pathing +export PATH=$PATH:/usr/local/bin:/usr/bin:/bin +export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH +cd "$TARGET_DIR" || exit 1 + +# 2. Update Repo +git pull origin main + +# 3. Rename messy filenames (Spaces/Brackets) +shopt -s nullglob +counter=1 +for f in *.jwlibrary; do + if [[ "$f" != "$MASTER_NAME" && "$f" != incoming_* ]]; then + mv "$f" "incoming_$counter.jwlibrary" + ((counter++)) + fi +done +shopt -u nullglob + +# 4. Identify standardized files +INCOMING_FILES=$(ls incoming_*.jwlibrary 2>/dev/null) + +if [ -z "$INCOMING_FILES" ]; then + echo "No new device backups found. Exiting." + exit 0 +fi + +# 5. Satisfy Binary & Merge +ln -sf "$LIB_SOURCE" ./libjwlCore.so +FILE_COUNT=$(echo "$MASTER_NAME $INCOMING_FILES" | wc -w) + +if [ -f "$MASTER_NAME" ] && [ "$FILE_COUNT" -gt 1 ]; then + jwlFusion -o:"master_tmp" "$MASTER_NAME" $INCOMING_FILES +elif [ ! -f "$MASTER_NAME" ] && [ $(echo "$INCOMING_FILES" | wc -w) -gt 1 ]; then + jwlFusion -o:"master_tmp" $INCOMING_FILES +else + # Recovery: If only 1 file exists and no master, promote it + cp $INCOMING_FILES "$MASTER_NAME" + echo "Promoted single file to master." +fi + +# 6. Cleanup & Finalize +rm -f ./libjwlCore.so incoming_*.jwlibrary + +if [ -f "master_tmp.jwlibrary" ]; then + mv "master_tmp.jwlibrary" "$MASTER_NAME" +fi + +# 7. Git Push +if git status --porcelain | grep -q .; then + git add -A + git commit -m "Automated Sync: $(date +'%Y-%m-%d %H:%M')" + git push origin main + echo "Sync successful. Master updated and pushed." +else + echo "No changes detected in master." +fi diff --git a/JW_Backups/UserdataBackup_2026-03-31_Samsung_SM-X800.jwlibrary b/JW_Backups/UserdataBackup_2026-03-31_Samsung_SM-X800.jwlibrary deleted file mode 100644 index 2e16d7f..0000000 Binary files a/JW_Backups/UserdataBackup_2026-03-31_Samsung_SM-X800.jwlibrary and /dev/null differ