2

I am looking for a tool that can synchronize folders by generating a script that can then be run from a command line, and the script generated does not require the tool to be installed to work.

Like it can compare directories, then script the copy/delete operations, and allow you to save the script and run the script from any computer.

Also I am working windows world. I have looked a quite a few synchronization tools, but none I have seen so far will generate scripts.

Any advice would be much appreciated!

EDIT: The situation I have is we have several websites with the same core codebase. When this core codebase is updated new new files, changed files removed files.

I would like to create a script that can be packaged with the new and changed files that will copy them, and delete the files that are no longer needed. Sort of a really simple update program. Currently I do this with winmerge, I put the changed and new files in an archive, and I copy the names of the missing items and write the script by hand.

Since the package will only contain the new and changed files the script has to remember which files need to be deleted since when we run the script it should not have to connect back to the original source to figure our the deleted files. Currently I write the script by hand, and it is tedious. I was just hoping that some file sync tool had the ability to package an update complete with changed files and deletes, seems like that would be a nice feature.

3 Answers 3

1

Just so I understand, you've got a single source, with multiple identical destinations. You're making changes at your source (creations, updates, deletions) and want to easily make your destinations identical to the source with all those changes?

Then this is what you need:

robocopy "\\sourcepath\folder" "\\destinationpath1\folder" /MIR /NFL /NDL
robocopy "\\sourcepath\folder" "\\destinationpath2\folder" /MIR /NFL /NDL
robocopy "\\sourcepath\folder" "\\destinationpath3\folder" /MIR /NFL /NDL

The /MIR switch will make your destinations identical to your source, including your deletion actions. The /NFL and /NDL stop robocopy from outputting the files and folders that are changing. This produces a simple output that lists number and size of files changed. If you'd like a log of what was synced, exclude these switches.

However, if you have any customizations set up on your destinations, those will be removed.

Update following Chris's first comment on this answer

I don't think what you're looking for is natively possible with robocopy, or other command line tools.

However, here's some psuedo-code that would do what you're looking for I think. The actual script is beyond my skills without a lot of research, but this is the workflow you'd need:

$codebase = "\\codebase\"
$comparesource = "\\destination to compare to codebase\"
$packagesource = "\\where you store update package files\"
$finaldestination = "\\path you're actually trying to update\"

robocopy $codebase $comparesource /MIR /LOG:c:\log.txt /FP /NS /NJH /NJS /L
  • /FP = Full path listed in the log file
  • /NS = No size listed in the log file
  • /NJH and /NJS = no job header and summary in the log file
  • /L = Just list what would happen, don't actually make any changes

This will give you a file containing output like this:

*EXTRA File          C:\file1.txt
       New File             c:\file2.xls
       Newer                c:\file3.txt

Then this would need to run:


If line contains "newer" or "New File" rest of line enters array $copyfilename
If line contains "*EXTRA" rest of line enters array $deletefilename
\\This would only work for a flat structure; subfolders complicate things and you'd need to grab the file name and subfolder name instead. 

for each in $copyfilename {
robocopy $codebase\$copyfilename $packagesource\$copyfilename /e

Append above line to $packagesource\updatepackage.bat, replacing $codebase with $packagesource and $packagesource with $finaldestination
}
for each in $deletefilename {
append "del $finaldestination\$deletefilename" to $packagesource\updatepackage.bat
}

At the end of this, you'd have a folder (your $packagesource) that contains new and changed files, as well as a batch file that has copy commands for those new and changed files, and delete commands for the removed files.

2
  • Something like that, but instead of doing robocopy each time it would be like you do robocopy, but instead of copy the differences from source to the compare directory, it would copy the updates to a seperate directory and record the copy operations, along with the delete operations that it would have made. That way I can just send out the update package to some offsite location without access to the original source, and they can just run it and it will be all selfcontained, so basically the script is a bunch of copy/delete statements, just I hate having to spend time writing them. May 19, 2011 at 17:52
  • Thank you so much for your well thought out answer. I think that would work. It looks like writing a script is will be necessary. I have looked at a ton of merge and sync packages I have not seen one that will automatically package an update. It is too bad I think creating this script would probably be a more complex workflow than I have right now :( May 20, 2011 at 14:38
4

Um, robocopy saves the configuration of a copy job to a file that you can recall later with a parameter. Is that sufficient by your definition of script? It was a download in XP/2003, and installed by default in Vista/7/2008 variants. There is also RichCopy, a GUI overlay to the aforementioned robocopy. It might even output the job file so you can run robocopy in a script later.

4
  • 1
    +1 for robocopy. The /MIR option of robocopy will synchronize a source and target directory, and you can save the command for later use, or just use the output of the command to compare what has changed.
    – Jeff Miles
    May 19, 2011 at 16:56
  • Sounds promising. I was not aware that robocopy would delete missing files. Although I am not sure it will work for what I want to use it for. I will update my question with a more specific example of what I want to do. May 19, 2011 at 17:03
  • Ok, I just read your edited question. Robocopy's functionality in this regard is easily modified depending on whether or not your a "mirror" (the /MIR parameter). If you do mirror, deleting files from the reference location means the next sync will delete the same file on the target location. That is not what you want. If you do not mirror, you will be fine, as deleted files could or could not be left depending on the job you set up. Also, robocopy is very specific about how it determines what you copy over or delete, based on changes in date/time, filesize, etc. Check the docs.
    – songei2f
    May 20, 2011 at 10:48
  • And just to be frank, there are other creative ways people do what you suggest without robocopy and version control systems like git or svn. In fact I was reading it last night, Google git web server or something like that to get a better idea. That way changes are transparent and easily noticed through diffs and such. I am a sys-admin, so moving files around did not have production implications; it was to make sure I had copies of files people would never really see again, so not a website.
    – songei2f
    May 20, 2011 at 10:50
1

Try out the Microsoft Synctoy. It doesn't generate scripts, but it is scriptable. If you want a custom script, you'll probably have to write your own. These guys were awesome when I was first starting to learn Windows scripting.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .