How to put timestamps in --backup-dir that has date AND time in filenmae?

What is the problem you are having with rclone?

I want to have timestamps with time and date in filenames in archiving backup-dir. It will make it easier for me tell which modified files I need. But I have looked everywhere and there is no command to help. I found this command but it treats timestamps as separate third argument. What is correct command. Please note I am using Windows which probably has different command.

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

rclone v1.59.1

  • os/version: Microsoft Windows 11 Pro 21H2 (64 bit)
  • os/kernel: 10.0.22000.856 (x86_64)
  • os/type: windows
  • os/arch: amd64
  • go/version: go1.18.5
  • go/linking: static
  • go/tags: cmount

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

None. Local

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

rclone sync "C:\Users\me\M S\sync\A" --backup-dir "C:\Users\me\M S\sync\C" "C:\Users\me\M S\sync\B" --suffix `date +%Y%m%d_%H%M%S` --suffix-keep-extension --create-empty-src-dirs -P

The rclone config contents with secrets removed.

Config file is empty since I use local.

A log from the command with the -vv flag

2022/08/31 14:28:12 DEBUG : rclone: Version "v1.59.1" starting with parameters ["rclone" "sync" "C:\\Users\\me\\M S\\sync\\A" "--backup-dir" "C:\\Users\\me\\M S\\sync\\C" "C:\\Users\\me\\M S\\sync\\B" "--suffix" "`date" "+%Y%m%d_%H%M%S`" "--suffix-keep-extension" "--create-empty-src-dirs" "-P" "-vv"]
Usage:
  rclone sync source:path dest:path [flags]

Flags:
      --create-empty-src-dirs   Create empty source dirs on destination after sync
  -h, --help                    help for sync

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 sync needs 2 arguments maximum: you provided 3 non flag arguments: ["C:\\me\\M S\\sync\\A" "C:\\Users\\me\\M S\\sync\\B" "+%Y%m%d_%H%M%S`"]

Hi, welcome to the forum!

That example you found, date +%Y%m%d_%H%M%S, is for Linux shells and will not work on Windows (unless using bash from git/msys, wsl or something).

On Windows there are different alternatives. See for example this: %DATE% and RClone

If you need more help then give us a bit more details: Do you want to run it from Command Prompt or PowerShell, manual as interactive command or from a scheduled task, etc. And if Command Prompt then locale date/time format is relevant, so share the output of echo %date% %time%.

echo %date% %time% works and gives me my date and time. So I added %date% %time% after --suffix but now rclone gives error calling my date and time as third argument.

I ran: 
rclone sync "C:\Users\hmnga_3dimcd4\M S\sync\A" "C:\Users\hmnga_3dimcd4\M S\sync\B" --backup-dir "C:\Users\hmnga_3dimcd4\M S\sync\C" --suffix %date% %time% --suffix-keep-extension --create-empty-src-dirs -P
Gives this error:
Command sync needs 2 arguments maximum: you provided 3 non flag arguments: ["C:\\Users\\hmnga_3dimcd4\\M S\\sync\\A" "C:\\Users\\hmnga_3dimcd4\\M S\\sync\\B" "16:34:23.99"]
So I added " " around it:
rclone sync "C:\Users\hmnga_3dimcd4\M S\sync\A" "C:\Users\hmnga_3dimcd4\M S\sync\B" --backup-dir "C:\Users\hmnga_3dimcd4\M S\sync\C" --suffix "%date% %time%" --suffix-keep-extension --create-empty-src-dirs -P

Ok so now it works after adding " " BUT weirdly. This creates a folder the same name as modified file in backup dir and inside is another folder called 08 (month?) and only inside that is the modified file. But the file's name is completely renamed to date and time. This is messed up. I just want the files to have time and date in addition to their own name and follow same directories as the source/remote directory.

Please share the actual output of echo %date% %time% .

31/08/2022 16:50:44.04

Thanks.

Now you need to transform that into the format you want - and at least get rid of the / characters which are treated as path separators.

It all depends how you want it, that's why I asked for more input so we could take it step by step.

The following will give you the sortable yyyyMMddHHmmss format, in your example "20220831165044"

%date:~6,4%%date:~3,2%%date:~0,2%%time:~0,2%%time:~3,2%%time:~6,2%

Wow that actually worked, thanks! But can I change format even more so that it looks like this 2022-08-31 16:50:44 instead of just 20220831165044 which is so hard to read? I do not know how to code it to change it to my liking so maybe you can help?

Try this:

echo %date:~6,4%-%date:~3,2%-%date:~0,2% %time:~0,8%

Note that since it now contains a space you need to quote it when passing as command-line argument:

--suffix "%date:~6,4%-%date:~3,2%-%date:~0,2% %time:~0,8%"

Is that how you want it? If not just ask again. Or, if you want to experiment yourself, you can find some background here:

https://ss64.com/nt/syntax-substring.html
https://ss64.com/nt/syntax-replace.html

hello and welcome to the forum,

might try

For /f "tokens=2-4 delims=/ "  %%a in ('date /t') do (set thedate=%%c%%a%%b)
For /f "tokens=1-2 delims=/: " %%a in ("%TIME%") do (if %%a LSS 10 (set thetime=0%%a%%b) else (set thetime=%%a%%b))
set currentdatatime=%thedate%.%thetime%
echo %currentdatatime%

and that will output
20220831.0833

1 Like

if you want more flexibility try

for /f "usebackq skip=1 tokens=1-6" %%g in (`wmic Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year ^| findstr /r /v "^$"`) do (
  set year=%%l
  set month=00%%j
  set day=00%%g
  set hours=00%%h
  set minutes=00%%i
  set seconds=00%%k
  )

set year=%year:~-4%
set month=%month:~-2%
set day=%day:~-2%
set hours=%hours:~-2%
set minutes=%minutes:~-2%
set seconds=%seconds:~-2%

@set currentdatetime=%year%.%month%.%day%.%hours%.%minutes%.%seconds%
::set thedate=%year%%month%%day%
echo %currentdatetime%

and that would output
2022.08.31.08.34.09

1 Like

Yes that is what I wanted! However, one more modification: how can I make it so that it has a space in beginning? E.g testfile.txt becomes testfile2022-08-31 17 : 33 : 21.txt and I want it to be testfile 2022-08-31 17:33:21.txt . Notice how testfile and 2022 has space between them. And also make 17 : 33 : 21 not have space between them so its like 17:33:21 only. I am being picky but hey that's the best part about coding, you can change everything.

Regarding initial space, I would think it is just to include one within the quotes, but maybe you tried that?

--suffix " %date:~6,4%-%date:~3,2%-%date:~0,2% %time:~0,8%"

Regarding the space with :, I guess that is not actual spaces but it is rclone replacing the ascii : character with a so-called full-width Unicode variant to make it a legal filename. See https://rclone.org/overview/#restricted-filenames for background. You probably want to choose some other character then, e.g.:

echo %date:~6,4%-%date:~3,2%-%date:~0,2% %time:~0,2%.%time:~3,2%.%time:~6,2%
2022-08-31 14.41.55

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