Powershell Command Fetch File From S3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Param(
    # AWS IAM Credentials
    [string]$access_key = "secret",
    [string]$secret_key = "secret",
    [string]$aws_region = "us-east-1",
    [string]$bucket_name = "www.itsmetor.com",

    # Database connection information
    [string]$database_name = "northwind",
    [string]$backups_dir = "D:\backups"
)

# Take the database backup
$db_filename = ("AIMS.2020-01-15.bak");
$backup_filename = (Join-Path $backups_dir $db_filename);

# Download the database backup to S3
Set-AWSCredential -AccessKey $access_key -SecretKey $secret_key;
Set-DefaultAWSRegion $aws_region;
$s3_file_key = ("databases" + $db_filename)
Write-Output ("Downloading " + $backup_filename + " from s3:\" + $bucket_name + "" + $s3_file_key);
Read-S3Object -BucketName $bucket_name -File $backup_filename -Key $s3_file_key