#!/bin/bash # Watch for new checkpoints and backup immediately # Runs every 15 minutes, checks if new checkpoint appeared CKPT_DIR="/data0/checkpoints/flux_lora" LAST_FILE="/data1/logs/.last_backup_ckpt" HF_USER="memoryai" LOG="/data1/logs/checkpoint_backup.log" while true; do sleep 900 # 15 minutes # Find latest checkpoint LATEST=$(ls -td "$CKPT_DIR"/checkpoint-* "$CKPT_DIR"/final 2>/dev/null | head -1) if [ -z "$LATEST" ]; then continue fi # Check if already backed up LAST_BACKED=$(cat "$LAST_FILE" 2>/dev/null || echo "") if [ "$LATEST" = "$LAST_BACKED" ]; then continue fi # New checkpoint found - backup! echo "[$(date)] Backing up: $LATEST" >> "$LOG" python3 -c " from huggingface_hub import upload_folder import os latest = '$LATEST' name = os.path.basename(latest) repo_id = '$HF_USER/4k-image-model-checkpoints' print(f'Uploading {name} to {repo_id}...') upload_folder( folder_path=latest, repo_id=repo_id, path_in_repo=f'flux_lora/{name}', repo_type='model', ) print('Done!') " >> "$LOG" 2>&1 echo "$LATEST" > "$LAST_FILE" echo "[$(date)] Backup complete: $LATEST" >> "$LOG" done