The company I work for has some Amazon EC2 Instances. These instances are running all kinds of custom developed software and some databases.
We wanted to create some kind of backup solution for these and sql databases and the software.
Here are my requirements:
- Backup solution must be done to some kind of storage and not local on the server
- Backup solution must run automatically (Scheduled)
Optional requirements:
- files must be zipped
- databases must be backupped from within script
reason: so I am not depended of a sql backup that has to be run first
After some research I came to the conclusion that I am going to be using PowerShell and that I will do my backup to a S3 storage bucket. I found a nice utililty named Cloudberry S3 Explorer which had some PowerShell Snap-in I could use. They even had an example script I could use as the base of my script.
To get the Cloudberry S3 Explorer powershell snap-in working (I did not wanted to install the tool on the server), follow these steps:
- Install Cloudberry S3 Explorer somewhere and copy all dll, xml and ps1xml files to a directory on your server
- Set the powershell execution policy to unrestricted by executing the command set-executionpolicy unrestricted
- From within the directory where you copied the dll, xml and ps1xml files run the following command:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\installutil.exe –I CloudBerryLab.Explorer.PSSnapIn.dll
In x64, I suggest you also use: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe CloudBerryLab.Explorer.PSSnapIn.dll
(as you see, you need the .net framework installed)
After some coding I had the following script (I did not implement the optional requirements just yet):
#declare variables
$SourceFolder = "D:\backup"
$key = "<your access key id>"
$secret = "<your secret access key>"
$destBucket = "<name of your s3 bucket>"
#load CloudBerryLab PSSnapin
Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn
$s3 = Get-CloudS3Connection -Key $key -Secret
$secret
$destination = $s3 | Select-CloudFolder -Path $destBucket
$source = Get-CloudFilesystemConnection | Select-CloudFolder $SourceFolder
$source | Copy-CloudSyncFolders $destination -DeleteOnTarget -IncludeSubFolders
Execute it, and you will see that all files in the $SourceFolder will be copied to you $destbucket. As we are using the Copy-CloudSyncFolders the next time it runs, it will synchronize the 2 directories.
I can now create a windows task which will execute the powershell with the following parameters:
-command "& ‘<location to your ps1 script>\<filename>.ps1′"

As I still do not have my secondary goals, I will try to work on that. But there is one thing I want to add to the Primary Goals list, that is the fact that the script has the access Key Id and the Secret Access Key in it, in plain text. Off course “not secure”. As more people can access the EC2 server, I don’t want them to see the passwords.
I know the Cloudberry command can’t handle a SecureString object, so I cant use the commands convertfrom-securestring and convertto-securestring to supply the credentials via a plain text file.
So I am thinking of putting this powershell script on one of my on premise servers and using PowerShell Remoting to execute the commands for a backup (I already tested this and it works, but it’s 2 long for now to write down
). So I will come back on that later.
In the mean time if some of the PowerShell Guru’s have a better idea to handle this in a more secure way, I would be most grateful with any advice.