There are
three main components to this workflow:
-
Timer (CRON equivalent). For this we will use windows task scheduler.
- Scripting shell. Since we are using windows, it is all PowerShell.
- S3 interface. Cloudberry and its awesome PowerShell snap-in.
Next, we
need to create a PS script which will execute our desired action. We will start by changing PowerShell’s
default execution policy to allow scripts.
Open up PowerShell and enter the command:
Set-ExecutionPolicy
RemoteSigned
Next,
create a new file in c:\scripts called sync.ps1,
right click on it and choose edit. Now
we will add the magic:
$key =
"YouAccessKeyIDGoesHere"$secret = "YourSecretAccessKeyGoesHere"
$s3bucket = "YourS3Bucket"
$localFolder = "c:\test\"
Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn
$s3 = Get-CloudS3Connection -Key $key -Secret $secret
$destination = $s3 | Select-CloudFolder -path $s3bucket
$src = Get-CloudFilesystemConnection | Select-CloudFolder -path $localFolder
$src | Copy-CloudSyncFolders $destination –IncludeSubfolders
Create a batch
script called BatchProcess.bat and place it in your c:\scripts folder. Add this single line to the batch file:
powershell.exe C:\scripts\sync.ps1
Now that we have a sync script and a batch file to call it, we need a timer to automate everything. Go to the Control Panel -> Administrative Tools -> Task Scheduler. Choose “Create task”
Make sure you
choose “Run whether user is logged on or
not” and check “Run with highest
privileges”. Also be sure to select
the proper “Configure For” dropdown
at the bottom, it doesn’t default to the OS you’re using. Next select the “Triggers” tab and create a new trigger. Change it to run every 5 minutes. Note that you can also change the “Begin on task” to run on start-up,
useful for auto-scaling groups. Finally,
go to the “Actions” tab and create a
new action. Select your BatchProcess.bat
file which you created above.
Now we have a sync
script which will automatically compare our local folder (c:\test) with a
remote S3 bucket (YourS3Bucket) and copy any deltas up to S3. This is a great way to automate backups.
Here are a number
of helpful links:
http://www.techrepublic.com/blog/10things/10-fundamental-concepts-for-powershell-scripting/2146