Copy backup to Amazon S3 Cloud

If you install the free S3 Explorer from CloudBerry Lab, you also get a powerfull PowerShell Snap-in allowing you to create a command line batch job for copying your backup to Amazon S3. Read this article to get my fully working example.

First Step: Create an Amazon S3 account

Amazon S3 is a very simple and cheap way of getting extra storage. It also allows you to save your data in different regions of the world. You are free to choose between US, Europe, Asia or South America – taking care of legal or safety issues you might have.

Second Step: Create bucket

After creating your S3 account, create a new “Bucket” for your backup. A Bucket is an endpoint for your backup. This is where you choose the regional residence of your backup.

Third Step: Download and install CloudBerry S3 Explorer

The Freeware version will do just fine for this example. You can download it from the CloudBerry Lab website.

Fourth Step: Register the CloudBerry snap-in for PowerShell

Before you can use the S3 Cloud copying utilities in the PowerShell, you need to register the DLL.

C:\Windows\Microsoft.NET\Framework\v2.0.50727\installutil.exe CloudBerryLab.Explorer.PSSnapIn.dll

If you use x64, you should do something like this instead:

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files (x86)\CloudBerryLab\CloudBerry Explorer for Amazon S3\CloudBerryLab.Explorer.PSSnapIn.dll"

The above comes from CloudBerrys site, I used installutil in C:\Windows\Microsoft.NET\Framework\v4.0.30319 on my Windows Server 2008R2 64-bit with no problems.

The DLL is now registered. Whenever you need to use the Snap-in in PowerShell, you need to add it with this command:

Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn

Fifth Step: Create and customize the PowerShell-script

Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn
$d = (Get-Date).AddDays(-1).ToString("dd")
Remove-Item F:\Backup\HTTP.rar
& "C:\Program Files\WinRAR\rar.exe" a -m5 -r F:\Backup\HTTP.rar E:\HTTP
& "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" -umysqluser -pmysqlpassword --routines --force --all-databases --default-character-set=latin1 | Out-File F:\Backup\MySQLDump.sql -Encoding oem
Remove-Item F:\Backup\MySQLDump.rar
& "C:\Program Files\WinRAR\rar.exe" a -m5 F:\Backup\MySQLDump.rar F:\Backup\MySQLDump.sql
Remove-Item F:\Backup\InetpubHistory.rar
& "C:\Program Files\WinRAR\rar.exe" a -m5 F:\Backup\InetpubHistory.rar C:\Inetpub\history
Copy-Item F:\Backup\HTTP.rar F:\Backup\HTTP-$d.rar
Copy-Item F:\Backup\MySQLDump.rar F:\Backup\MySQLDump-$d.rar
Copy-Item F:\Backup\InetpubHistory.rar F:\Backup\InetpubHistory-$d.rar

$s3 = Get-CloudS3Connection -Key {Insert your S3 API Key here} -Secret {Insert your S3 Secret here}
$destination = $s3 | Select-CloudFolder -path "MyBucket/Backup"
$src = Get-CloudFilesystemConnection | Select-CloudFolder "F:\Backup"
$src | Copy-CloudItem $destination -filter "HTTP-$d.rar"
$src | Copy-CloudItem $destination -filter "MySQLDump-$d.rar"
$src | Copy-CloudItem $destination -filter "InetpubHistory-$d.rar"

C:\Inetpub\history is an updated history of your IIS7.5 metabase. IIS backups the latest couple of settings automatically, and you can also force a new history backup entry (Try googling “IIS7.5 appcmd” for more info)

In a simple way, this gives you 1 month of rolling backup locally and on your S3 storage. Please note, that the above is inspiration, and you need to customize the script for your needs. Remember the S3 API key, secret and bucket name. If you use a folder name after your bucket (MyBucket/Backup), you must create the folder using Amazon S3 console first.

Last step: Setup a Scheduled task

Now, you only need to setup a scheduled task that runs your Powershell script:

powershell.exe F:\Backup\Backup.ps1

Important! Please test the command in a command line first (regular command line – not PowerShell), since you may get an error, that script execution is not allowed:

File f:\backup\backup.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-
help about_signing" for more details.

If you get this error, you should start PowerShell and execute the following command:

Set-ExecutionPolicy RemoteSigned

Happy backup’ing – and always remember to test your backup before feeling happy!


  1. It would be nice if they made this a PowerShell v2 module instead of a v1 snap-in.

  2. Thank you so much for featuring CloudBerry Explorer in your article. Please come back to us to claim your free license!

Leave a Reply

Your email address will not be published.