Created
September 27, 2014 10:34
-
-
Save rhysgodfrey/18485cd9f8b95a7b5e42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$server = '.' | |
$database = 'MyDatabase' | |
$s3Bucket = 's3-sql-backups' | |
$backupPath = 'C:\SqlBackup\' | |
$region = 'eu-west-1' | |
# accessKey and secretKey can be removed if running on an EC2 instance and using IAM roles for security | |
$accessKey = 'USER-ACCESS-KEY' | |
$secretKey = 'USER-SECRET-KEY' | |
$timestamp = get-date -format yyyyMMddHHmmss | |
$fileName = "$database-$timestamp.bak" | |
$filePath = Join-Path $backupPath $fileName | |
Backup-SqlDatabase -ServerInstance $server -Database $database -BackupFile $filePath | |
# AccessKey and SecretKey can be removed if running on an EC2 instance and using IAM roles for security | |
Write-S3Object -BucketName $s3Bucket -File $filePath -Key $fileName -Region $region -AccessKey $accessKey -SecretKey $secretKey | |
Remove-Item $backupPath$database*.bak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment