I am in the process of deploying SharePoint (MOSS 2007) , and a found a requirement to automatically sync the new service up with old network storage locations for the time being. My requirements were quite simple:
- Copy initial contents of “Shared Documents” and “Private Documents” for a the HR department.
- automatically update the contents of these folders if there were new files or folders in them.
In old school days, I would just use a scheduled task for a batch file with xcopy utilizing the “/d” command, which “Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.” But because my SharePoint server name was not the same as the UNC for the WebDAV folder, which looks something like \\intranet\DAvWWWRoot\ , it was just not happening. I tried to use the URL, but nothing was showing up in SharePoint… so I had to look for a new solution. what I found was DavCopy a free command line utility.
At first, I didn’t think this would solve my problem, because I wanted new files only to sync, and didn’t see anything based on the date or “new” files in the “/?” usage report. That was until I saw the “archive” crap… yea, remember archive crap? if a file is modified, copied, or anything of the such, the “archive” attribute is set. then when the file is copied to a backup device, the archive bit is unset, as it has been “archived”. with davcopy, because I want my incremental backup to still backup the files, I used the “/a” switch.
so now my little sync-moss.bat files looks like this:
ECHO “Syncing HR”
cd /d “e:\shared work areas\HR\HR Only”
davcopy * “http://intranet/HR/HR Only” /fd /o /e /s /a /xf “thumbs.db” /xd “.”
cd /d “e:\shared work areas\HR\Shared Documents\”
davcopy * “http://intranet/HR/Shared Documents” /fd /o /e /s /a /xf “thumbs.db” /xd “.”
for a list of those command line parameters, better read the davcopy.exe documentation.
and to schedule it every day at 5:30pm, we will use schtasks:
schtasks /create /tn “sync-moss” /tr c:\sync-moss.bat /sc daily /st 17:30:00 /ru domain\user /rp password
yep… I think that will work… we’ll see. at least the batch file works, as seen in the output:
I am probably sure there is a better way to do this… but this is just a temporary solution.