synchronize of file currently in use - how to solve?

Advertisement

miloskrizan
Donor
Joined:
Posts:
7
Location:
Slovakia

synchronize of file currently in use - how to solve?

Hello Martin,

I have another issue I was fighting with and I am not sure what is the best solution, if there exists any switch or what command to use? I synchronize MS Outlook folder on daily basis and Outlook is obviously opened whole day. The error is that when the scheduled script run Outlook is opened at the moment and winscp cannot copy file to server. Of course the same issue with all files that are opened by some windows process/service.

What do you suggest?

here is the error line:
System Error. Code:33 The process cannot access the file because another process has locked a portion of the file

Here is my script:
option batch off
option confirm off
open sftp://user:pwd@domain -rawsettings SendBuf=0 SSHsimple=0 PingType=1 PingIntervalSecs=10 Compression=1 -timeout=10 -hostkey="ssh-rsa 3072 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
option transfer binary
option exclude "[~]*"
synchronize remote -mirror "c:\Users\user1\AppData\Local\Microsoft\Outlook\" "/cecho/Cloud"
Close

I am attaching log also.

Reply with quote

Advertisement

miloskrizan
Donor
Joined:
Posts:
7
Location:
Slovakia

any recommendations?

So what you recommend till there will be any existing solution?

1. Keepuptodate? - backup after outlook has been closed?
https://winscp.net/eng/docs/scriptcommand_keepuptodate

or
2. force close current App and do backup?

or

3. any shadow copy? - means create Temp folder and copy currently used file there and then backup?

Is there an option to ignore the error (maybe with on error resume next) and then any error handler - if there is a Error code 33 then add the Path and file that cannot be synch into some list and then use this list in keepuptodate?

How you solved it? How, anybody of you reading this post, are handling this problem?
If there is any existing bypass solution I will be thankful.

Thank you
Milos

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
31,808
Location:
Prague, Czechia

Re: any recommendations?

Well, I have recommended, excluding the file from the synchronization.

You can also try using option batch continue. Though it has a quite broad effect.
https://winscp.net/eng/docs/scriptcommand_option#batch

Another option is to convert your script to PowerShell code with use of WinSCP .NET assembly.
It has more flexibility in handling errors with its Session.QueryReceived event:
https://winscp.net/eng/docs/library_session_queryreceived
You can choose to ignore any errors you like using QueryReceivedEventArgs.Continue.
https://winscp.net/eng/docs/library_queryreceivedeventargs

For some example, see:
https://winscp.net/eng/docs/library_example_recursive_download_custom_error_handling

Reply with quote

miloskrizan
Donor
Joined:
Posts:
7
Location:
Slovakia

possible solution

If anybody is still searching for simple solution here is a code.
The code is resuming on errors and batch continue ... means if there is a file currently in use - will be simply ignored. But then later I used the keepuptodate command to track the same folder and then sync after file currently in use will be closed.

It simply works perfect.

option batch continue
on error resume next
option transfer binary
open sftp://user:pwd@domain -hostkey="ssh-rsa 3072....."
synchronize remote -delete "c:\Users\test\AppData\Local\Microsoft\Outlook\" "/outlook_backup"
keepuptodate -delete "c:\Users\test\AppData\Local\Microsoft\Outlook\" "/outlook_backup"
Close
exit

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
31,808
Location:
Prague, Czechia

Re: possible solution

Thanks for sharing your solution.

Though note that there's no on error resume next – that's Visual Basic command.
It would abort WinSCP normally, as it's not a recognized command. But it's ignored, because of preceding option batch continue.

Reply with quote

Advertisement

You can post new topics in this forum