#!/bin/bash # This script uses rclone to copy new and updated files from the mounted folder to Google Drive, # preserving the directory structure, and then deletes local files that are over 3 days old. # Check that DRIVE_FOLDER_ID environment variable is set. if [ -z "$DRIVE_FOLDER_ID" ]; then echo "DRIVE_FOLDER_ID environment variable is not set. Exiting." exit 1 fi # The local folder to be synced (mapped from the host) LOCAL_DIR="/shared/transcriptor/clips" # The remote name must match the one defined in your rclone config (e.g., "gdrive") REMOTE_NAME="gdrive" # Continuous loop to perform the sync every 60 seconds. while true; do echo "Starting sync: $(date)" # The rclone copy command will: # - Copy new or updated files (with --update, only files with newer timestamps are overwritten) # - Preserve the folder structure by default # - Use the provided Google Drive folder ID via --drive-root-folder-id rclone copy "$LOCAL_DIR" "${REMOTE_NAME}:" \ --drive-root-folder-id="${DRIVE_FOLDER_ID}" \ --update \ --verbose echo "Sync complete: $(date)" echo "Deleting local files older than 3 days: $(date)" # Delete files in LOCAL_DIR (and its subdirectories) that are over 3 days old find "$LOCAL_DIR" -type f -mtime +3 -delete sleep 600 done