Last active
November 4, 2024 10:24
-
-
Save tamld/2b428426562ef57b483e283da30f195c to your computer and use it in GitHub Desktop.
rclone sync drive online
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal | |
| :: Check if required tools are installed | |
| dir "C:\Program Files\7-Zip\7z.exe" /b >nul || ( | |
| curl -fS -o %temp%\7z.msi https://www.7-zip.org/a/7z2408-x64.msi | |
| msiexec /i %temp%\7z.msi /quiet | |
| ) | |
| :: Check if rclone is installed | |
| where rclone > nul | |
| if %ERRORLEVEL% neq 0 ( | |
| curl -fS -o rclone.zip https://downloads.rclone.org/v1.68.1/rclone-v1.68.1-windows-amd64.zip | |
| "C:\Program Files\7-Zip\7z.exe" x -y rclone.zip | |
| ren rclone-v1.68.1-windows-amd64 rclone | |
| move rclone "C:\Program Files\rclone" | |
| ) | |
| :: Check if rclone is in PATH | |
| echo %PATH% | findstr /C:"C:\Program Files\rclone" >nul | |
| if %ERRORLEVEL% neq 0 ( | |
| :: Add rclone to PATH permanently | |
| setx PATH "%PATH%;C:\Program Files\rclone" | |
| ) | |
| :: Add rclone to temporary PATH for this session | |
| set PATH=%PATH%;"C:\Program Files\rclone" | |
| :: Get the current date in YYYY-MM-DD format using PowerShell | |
| for /f %%i in ('powershell -command "Get-Date -Format ''yyyy-MM-dd''"') do set DATE=%%i | |
| :: Configuration variables | |
| set "PRIMARY_BACKUP_DRIVE=" | |
| set "SECONDARY_BACKUP_DRIVE=" | |
| set LOG_FILE=%temp%\rclone_sync_log_%DATE%.txt | |
| if not defined PRIMARY_BACKUP_DRIVE ( | |
| echo PRIMARY_BACKUP_DRIVE is not set. Exiting... | |
| exit /b 1 | |
| ) | |
| if not defined SECONDARY_BACKUP_DRIVE ( | |
| echo SECONDARY_BACKUP_DRIVE is not set. Exiting... | |
| exit /b 1 | |
| ) | |
| :: Log start time | |
| echo Starting sync on %DATE% >> "%LOG_FILE%" | |
| echo Syncing from %PRIMARY_BACKUP_DRIVE% to %SECONDARY_BACKUP_DRIVE%... >> "%LOG_FILE%" | |
| :: Rclone sync command | |
| rclone sync "%PRIMARY_BACKUP_DRIVE%" "%SECONDARY_BACKUP_DRIVE%" --drive-server-side-across-configs --checksum --progress --fast-list --transfers=20 --checkers=20 --delete-after --min-age 1m >> "%LOG_FILE%" 2>&1 | |
| :: Log completion | |
| echo Sync completed on %DATE% >> "%LOG_FILE%" | |
| echo Check the log file at %LOG_FILE% for details. | |
| :: Clean up temporary files | |
| del /q rclone.zip | |
| endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment