How to Create Website Backup to SkyDrive Using Powershell

how to create website backup

How to Create Website Backup 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 strategy to create website backup 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:

[sourcecode language=”powershell”]
$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.

Antonio Chagoury

Hi, I'm Antonio, Founder and CEO of Maxiom Technology (formerly Inspector IT).I'm a technology executive and entrepreneur who has achieved consistent success in driving growth, generating revenue, and enhancing value in domestic and international markets through technology product innovations.

  • 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.