Link to home
Start Free TrialLog in
Avatar of cadcollin
cadcollinFlag for United States of America

asked on

How to create SyncToy folder pairs via command line?

We're utilizing SyncToy 2.1 to backup directories on users' desktop PCs to a server.  We then back up that server onto tape.

The drive on the server that housed these backups recently failed and had to be replaced.  And unfortunately, when we replaced the drive, SyncToy only pulled files from the desktops that had been updated since the last SyncToy synchronization.  We need to re-pull everything.

We weren't able to find a way to re-perform an initial sync for our existing folder pairs, so we just wiped them out with the intention of recreating them.  We're looking to script the recreation of the pairs rather than create them manually in the SyncToy GUI though.  (There's more than 100 pairs to be created, and each one takes a while using the GUI.  Plus, we'd like to have the script available, just in case something like this happens again.)

SyncToy's documentation notes:

The parameters associated with SyncToy.exe are described below:

-d(left=, right=, name=,operation=Synchronize|Echo|Contribute, [check=yes|no], excluded=,included=) Creates a new folder pair with the specified options:
left - mandatory, provide absolute path for left folder
right - mandatory, provide absolute path for right folder
name - mandatory, provide name of folder pair
operation - mandatory, specifiy action type for this folder pair
check - optional, specify whether file contents should be checked for file matching, default is no
excluded - optional, specifies exclude filter for files, defaults to none
included - optional, specifies include filter for files, defaults to all
-u Delete one or more folder pairs, no user data will be deleted
-? Display Help

Here's the syntax we're using (where [machinename] is the name of a PC on our network that the user account on the server running SyncToy has permissions over):
"C:\Program Files\SyncToy 2.1\SyncToy.exe" -d(left="\\[machinename]\c$\users", right="h:\backups\[machinename]", name="[machinename]", operation="contribute", excluded="*.iso;*.mp3;*.wma;*.wmv;*.tmp;*.mdmp;*.hdmp;*.vhd")

When executing this command, synctoy.exe starts, then immediately throws the following error:
Failed to construct a valid folder pair from the string: (left=\\pc1\c$\users,.  Invalid folder pair - one endpoint is contained within the other.  Please select a different folder to continue.

We thought that the error might stem from using a UNC path in the left folder (even though we're able to create folder pairs using UNC paths in the SyncToy GUI), but we weren't even able to get a local to local folder pair set up via command line.  When we tried, we got the same error.

Any help would be greatly appreciated.  If you need any additional information, please don't hesitate to ask!
Avatar of Jian An Lim
Jian An Lim
Flag of Australia image

SyncToy -d(left=c:\temp,right=c:\temp2,name=MyDoc,operation="contribute")

I have no problem to run this on my local PC

did you run this cmd as administrator ??
Avatar of cadcollin

ASKER

Our syntax appears nearly identical, with the exception of what we chose to encapsulate.  We put quotes around the left and right folder paths, since the paths often contain spaces.  We've also tried with and without quotes around the folder pair's name and the extension exception list.

And yes, the command is being issued as a user with rights over the local server and the remote desktop.

We've tried executing this command on a Windows 7 (x86) box and a Windows Server 2008 Standard (x86) SP2 box; both had the same result.  What OS did you run the command on?  And also, could you please confirm that after running the command, when you pull up the SyncToy GUI, you're able to see the folder pair "MyDoc" in the left frame of the application's workspace?
i run this on my local PC (windows 7 x86) with only local admin rights.
i try to run as user and as admin, both works.

I confirm when i pull up the GUI, i able to see the pair on the left frame.




=====
by default, your local admin would not have access to left=\\pc1\c$\ as c$ is administrator only rights. you probably need to create a share yourself call \\pc1\cdrive\ and test it.


The command isn't being executed as a local administrator.  Per my last update: "... the command is being issued as a user with rights over the local server and the remote desktop."

We're able to browse the left folder's contents using Windows Explorer as the same user the command's being run as.
i believe we need to sort out why your left drive have issue

left=\\pc1\c$\users,.  Invalid folder pair - one endpoint is contained within the other.



can you do this as below?

md c:\temp
SyncToy -d(left="\\pc1\c$\users",right="\\pc1\c$\temp",name=MyDoc,operation="contribute")


What are you using to replace [machinename] with something sensible?

Or was that just an edit for EE to hide the real name?

How is this command being launched?

Via a BATCH script?

Via an exec() / system() style command from another language which would incorporate using %COMSPEC%?



I've just installed 2.0 and ...

SyncToy.exe -d(left="\\bv-cluster-file\Department Data\In-House IT\Documents\Camelot",right="\\bv-dev-svr-4\c$\Camelot",name="Camelot",operation=Contribute)

produces no errors and nothing in the GUI when I reload it.

Going to try the later release (2.1 - http://www.microsoft.com/downloads/details.aspx?FamilyID=c26efa36-98e0-4ee9-a7c5-98d0592d8c52&DisplayLang=en)


Aha!

I get an error.

Different to the one you get (See image).

But the difference is important.

I've not created the right hand folder.

Creating it now ...

And the command works.

So. You are trying to sync from a folder that doesn't exit.


SyncToyError.png
Are you sure \\[machinename]\c$\users is real?

It is NOT the same things as C:\

C:\users is a directory on a LOCAL harddrive (normally)

\\[machinename\c$\users is a folder on a hidden share.

The share may be limited rights or not defined.
And the completed pairing is now visible in SyncToy's gui.
@limjianan: I'll give it a shot once the existing sync finishes.  (I ended up rebuilding the sync pair manually this time around, but still need to find a solution to this problem in case we have to rebuild it again.)

@RQuadling: The "[machinename]" was just an edit for Expert's Exchange.  It's replaced with the name of a desktop PC on our domain.  Right now, we're executing the command directly from the command line. When we can get it working, we'll write a batch script to execute the command for every desktop on our domain.
The directories may be hidden, but they definitely exist... and the user executing the command definitely has access to the directories.  (That's what's weird about the situation.)  We get the same error that you did when we intentionally provide a path to a folder (or folders) that don't exist.
Can you get it working manually?

If so, where is the info for this .... looking ....

C:\Documents and Settings\RichardQ\Local Settings\Application Data\Microsoft\SyncToy

Hmmm. Mostly binary files. Structure could be reversed.

Trying ...

SyncToy.exe -d(left="\\richardquadling\c$\Batch",right="\\bv-dev-svr-4\c$\Camelot",name="batch",operation=Contribute)

and that worked.

OK.

Try using ProcMon tuned to watch for path contains SyncToy.

What events happen around the failure?
I apologize for the delay.  I didn't get a chance to work on this over the weekend, and we're already running another round of syncing; it'll be a day or two before I get another chance to try anything else.  I'll update the request ASAP!
I initially cross-posted this question on MIcrosoft's SyncToy forums and got the following response a few days after receiving a response on Expert's Exchange:
Hi,
Please remove any blank in your create folder pairs string. Then have a try. Then it will work well. I have had a try.
This is by design, but the error message gave some misleading to you, sorry for this. Will file a bug to correct the misleading message issue.
Thanks,
Ping

http://social.microsoft.com/Forums/en-US/synctoy/thread/b562c0d9-9c6e-445c-b2ad-bcdc806af1b0 


Unfortunately, since the source folders are Windows XP's "Documents and Settings" directories, the only way to resolve this issue (that I can think of) is to share out each Documents and Settings folder from each machine.
No.

Use the 8.3 file name.

DOCUME~1

But ...

SyncToy.exe -d(left="\\richardquadling\c$\Documents and Settings\RichardQ\temp\TeamViewer\Version4",right="\\bv-dev-svr-4\c$\Camelot",name="batch",operation=Contribute)

worked.


SyncToySpaces.png
@RQuadling:  Good call!  For whatever reason, I was only under the impression that that would only work locally.  I tested the 8.3 path in Windows Explorer and it worked, so I'll give it a shot in the SyncToy script and let you know if it worked or not!
@RQuadling:  The syntax included in your last doesn't include any parameters for file-type exclusion, which we'll need, but since it worked for you, I decided to copy and paste your syntax.  The only thing I changed was the paths of the left and right folders.  The command is being executed as a user with administrative rights locally, and over the remote source.

C:\Program Files\SyncToy 2.1>SyncToy.exe -d(left="\\9ts8lf1\c$\documents and settings\",right=
"h:\test",name="batch",operation=Contribute)

C:\Program Files\SyncToy 2.1>SyncToy.exe -d(left="\\9ts8lf1\c$\docume~1\",right=
"h:\test",name="batch",operation=Contribute)

Neither one of these commands generated a pop-uperror, but neither one of them successfully created a Sync Pair either.  The SyncToy GUI appears briefly, but then disappears immediately.  Neither the left or the right folder has the SyncToy generated "SyncToy_*.dat" file that's created upon pair creation.  When I check the SyncToy log, I find the following:
SYNC: 09/01/2010 09:02:10:572: Starting SyncToy, version 2.1.0.0, built 10/19/2009 2:58:16 AM.
SYNC: 09/01/2010 09:02:10:666: *** Failed to construct a valid folder pair from the string: (left=\\9ts8lf1\c$\docume~1",right=h:\test,name=batch,operation=Contribute). Exception handled:Illegal characters in path.

Notice the issued command has properly encapsulated paths; the error doesn't.

This is totally bizarre.  Any other recommendations?
If you have dropped the spaces, then drop the quotes around the names.

No trailing \ either .
So ...

SyncToy.exe -d(left=\\9ts8lf1\c$\docume~1,right=h:\test,name=batch,operation=Contribute)

Running that exact command yielded the following error on my Windows 7 machine and on our Windows Server 2008 Standard (x86) SP2 machine.  The SyncToyCmd.exe still works, but now SyncToy.exe can't even be called, without parameters, from Windows Explorer.  Every time, whether launched from the Command Line or from Windows Explorer, it results in the attached error messages.

I'm not sure what was different about this than the others, obviously SyncToy interpreted it differently.  (And, from what I can tell, every variation we've stated ought to have worked.  We've varied our syntax to accommodate your suggestions, but it looks like every variation ought to have worked.)

Re-installing SyncToy ought to resolve this issue, but I'm a little concerned that doing so might removed the existing folder pairs.  Since I've already manually recreated all of the pairs on the server recently (which took quite a while), and I've got the same problem on my desktop, I'm going to try re-installing on my desktop first.

Which version of Windows are you running?  limjianan said he was able to get this working under Windows 7 (x86), but I still get the feeling that an OS conflict may be at the root of this problem.
Untitled.gif
OK. I'm stuck. I can't think of anything else.

The syntax is working for me and it should be for you. My desktop is still in the dark ages. WinXPSP3x86.

I'll have a play with on my dev servers (2008 ... something ... not exactly sure - it runs 64 SQL Enterprise  on one and IIS7 on other).

As SyncToy requires .NET (and different versions thereof), make sure you are uptodate on this.

The fact that you get the "Not a win32 app" error is truly bizarre.

Used the MSI to repair SyncToy.  Thankfully, the Folder Pairs from before the "SyncToy.exe is not a valid Win32 application" issue were preserved, and the GUI is working again... but we still aren't able to create folder pairs via cmd.  Let me know how the tests on your dev servers go!
Will do. In about 10 hours time.
Dev1, Dev2 and Dev4are VM's of Windows 2003 Enterprise Ed. x86
Dev3 and Test1 are VM's of Windows 2008 Enterprise SP2 x86

Loaded SyncToy 2.1 on Test1.

Ran Windows Update to check any .NET upgrades.

Noticed that there is no Documents and Settings on C: on my 2008 server. Instead, it is C:\Users


synctoy -d(left=\\bv-test-svr-1\c$\users\datama~1,right=n:\Copied,name=Server,operation=Contribute,excluded=*.ini)


Can you make sure that there is only 1 SyncToy.exe installed?
SyncToyNoErrors.png
I'm up to date on .NET updates on my Windows 7 x86 machine, but there's a couple of updates available on our production Windows Server 2008 Standard (x86) SP2 server.  Since they may require a post-install reboot, they'll have to wait till after hours.

Since my server and the desktop have been experiencing similar problems, I don't know if the updates will fix anything... but it certainly can't hurt to try.

Both machines are only running one copy of SyncToy.
I'm pretty stuck now. I see everything working as expected.

If you are still getting issues, then running a tool like ProcMon and watching the SyncToy process to see what and where it travels could be useful in finding the issue you are having.

ASKER CERTIFIED SOLUTION
Avatar of cadcollin
cadcollin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'd really recommend using ProcMon to watch what SyncToy is trying to do. It will really help. Honestly.