%DATE% and RClone

Hi,

tl;dr: %date% variable does not seem to work when configured in a Scheduled Task with rclone

I've encountered a strange issue. I am running version 1.51.0 on 64-bit Microsoft Windows Server 2016 (10.0.14393 Build 14393).

When running the following command with cmd
rclone copy D:\WindowsImageBackup\ gdrive:/Backup/WIB/%date% --log-file D:\BackupRepository\rclone.%date:~9,1%.log --log-level INFO

I get the following result
Log file: rclone.6.log
Google Drive folder name: 2020-02-16

However, if I set it up as a Scheduled Task, run by the SYSTEM account, the log file and Google Drive folder gets the following names:
Log file: rclone.%date
Google Drive folder name: %date%

I've done some searching and found this link that I thought explained my issue, however when I tried re-creating this issue with a scheduled task running the following command

mkdir C:%date%

it worked perfectly.

I've tried searching the web and this forum for solutions but haven't found anything. Don't know if it's because % is escaped by the search engines.

Am I doing something wrong here? Any work-around or solution letting me use the current date to name copied folders would be greatly appreciated.

hello and weclome to the forum.

when i need time and date in a windows batch file, i use this

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 day=00%%g
  set hours=00%%h
  set minutes=00%%i
  set month=00%%j
  set seconds=00%%k
  set year=%%l
  )
set month=%month:~-2%
set day=%day:~-2%
set hh=%hours:~-2%
set mm=%minutes:~-2%
set ss=%seconds:~-2%
set thedatetime=%year%%month%%day%%hh%%mm%%s%
echo %thedatetime%

which will give you 202002161032

rclone copy D:\WindowsImageBackup\ gdrive:/Backup/WIB/%thedatetime% --log-file=D:\BackupRepository\rclone.%thedatetime%.log --log-level=INFO

Thank you! Yes, I saw this mentioned in some of the posts I encountered. Have you tried this with a Scheduled Task? It might be possible to have this run before the rclone command but I am not sure.

My only thought is that it would be nice to not have to depend on all the extra code. It feels like it should be possible to use the variables already available, but perhaps I am wrong.

If possible I would like to have everything run within a single life of code so I don't have to resort to creating batch scripts and saving them on disk and so on.

the code i shared will work in task scheduler.

if your path and filenames have the space character in them, you need to quote them like so:

rclone copy "D:\WindowsImageBackup" "gdrive:/Backup/WIB/%date%" --log-file "D:\BackupRepository\rclone.%date:~9,1%.log" --log-level INFO

I am not sure I quite understand how I would implement that. Do you place your script in a separate action (as seen in the image below)?

I still would like to know why rclone (or Windows) won't let me use the %date% variable when it works in batch and all my other Scheduled Tasks that don't use rclone.

task_actions

did you try the command i shared with you?

as i mentioned, it might be that you have the space character in your rclone command.
if you have a space, with rclone, you must use quotes.

create a text file named rclonecopy.cmd in the same folder as rclone.exe
and paste this text into it

when testing scripts:

  1. the --log-level should be DEBUG
  2. use the flag --dry-run
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 day=00%%g
  set hours=00%%h
  set minutes=00%%i
  set month=00%%j
  set seconds=00%%k
  set year=%%l
  )
set month=%month:~-2%
set day=%day:~-2%
set hh=%hours:~-2%
set mm=%minutes:~-2%
set ss=%seconds:~-2%
set thedatetime=%year%%month%%day%%hh%%mm%%s%
c:\rlcone\rclone.exe copy D:\WindowsImageBackup\ gdrive:/Backup/WIB/%thedatetime% --log-file=D:\BackupRepository\rclone.%thedatetime%.log --log-level=DEBUG --dry-run

and run rclonecopy.cmd from task scheduler.

Ah, okay. That's what I thought you meant but I wasn't sure. I will try that and get back to you.

When it comes to space characters in my rclone command I don't have any, but I tried escaping all paths with "" anyway however this made no difference. The log file still gets named rclone.%date no matter what I do.

your rclone command uses %date% as in gdrive:/Backup/WIB/%date%

and if you run echo %date% from the command line or script you get
Sun 02/16/2020 which does have a space character in it.

my advice is get the rclone working first on the command line or script.
only after that, automate it with task scheduler,

running a command as SYSTEM user can create new problems you might not understand or anticipate.

my advice is get the rclone working first on the command line or script.
only after that, automate it with task scheduler,

That's what I did if you read my initial post. It works when I run it in CMD on the server (with any account). It's only when I put it in the Task Scheduler that it does not work with rclone. However other commands work with %date% in the Task Scheduler, only not with rclone.

echo %date% does not result in Sun 02/16/2020 for me. It results in 2020-02-16. I've verified that it's the same for all accounts (including SYSTEM with psexec) on the server. Even if this wouldn't be the case I've escaped my paths but still get the same error.

Running the bat script with your function did output the correct file names, but as I mentioned earlier before it would be nice with a solution that does not require me to save multiple scripts to disk (since this is not the only job I've configured).

run your command with -log-level=DEBUG and post the log.

2020/02/16 21:38:19 DEBUG : rclone: Version "v1.51.0" starting with parameters ["C:\\Rclone\\rclone.exe" "copy" "D:/WindowsImageBackup/" "gdrive:/Backup/WIB/%date%" "--backup-dir" "gdrive:/Recycle/%date%" "--bwlimit" "62M" "--immutable" "--drive-impersonate" "account@test.com" "--log-file" "D:/WindowsImageBackup/rclone.daily.log" "--log-level" "DEBUG"]
2020/02/16 21:38:19 DEBUG : Using config file from "C:\\ProgramData\\RClone\\Config\\rclone.conf"
2020/02/16 21:38:19 INFO  : Starting bandwidth limiter at 62MBytes/s
2020/02/16 21:38:24 INFO  : Google drive root 'Backup/WIB/%date%': Waiting for checks to finish
2020/02/16 21:38:24 INFO  : Google drive root 'Backup/WIB/%date%': Waiting for transfers to finish
2020/02/16 21:38:26 DEBUG : MediaId: MD5 = bbed36603fac77b6630acb7a126b430d OK
2020/02/16 21:38:26 INFO  : MediaId: Copied (new)
2020/02/16 21:38:27 DEBUG : Catalog/BackupGlobalCatalog: MD5 = 5f5e067c59144305b2cea46463dbd53d OK
2020/02/16 21:38:27 INFO  : Catalog/BackupGlobalCatalog: Copied (new)
2020/02/16 21:38:28 DEBUG : Logs/Backup_Error-14-02-2020_15-12-06.log: MD5 = 51c13df7b9939670cae025ea0a227808 OK
2020/02/16 21:38:28 INFO  : Logs/Backup_Error-14-02-2020_15-12-06.log: Copied (new)
2020/02/16 21:38:28 DEBUG : Catalog/GlobalCatalog: MD5 = a574ab56c00733beedb2d1e86b353624 OK
2020/02/16 21:38:28 INFO  : Catalog/GlobalCatalog: Copied (new)
2020/02/16 21:38:29 DEBUG : Logs/Backup_Error-16-02-2020_01-00-34.log: MD5 = 51c13df7b9939670cae025ea0a227808 OK
2020/02/16 21:38:29 INFO  : Logs/Backup_Error-16-02-2020_01-00-34.log: Copied (new)
2020/02/16 21:38:29 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_AdditionalFilesc3b9f3c7-5e52-4d5e-8b20-19adc95a34c7.xml: MD5 = e3685aed126047e9dd81bcf7ac7b14c7 OK
2020/02/16 21:38:29 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_AdditionalFilesc3b9f3c7-5e52-4d5e-8b20-19adc95a34c7.xml: Copied (new)
2020/02/16 21:38:30 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_RegistryExcludes.xml: MD5 = 5ca3c05fc25b900878206f22a077dc86 OK
2020/02/16 21:38:30 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_RegistryExcludes.xml: Copied (new)
2020/02/16 21:38:30 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Components.xml: MD5 = f520306655c957a9219e1be6e572890c OK
2020/02/16 21:38:30 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Components.xml: Copied (new)
2020/02/16 21:38:31 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer0bada1de-01a9-4625-8278-69e735f39dd2.xml: MD5 = 743f9a65e9644804d5bd8438f307ac2e OK
2020/02/16 21:38:31 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer0bada1de-01a9-4625-8278-69e735f39dd2.xml: Copied (new)
2020/02/16 21:38:31 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer4dc3bdd4-ab48-4d07-adb0-3bee2926fd7f.xml: MD5 = 5f3bb719497af7a1fb42b43558f9adaa OK
2020/02/16 21:38:31 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer4dc3bdd4-ab48-4d07-adb0-3bee2926fd7f.xml: Copied (new)
2020/02/16 21:38:31 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer4969d978-be47-48b0-b100-f328f07ac1e0.xml: MD5 = 9fcab7470fee2c26732d10b15166a912 OK
2020/02/16 21:38:31 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer4969d978-be47-48b0-b100-f328f07ac1e0.xml: Copied (new)
2020/02/16 21:38:31 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer542da469-d3e1-473c-9f4f-7847f01fc64f.xml: MD5 = 3ea172eb2a0591da27c703e60dd5d5e0 OK
2020/02/16 21:38:31 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer542da469-d3e1-473c-9f4f-7847f01fc64f.xml: Copied (new)
2020/02/16 21:38:32 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer66841cd4-6ded-4f4b-8f17-fd23f8ddc3de.xml: MD5 = 4f0c424eeb115657f86c4ae6fb5a905b OK
2020/02/16 21:38:32 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer66841cd4-6ded-4f4b-8f17-fd23f8ddc3de.xml: Copied (new)
2020/02/16 21:38:32 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer75dfb225-e2e4-4d39-9ac9-ffaff65ddf06.xml: MD5 = 8210ed04fc8737a820cb34a385ae2679 OK
2020/02/16 21:38:32 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writer75dfb225-e2e4-4d39-9ac9-ffaff65ddf06.xml: Copied (new)
2020/02/16 21:38:33 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writerafbab4a2-367d-4d15-a586-71dbb18f8485.xml: MD5 = b434989f3511caa2e32297d6ad2513b5 OK
2020/02/16 21:38:33 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writerafbab4a2-367d-4d15-a586-71dbb18f8485.xml: Copied (new)
2020/02/16 21:38:33 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writera6ad56c2-b509-4e6c-bb19-49d8f43532f0.xml: MD5 = dec75165f416b3e7281c2d9a52c340e9 OK
2020/02/16 21:38:33 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writera6ad56c2-b509-4e6c-bb19-49d8f43532f0.xml: Copied (new)
2020/02/16 21:38:34 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writerbe000cbe-11fe-4426-9c58-531aa6355fc4.xml: MD5 = 5634c9012f93b0ab42e43c47c0a173ba OK
2020/02/16 21:38:34 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writerbe000cbe-11fe-4426-9c58-531aa6355fc4.xml: Copied (new)
2020/02/16 21:38:34 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writerd61d61c8-d73a-4eee-8cdd-f6f9786b7124.xml: MD5 = 73a296992e9bc7414fee5b3c0933634c OK
2020/02/16 21:38:34 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writerd61d61c8-d73a-4eee-8cdd-f6f9786b7124.xml: Copied (new)
2020/02/16 21:38:34 DEBUG : Backup 2020-02-16 010034/BackupSpecs.xml: MD5 = 7891d2ed9ae35a830e5e3480725b45a5 OK
2020/02/16 21:38:34 INFO  : Backup 2020-02-16 010034/BackupSpecs.xml: Copied (new)
2020/02/16 21:38:34 DEBUG : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writere8132975-6f93-4464-a53e-1050253ae220.xml: MD5 = a208639f808680f223663cae7815f73e OK
2020/02/16 21:38:34 INFO  : Backup 2020-02-16 010034/5be65265-64d9-4048-a6ae-db28c5a72d1c_Writere8132975-6f93-4464-a53e-1050253ae220.xml: Copied (new)
2020/02/16 21:38:34 INFO  : 
Transferred:   	    3.448M / 3.448 MBytes, 100%, 332.214 kBytes/s, ETA 0s
Transferred:           20 / 20, 100%
Elapsed time:        10.6s

2020/02/16 21:38:34 DEBUG : 17 go routines active
2020/02/16 21:38:34 DEBUG : rclone: Version "v1.51.0" finishing with parameters ["C:\\Rclone\\rclone.exe" "copy" "D:/WindowsImageBackup/" "gdrive:/Backup/WIB/%date%" "--backup-dir" "gdrive:/Backup/WIB/%date%" "--bwlimit" "62M" "--immutable" "--drive-impersonate" "account@test.com" "--log-file" "D:/WindowsImageBackup/rclone.daily.log" "--log-level" "DEBUG"]

Thank you for all your help so far!

i have an idea.

try putting cmd /c before your command.

cmd /c rclone.exe copy "D:\WindowsImageBackup" "gdrive:/Backup/WIB/%date%" --log-file "D:\BackupRepository\rclone.%date:~9,1%.log" --log-level INFO

That did it! Thank you! I can't believe I did not try that earlier. Thanks again!

like this

1 Like

excellent,

me too, i cannot believe i did not suggest that earlier. :wink:

well, i would not do that, i would let windows decide given the context.
as there are muliple cmd.exe.

%windir%\system32\cmd.exe
and
%windir%\SysWOW64\cmd.exe

Good call! I will withdraw my addition!

on windows, there are two versions of rclone.exe
32bit and 64bit.

you might like this