How to backup a directory based on modification timestamp of files inside?

What is the problem you are having with rclone?

Not a problem, but something I can't figure out how to do.

I run a simple script to perform an rclone copy to Google Drive of a RAMDisk each day, giving it the naming format of YYYYMMDD_name. This works great, but is a bit wasteful because I don't actually change something on the disk every single day.

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.

Run the command 'rclone version' and share the full output of the command.

- os/kernel: 10.0.19045.3448 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.17.8
- go/linking: dynamic
- go/tags: cmount

Are you on the latest version of rclone? You can validate by checking the version listed here: Rclone downloads
-->
no

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

I don't know

Please run 'rclone config redacted' and share the full output. If you get command not found, please make sure to update rclone.

Usage:
  rclone config [flags]
  rclone config [command]

Available Commands:
  create      Create a new remote with name, type and options.
  delete      Delete an existing remote.
  disconnect  Disconnects user from remote
  dump        Dump the config file as JSON.
  file        Show path of configuration file in use.
  password    Update password in an existing remote.
  paths       Show paths used for configuration, cache, temp etc.
  providers   List in JSON format all the providers and options.
  reconnect   Re-authenticates user with remote.
  show        Print (decrypted) config file, or the config for a single remote.
  touch       Ensure configuration file exists.
  update      Update options in an existing remote.
  userinfo    Prints info about logged in user of remote.

Flags:
  -h, --help   help for config

Additional help topics:
  rclone config edit       Enter an interactive configuration session.

Use "rclone [command] --help" for more information about a command.
Use "rclone help flags" for to see the global flags.
Use "rclone help backends" for a list of supported services.
Command config needs 0 arguments maximum: you provided 1 non flag arguments: ["redacted"]

A log from the command that you were trying to run with the -vv flag

N/A

You need proper backup with content deduplication IMO. Rclone can not do this. I suggest you use right tool for this job and try software like restic or similar.

I'm not asking Rclone to do this, I'm asking how to check the modification dates as described, in the .bat file I'm running. Surely that must be possible? Doesn't seem like all that esoteric a task, just not something I know how to do myself. Maybe I'm just asking in the wrong place.

Yes.. This is not really rclone issue but "how to use my OS". Maybe some Windows forums can be more useful here.

1 Like

Thanks, trying again in a Windows forum. Although Restic looks very interesting too, so thanks for that pointer!

1 Like

can you explain the script, as a set of steps, that could then be re-written as code.

I managed to get to a working solution with the help of chatGPT. Here is the Windows forum post I made before I solved it myself.

Here is the code:

@echo off
setlocal enabledelayedexpansion
set datepath=20%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
set y=%DATE:~10,4%
set m=%DATE:~4,2%

REM Define source folder, destination folder, and list of extensions to ignore
set "sourceFolder=V:\test"
set "destinationFolder=V:\test_dest"
set "ignoreExtensions=.log;.data;.scid;.dly"  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 (

rclone copy V:\SC-Development SCBackups:20%y%/%m%/%datepath%_Dev_local -P --copy-links --exclude "/$RECYCLE.BIN/" --exclude "System Volume Information/**" --exclude *.scid --exclude *.dly --exclude *.depth --exclude *.log --exclude *.simulated.data --exclude "/*/Data/MarketDepthData/**" --exclude "/.*/**"

    echo Folder copied to destination.
) else (
    echo No newer files found in the source folder.
)

endlocal

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.