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.
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%
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.
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.
create a text file named rclonecopy.cmd in the same folder as rclone.exe
and paste this text into it
when testing scripts:
the --log-level should be DEBUG
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
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.
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).