Scheduled upload doesn't work from .bat file, win 2012 R2

Advertisement

yoku
Guest

Scheduled upload doesn't work from .bat file, win 2012 R2

Hi,

I have a .bat file with something like this:
@echo off
title Backup
SET logfile=C:\backup\Backup.log
 
echo ------------------------START Backup------------------------ >>%logfile% 2>&1
date /T  >>%logfile% 2>&1
time /T >>%logfile% 2>&1
 
if not exist "C:\Backup" mkdir C:\Backup
if not exist "C:\Backup\Archive" mkdir C:\Backup\Archive
echo -----copy----- >>%logfile% 2>&1
 
xcopy C:\\design\* C:\Backup\design\* /y /s
 
del /F /Q c:\AIC_Backup\Archive\*
 
"c:\backup\7-Zip\7z" a -r C:\Backup\Archive\Backup.7z C:\AIC_Backup\*
echo errorlevel: %ERRORLEVEL%
 
IF %ERRORLEVEL% == 0 GOTO OK
 
echo.
echo !!! ERROR There was a problem during zip procedure. ErrorLevel = %ERRORLEVEL%
echo.
GOTO end
 
:OK
echo ------------------------Archive Done------------------------ >>%logfile% 2>&1
 
echo ------------------------Start Uploading------------------------ >>%logfile% 2>&1
 
"c:\Program Files (x86)\WinSCP\winscp.com" /command "open sftp://root:root@server/" "put c:\Backup\Archive\Backup.7z /data1/backup/Backup.7z" "exit" "/log=Backup.log" "/loglevel=1"   
echo ------------------------Uploading Done------------------------ >>%logfile% 2>&1
 
:end
echo ------------------------Backup Done------------------------ >>%logfile% 2>&1
Working cool, if I run it manually, but unfortunately scheduled task doesn't upload it. Archive is done, just WinSCP upload is not working. There is no log records for uploading (only if I run it by hand). Can anybody help me? Thanks

Reply with quote

Advertisement

yoku
Guest

+ info:
If I try to run it from Task Scheduler, it runs but doesn't execute the winscp command. So it's working only if I double click on backup.bat.

Reply with quote

yoku
Guest

Hi Martin,

Thanks a lot, it's a good starting point. At first, config was read out from registry. Now I exported settings to .ini and moved into WinSCP folder.
. 2017-05-09 13:01:22.093 Configuration: c:\backup\WinSCP\WinSCP.ini
Also I exported pub hostkey with ssh-keyXXXgen -l -f /etc/ssh/ssh_host_rsa_key.pub and put it in the command:
"c:\backup\WinSCP\winscp.com" /command  "open sftp://root:root@server/ -hostkey=""ssh-rsa 2048 1g:f3:e2:bc:35:ff:19:2f:a6:6f:d1:82:e6:af:1c:9c""" "put c:\AIC_Backup\Archive\AIC_Backup.7z /data1/backup/AIC/AIC_Backup.7z" "exit" "/log=AICBackup.log" "/loglevel=1"
The shown key is the same as the GUI shows before first connect e.g: https://winscp.net/eng/data/media/screenshots/unknown_hostkey.png

But scheduled task still doesn't work :( No log records for winscp command, just from .bat (>>%logfile% 2>&1). In attachment I uploaded the log when I run it with clicking on backup.bat. Do you see maybe anything wrong in it?

I'll keep checking for the issue. Thanks

Reply with quote

Guest

Also I tried to add -certificate switch in open command, but always got an error msg like Unknown switch 'certificate'.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,449
Location:
Prague, Czechia

Did you try using an absolute path to the log file? /log=C:\backup\AICBackup.log

Also redirect even WinSCP output to your batch file log:
"c:\backup\WinSCP\winscp.com" /command  ... >>%logfile% 2>&1

Reply with quote

Advertisement

You can post new topics in this forum