編寫個powershell腳本sql
$server = '.' $database = 'databaseName' $s3Bucket = 's3bucket' $backupPath = 'D:\BackupTask\data\' $region = 'us-west-2' # accessKey and secretKey can be removed if running on an EC2 instance and using IAM roles for security $accessKey = '' $secretKey = '' $timestamp = get-date -format yyyyMMddHHmmss $fileName = "$database-$timestamp.bak" $filePath = Join-Path $backupPath $fileName $s3FilePath = "sql-server-bak\" + $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 $s3FilePath -Region $region -AccessKey $accessKey -SecretKey $secretKey Remove-Item $backupPath$database*.bak
命名爲BackupToS3.ps1,將腳本添加到windows計劃任務執行便可shell