commit 6d4950d5dfcffe79ad866d6d0ce4b8f953f38794 Author: t0is Date: Mon Mar 3 16:31:21 2025 +0100 init commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..66d7a1c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:latest + +# Install rclone and bash +RUN apk update && apk add --no-cache rclone bash + +WORKDIR /app + +# Copy the entrypoint script into the container +COPY entrypoint.sh . + + +# Make sure the script is executable +RUN chmod +x entrypoint.sh + +CMD ["./entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a0f4954 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + drive-sync: + build: . + environment: + # Set your target Google Drive folder ID here. + - DRIVE_FOLDER_ID=1HKPydId23FmOWaT5dzBnDt0ooIMwzDLS + volumes: + # Map your local folder to the container's /shared/transcriptor/clips + - /shared/transcriptor/clips:/shared/transcriptor/clips + # Mount your rclone configuration file containing the Google Drive remote details. + - ./rclone.conf:/root/.config/rclone/rclone.conf:ro \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..8110b7c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,35 @@ +#!/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-folder-id + rclone copy "$LOCAL_DIR" "${REMOTE_NAME}:" \ + --drive-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 \ No newline at end of file diff --git a/rclone.conf b/rclone.conf new file mode 100644 index 0000000..7bc9300 --- /dev/null +++ b/rclone.conf @@ -0,0 +1,7 @@ +[gdrive] +type = drive +client_id = 830644885820-9792hiic15cmglcbjg5nl210im3m7m6r.apps.googleusercontent.com +client_secret = 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 +scope = drive +token = {"access_token":"ya29.a0AeXRPp5InawrsmE5ZZxff0Z4nYmQZJggOxhkHmT_YMe4tpwDaVMhYaYdKI4C5nWkvaMSPCTxQCawoo6-6ZnEMqS9MApZUyKlSbt2GS_3QEtwZtmDX5nlwTBhDuXpAWBdKmSV_BxY_-GU921RjyPRnca6A3mv9Zcuojdvk6PraCgYKAesSARMSFQHGX2Miwm4Sp1WgzBVkMEmzqTDUZw0175","token_type":"Bearer","refresh_token":"1//09jwQv3qxecZtCgYIARAAGAkSNwF-L9Ir1gOqVz6-Xf9odzOxDgQdUQfD-_N2e_0WOYKKSSUUsIr9k5jey9d_EZrxNveLK7u-YQE","expiry":"2025-03-03T17:24:59.513329+01:00"} +team_drive =