New
#1
Rclone backups, how to check modification timestamps?
Windows 10, I'm using RClone to backup a RAMDisk to Google Drive daily, works great but...
I would like to automatically check the source RAMDisk, and only perform the backup (of the entire disk) if any file, anywhere on the disk, has been modified more recently than the root directories (the RAMDisk is recreated from a local drive each day at boot, so the root directories always have a modified date/time of when the system last booted. Anything modified after that date/time, is clearly newer therefore everything should be backed up).
I'm not all that skilled in windows scripting so I haven't been able to figure out how to accomplish this. I specifically don't want to use sync as I want a daily backup so I can always roll back to any day (where something changed) should I need to.
Any tips on how to accomplish this?
- - - Updated - - -
"AI" to the rescue. I worked with chatGPT for about an hour and eventually got there. I had it make a simple local copying script and then just replace the final copy with my rclone command. Looks to be working nicely. Here is the final code:
- - - Updated - - -Code:@echo off setlocal enabledelayedexpansion REM Define source folder, destination folder, and list of extensions to ignore set "sourceFolder=C:\Path\To\Your\Source\Folder" set "destinationFolder=C:\Path\To\Your\Destination\Folder" set "ignoreExtensions=.txt;.log;.ini" REM Add extensions to ignore separated by semicolon REM Get the modification timestamp of the source folder (to the minute) for %%F in ("%sourceFolder%") do ( set "sourceTimestamp=%%~tF" set "sourceTimestamp=!sourceTimestamp:~0,16!" ) REM Initialize a flag to determine if a newer file is found set "newerFileFound=" REM Check files in the root directory of the source folder for %%A in ("%sourceFolder%\*.*") do ( REM Get the modification timestamp of the current file (to the minute) for %%B in ("%%A") do ( set "fileTimestamp=%%~tB" set "fileTimestamp=!fileTimestamp:~0,16!" ) REM Compare the file timestamp with the source folder timestamp if "!fileTimestamp!" neq "!sourceTimestamp!" ( set "newerFileFound=1" goto :copyFolder ) ) REM Check files in subdirectories of the source folder for /r "%sourceFolder%" %%A in (*) do ( REM Get the modification timestamp of the current file (to the minute) for %%B in ("%%A") do ( set "fileTimestamp=%%~tB" set "fileTimestamp=!fileTimestamp:~0,16!" ) REM Check if the file extension is in the list of extensions to ignore set "fileExtension=%%~xA" set "ignore=0" for %%E in (%ignoreExtensions%) do ( if /i "!fileExtension!" == "%%~E" ( set "ignore=1" ) ) REM Compare the file timestamp with the source folder timestamp if "!ignore!" neq "1" ( if "!fileTimestamp!" gtr "!sourceTimestamp!" ( set "newerFileFound=1" goto :copyFolder ) ) ) :copyFolder REM Copy the entire source folder to the destination if any newer file is found if defined newerFileFound ( robocopy "%sourceFolder%" "%destinationFolder%" /e /mir echo Folder copied to destination. ) else ( echo No newer files found in the source folder. ) endlocal
Specifically, this is designed to check all files in the source directory and perform a copy of everything in the source directory under either of 2 conditions:
1. If any file in the root of the source directory has the same file modification time as the root folder (to the minute)
2. If any file in any subdirectory has a modification time newer than the source directory (to the minute)
Perhaps this will be useful to someone else as well.