Premium Support

Premium support customers may submit help-desk tickets using the form below.
Alternatively, the help-desk system can be accessed directly at support.maxiomtech.com. support@maxiomtech.com
+1 (703) 942-9420

Backup Your Website to SkyDrive Using Powershell

Backup Your Website to SkyDrive Using Powershell

In a previous post I showed you how to use a powershell script to backup your website and database. This type of backup strategy is great if or when you accidentally overwrite a file or if your site is ever compromised. In this post, I’ll take my previous post (and Powershell code snippet) one step farther by mitigating disaster recovery all at the same time by pushing the backups to the cloud as they are created.

Why backup to the cloud? (SkyDrive in our case)

Offsite Backups / Disaster Recovery

Your files are no longer only stored on your server and are distributed to any system you have sync’d with Skydrive. This also gives you the added benefit of having a local copy when you need it for setting up a development instance of the site or app.

This is not only useful for your own development teams as you can now share the same backups with your clients. Simply share the specific folder with them, and voila’, now your client has a delivered backup of their apps without any additional effort.

Easy Backup Verification

Knowing that your backups were completed and delivered successfully is also important. With SkyDrive, you can get notifications directly from the desktop client each time new files are synced and you can use the SkyDrive iPhone, Windows Mobile or Android apps to check on your backups remotely from anywhere. Neat huh?

The Code

The following code is fairly straight forward. It will:

  • Run every friday
  • Remove the previous week’s backup
  • Copy this week’s backup to the SkyDrive backup folder of your chosing
  • Determine the latest file if modified date matches today’s date
  • Accomplish some additional house keeping by creating folders for each site to keep things organized

You may, of course, change this logic and replace it with whatever works for you. These are provided only as an example of what you can do.

The code below does not handle the backup and zipping process. Please check out my previous post on zipping the backups and see how the two processes fit together:

$outputMainDir = "F:Backups"
$outputWebsDir = $outputMainDir + "Webs"
$outputDBDir = $outputMainDir + "Databases"
$skyDriveDir = "F:SkyDriveServerBackups"
#Copy Latest File to SkyDrive
if((Get-Date).DayOfWeek -eq "Friday") {
	#Remove Last Weeks Backups - Removes everything which is kinda scary.
	$skyDriveFiles = Get-ChildItem ($skyDriveDir + "*.zip") -Recurse -Attributes !D
	foreach($f in $skyDriveFiles) {
		Remove-Item $f
	Get-ChildItem ($outputDBDir + "*.zip") -Attributes !D | Where-Object {$_.CreationTime.Date.ToShortDateString() -eq (Get-Date).Date.ToShortDateString()} | ForEach-Object { Copy-Item -Path $_.FullName -Destination ($skyDriveDir + "Databases")   }
	Get-ChildItem ($outputWebsDir) -Recurse -Include "*.zip" -Attributes !D | Where-Object {$_.CreationTime.Date.ToShortDateString() -eq (Get-Date).Date.ToShortDateString()} | ForEach-Object { if(!(Test-Path -path ($skyDriveDir + "Webs" + $_.Directory.Name))) { New-Item ($skyDriveDir + "Webs" + $_.Directory.Name) -Type Directory} Copy-Item -Path $_.FullName -Destination ($skyDriveDir + "Webs" + $_.Directory.Name)   }


As I mentioned earlier, at Maxiom Technology we chose to backup to SkyDrive, but this same solution can be applied to any other cloud file sharing/sync service such as Dropbox or Google Drive.

I hope you find this useful. Please also feel free to shoot me a comment if you have any questions or suggestions — we’re always looking at way to improve our processes.

Jonathan Sheely

Sr Software Engineer at InspectorIT. Jonathan is an out of the box thinker who has over 10 years experience building and supporting web application software and infrastructure. Jon specializes in ASP.NET C#, Javascript and CSS but is willing to learn anything that gets the job done.

  • Rob
    Posted at 9:01 am, October 4, 2013

    Just wondering how you map the skydrive as a network drive? I’ve tried a few examples but none have worked.

  • mm
    Posted at 9:06 am, October 4, 2013

    Just install skydrive on that machine and setup the sync to a folder of your choosing. Then point the script to copy the archives to that folder.

    It’s not really a network share in the traditional sense.

    Hope this helps.