Skip to content

Instantly share code, notes, and snippets.

@hughe
Created December 17, 2015 20:19
Show Gist options
  • Save hughe/ed8257a114366dc035d3 to your computer and use it in GitHub Desktop.
Save hughe/ed8257a114366dc035d3 to your computer and use it in GitHub Desktop.
Example of backing up a folder to StorReduce using Powershell and the AWS CLI.
# # # #
# Simple PowerShell script to backup a timestamped directory to StorReduce
# # # #
# 1. Download and install aws-cli from https://aws.amazon.com/cli/
# 2. Create a bucket in StorReduce as well as access keys (and optionally bucket policy, if not using root account)
# 3. Open and/or create %UserProfile%\.aws\credentials (e.g. C:\Users\Administrator\.aws\credentials) and enter your keys from step 2:
#
# [default]
# aws_access_key_id=IAMANACCESSKEY
# aws_secret_access_key=IAMASECRETACCESSKEY
#
# 4. Run .\backup.ps1 <full path of dir to backup> <bucket name from step 2> <storreduce api endpoint url>:
# e.g: .\backup.ps1 C:\Users\Administrator\Downloads backups https://storreduce.us-west-2.elb.amazonaws.com
#
# For convenience the script could be changed to have a hardcoded bucket and endpoint url.
# See our aws-cli tuning guide <here> for guidance on how to optimize throughput.
# # # #
$directory = $args[0]
$bucket = $args[1]
$endpoint = $args[2]
If(!$directory)
{
'Directory to backup must be specified as first arg.'
exit
}
If(!$bucket)
{
'StorReduce bucket must be specified as second arg.'
exit
}
If(!$endpoint)
{
'StorReduce S3 Api endpoint must be specified as third arg.'
exit
}
$baseFolder = [System.IO.Path]::GetFileNameWithoutExtension($directory)
$timeStamp = (Get-Date).ToUniversalTime().tostring("yyyyMMdd-hhmmss")
$destination = $baseFolder + "_" + $timeStamp
# # # #
# Note if using a valid certificate "--no-verify-ssl" should be removed from this command
# # # #
cmd "/c aws s3 cp $directory/ s3://$bucket/$destination --recursive --endpoint-url $endpoint --no-verify-ssl"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment