Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Aquileoxxi

Re: synchronize of file currently in use - how to solve?

martin wrote:

There's currently no simple solution.

All you can do currently, is to exclude the files that tend to be locked from the synchronization.

There are two requests that may solve this:
Issue 969 – Option to exclude files opened for writing
Issue 1676 – Use Volume Shadow Copy
You can vote for them in the tracker.


Hi, I've just register and donate to vote for the shadow copy support. It will transform this great program in the perfect mirror/backup solution over SFTP.

Thanks for your work.
martin

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.
miloskrizan

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
martin

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:
Recursively download directory tree with custom error handling
miloskrizan

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
  2. force close current app and do backup?
  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
miloskrizan

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.