Web Deploy: dirPath Provider

This blog post is part of a series of posts on the web deploy providers.

Disclaimer:
All the gists have been formatted for readability.
That means that if you plan to use them in a command-prompt you need to re-format them accordingly.


Introduction

This is what MSDN says about the dirPath provider:

The dirPath provider synchronizes directory content.

The dirPath provider works a lot like the filePath provider with the exception that it operates on folders/directories instead of files. You can use the provider as a source or a destination argument depending if you want to sync to or from a directory.

  • The dirPath provider takes an argument that is the full path of a file system directory (e.g., C:\inetpub\wwwroot).
  • UNC paths and mapped network drives are supported.
  • Environment variables like %windir% are supported, but wildcard characters are not.
  • If the path contains spaces, the path must be enclosed in double quotation marks.

Syntax

The dirPath provider takes an argument that’s one of the following:

  1. a directory path
  2. alternatively an UNC path

Special Settings or Considerations

  • Files on the destination that do not exist on the source will be deleted by default.
    • -enableRule:DoNotDeleteRule
      If you want to modify that default behavior, enabling the web deploy rule “Do Not Delete Content” is your friend. An example of this rule in action can be found here.
  • By default, the provider doesn’t synchronize ACLs, attributes, or ownership information. This is because the permissions are copied as security identifiers (SIDs) and may not work uniformly on all computers.
    • ,includeAcls=true
      If you need to synchronize both permissions and content, you can use the optional includeAcls provider setting to include ACLs in the sync operation.
      note: ACLs will be copied as SIDs. For the permissions to be set correctly, you must use domain accounts or have local accounts with matching SIDs on both the source and destination computers.

Examples

I’m going to use the dirPath provider both as a source argument and as a destination argument to “move” the content of a shared network resource, an upload-folder, from a production environment to a testing environment.

Background

This should be a pretty common situation where you have a live production site and as part of you deployment process you need to use the content from the production environment in your testing environment. One such “operation” might be to copy manually uploaded content (images, files, etc.)

image

There’s a web site (http://www.example.com) that has a production and a testing environment (both on the same set of servers ,wfe1 and wfe2).
note: Not preferred for a “real” application but since this a demo setup it’s ok.

The two web servers involved are load balanced and have the same set of web applications (even though the image only shows the details of wfe1, wfe2 is exactly the same).
Web server A (wfe1) hosts two network resources/shares that the sites, prod and test, are using as virtual folders (/upload).

What we hope to accomplish is:

  1. to synchronize the contents of the production site upload folder (1) to a zip file (prod.example.com.upload.zip)
  2. restore the contents of that zip file into the test site upload folder (2).

image

note: this might very well be apart of some deployment/build process and then you might have to use web deploy in a remote scenario which is described in great detail here and here.

1. dirPath as source argument

I actually know, and have access to, the physical path that the network share (1) corresponds to so I’m using that a source argument on line 3.
I could of course have used the UNC path but since I’m demoing the dirPath provider…well, I´d like to cover all the options.

As destination (line 4) I’m using the package provider since that allows me to put the output of the dirPath provider in a zip file.
note: there are some limitations on file sizes and number of files to take into consideration using the package provider though. If that’s an issue, please consider using the archiveDir provider instead.

2. dirPath as destination argument

So now when I have a “backup” of the production site upload folder I can use that as source argument (line 3) and sync that to the test site upload folder (line 4).
note: This time I’m actually using the UNC path (which I could have used in the previous example too).

3. Do Not Delete Rule

Web Deploy configuration rules can be used with the sync operation to modify the behavior.
One such rule is the ‘Do Not Delete Content’ rule, which we’ll have a look at now.

Problem

Imagine that I have executed the “backup/restore” command as describes above. Now the testers start working with the testing environment, thus adding new manual content.
The command runs nightly as part of build process. The problem is, if you remember:

files on the destination that do not exist on the source will be deleted by default

When the testers return the next day all the manual content they added yesterday is gone. The developers start looking at the logs and soon find entries like this one:

image

Apparently all the files that they added to the test site upload folder has been deleted by the web deploy sync operation.
And then the developers remember that they can prevent that behavior by modifying the operation slightly, like this:

line 5 shows how to enable the rule.

…and now the content that the testers will upload to the test site will remain even after a nightly sync operation from production.

note: enabling this rule also works when syncing to a package provider etc.

, , ,

  1. Practical Web Deploy Provider Examples « Johan Leino

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: