Incrementally Update a Deployed UPK Player (using XCOPY)
By Marc Santosusso-Oracle on Apr 12, 2011
Publishing incremental updates to UPK content will usually be faster than publishing to a new location due to UPK's ability to incrementally publish the content that has changed. However, it's not very common for UPK Authors to publish directly to the production environment. This means that most authors need to publish content to a staging location and then move the content from that staging location to the production location. In this post, we'll look at how we can deploy content from a staging location to a production location by incrementally updating a UPK Player package using the Windows command XCOPY. The basic principles discussed here can likely be applied to similar file copy utilities. If you do use a different utility to perform a similar task, please let us know in the comments.
First, we will identify the the staging location where content is published and the production location where content is deployed. The locations I'll use for my examples are:
Staging location: "C:\staging_location\Publishing Content\PlayerPackage"
Production location: "Z:\production_location\VirtualDirectory"
Now, we will choose the XCOPY options. Below is a list of the XCOPY options we've selected for the purposes of this example:
/D -- used without a date specified to copy only the newer files. REQUIRED
/E -- copies directories subdirectories, including empty ones. REQUIRED
/C -- copies even if errors occur. OPTIONAL
/F -- displays full file names. OPTIONAL; Useful if you log the results.
/H -- copies hidden and system files. OPTIONAL; Probably not necessary, but just in case.
/R -- overwrites read only files OPTIONAL; Probably not necessary in most situations.
/Y -- overwrite files without prompting. REQUIRED
Next, we will construct the XCOPY command using the options. In the example below I've used all of the options, but feel free to drop any of the options marked as optional above. Note the options can be consolidated with a single forward slash as I've done in my example:
xcopy "C:\staging_location\Publishing Content\PlayerPackage" "Z:\production_location\VirtualDirectory" /DECFHRY
That command will work, but instead of typing this out each time we want to update the production location with new content, we'll use a batch file. The first few lines of the batch file will establish variables to hold the locations of the source (staging_location) and destination (production_location). This allows you to easily change either location without rewriting the entire batch file.
The first variable, 'source', will need to be the PlayerPackage folder in the staging location where the UPK Authors publish the content. To establish this variable use the SET command:
set source="C:\staging_location\Publishing Content\PlayerPackage"
The next variable, 'dest' (short for destination), will need to be the folder on the web server where you want the content to be updated.
Now we will update the XCOPY command, replacing the two locations with the two variables:
xcopy %source% %dest% /DECFHRY
Your entire batch file should look something like this:
set source="C:\publisheded_location\Publishing Content\PlayerPackage"
xcopy %source% %dest% /DECFHRY
Save the file and you're finished! When you execute this batch file, it will update the files that have changed since the last time the content was published, significantly reducing the time it takes to deploy your UPK content.
- When this batch file is manually executed a DOS window will appear and display the files that are being updated. Once the XCOPY completes, the DOS window will disappear.
- You can also have this batch file launched periodically using a scheduled task. You may even want to coordinate this with a scheduled command line publishing process. For example, you could have a scheduled publishing occur on a Friday evening. Have the content reviewed on the staging server on Monday and have the xcopy batch file scheduled for a Wednesday.
- There is a way to perform this content deployment process with very little downtime. Consider maintaining two identical folders of content on the production environment. This will allow the content to be incrementally copied to the folder on the server which is not currently live. Once the copy has finished, switch the virtual directory to the updated folder.
- Consider writing the results of the batch file to a log file along with the start and end times to track your updates.
- Using this method to update content can make it easier for a System Administrator to empower a UPK Author to deploy content. The UPK Author would be given a way to start this batch file without requiring the System Administrator to be involved each and every time content needed to be updated.
- XCOPY does not offer a way to remove unused files. Consider updating your batch file to remove files from the destination which are not present in the source. Alternatively, use more advance file syncing software to keep the destination folder free of unnecessary files.(Thanks, Graham.)