Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Last active February 7, 2026 07:06
Show Gist options
  • Select an option

  • Save yeiichi/ba8323346a56270894d1722942ca5e29 to your computer and use it in GitHub Desktop.

Select an option

Save yeiichi/ba8323346a56270894d1722942ca5e29 to your computer and use it in GitHub Desktop.
Selective JSON/JSONL sync with preserved directory structure
# --- Configuration ---
SOURCE_DIR := /path/to/src/
DEST_HOST := host_name_in_ssh_config
DEST_PATH := /path/to/dest
# --- Flags ---
# -a: Archive (preserve permissions/times)
# -v: Verbose (see what's happening)
# -z: Compress (faster over network)
# -R: Relative (ensures directory structure is preserved)/Don't use -> redundant in this context
# Using standard flags; --files-from handles relative paths automatically
RSYNC_FLAGS := -avz --from0 --files-from=-
.PHONY: sync dry-run check-conn help
# Default target
all: help
help: ## Show this help message
@echo "Description: Selective JSON/JSONL sync with preserved directory structure"
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@printf " \033[36m%-15s\033[0m %s\n" "help" "Show this help message"
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| grep -v '^help:' \
| awk 'BEGIN {FS = ":.*?## "}; \
{printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
sync: ## Starting sync to the destination host (preserving structure)
@echo "Starting sync to $(DEST_HOST)..."
cd $(SOURCE_DIR) && find . -type f \( -name "*.json" -o -name "*.jsonl" \) -print0 | \
rsync $(RSYNC_FLAGS) . $(DEST_HOST):$(DEST_PATH)
@echo "Sync complete."
dry-run: ## Performing dry-run (simulation)
@echo "Performing dry-run (simulation)..."
cd $(SOURCE_DIR) && find . -type f \( -name "*.json" -o -name "*.jsonl" \) -print0 | \
rsync -n $(RSYNC_FLAGS) . $(DEST_HOST):$(DEST_PATH)
@echo "Dry-run finished. Review the list above."
check-conn: ## Quick check if the remote is reachable
@ssh -q $(DEST_HOST) exit && echo "$(DEST_HOST) is reachable." || \
echo "Cannot reach $(DEST_HOST)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment