Sunday, 8 January 2012

Backup IIS Server Package to Amazon S3 using C#

I recently updated our backup process at work to store our backups on Amazon S3. I wanted a simple process to that would backup the IIS server configuration and website files that can be easily be restored on a new server in case of a major problem. Luckily Microsoft have release MSDeploy which can be installed using the Web Platform Installer.

Within IIS you can backup everything to a server package by opening the context menu selecting depoy, then “Export Server Package”. This will create the server package containing the IIS configuration along with all the sites and their files. This is all good however it is still a manual process that is likely to be forgotten about after a while. Likely there are a series of libraries we can use to automate this process.

The namespace Microsoft.Web.Deployment provide the functionality we need to backup IIS, this is provided by Microsoft.Web.Deployment.dll. To backup the server we need to use the DeploymentManager to create an object use to create the package, we can then use this to “sync” the server setting to a package.

After we have backed up the site package we need to upload it to Amazon S3. To do this we can use the AWSSDK .NET library. The library can be installed via NuGet by searching for “AWS SDK”. This will install the required assemblies.

We can use the AWS SDK to upload our server package zip to S3 using the TransferUtilityUploadRequest to create our request to use with the TransferUtility to upload our file.

When this is all tied together we have an app that will backup and upload the server package to S3.

No comments:

Post a Comment