After hours backup ending in morning

Advertisement

AgedFast
Joined:
Posts:
2
Location:
Australia

After hours backup ending in morning

Good weekend everyone,

I'm trying to automate large backups during my off-peak bandwidth.
What I've managed so far is from reading the WinSCP documents.
Currently I'm using the following batch with windows scheduler.

set TMPPATH=@@@@@@


"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\writable\path\to\log\WinSCP.log" /ini=nul ^
  /command ^
       "open sftp://$$$$$$:######@%%%%%%/ -hostkey=""******=""" ^
       "put ""d:/dump/*"" ""%TMPPATH%""" ^

for /r "%TMPPATH%" %%f in ("*.*") do move "%%f" "@@@@@@"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)

exit /b %WINSCP_RESULT%

Then later I run
taskkill /f /im "WinSCP.exe"

However this batch isn't using parallel connections and following a search on WinSCP it appears as though its too complicated of a task to achieve through batch, this is when I found the following.

https://winscp.net/eng/docs/library_example_parallel_transfers#upload_csharp

My question is being that C# is a more in depth language would there be a way to add some line that if possible start and end at set time and leave running in background or at minimum end at set time so I can still see the following.
$ "Uploaded {0} files, totaling {1:N0} bytes"

Thanks for all support my only coding experience is HTML, thankfully C# looks like a clean enough language that I know at least the lines I need to change in the example.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: After hours backup ending in morning

At the beginning of the while (true) block, add:

        while (true) 
        {
            if (DateTime.Now.Hour >= 6)
            {
                Console.WriteLine("It's 6 o'clock, aborting");
                break;
            }

Reply with quote

AgedFast
Joined:
Posts:
2
Location:
Australia

Thank you sir, you are an absolute legend.

Am I correct in assuming if I wanted it to run 6pm to 6am, all I would have to do is have >=12?

Edit - Never mind I've messed around and seem to have it working, thanks for everything.

Reply with quote

martin
Site Admin
martin avatar

AgedFast wrote:

Am I correct in assuming if I wanted it to run 6pm to 6am, all I would have to do is have >=12?
The number is not a duration, but real clock (note DateTime.Now). So if you want to stop at 6:00 (am), keep my code as it is.

Reply with quote

Advertisement

You can post new topics in this forum