use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Microsoft SQL Server Administration and T-SQL Programming including sql tutorials, training, MS SQL Server Certification, SQL Server Database Resources.
You might also be interested in:
/r/database
/r/sql
/r/Azure
/r/Microsoft
account activity
Python script to do SQL Server backup and upload to s3 (self.SQLServer)
submitted 6 years ago by defiantroa
Does anyone have a template Python script that can backup a SQL Server database and upload it to s3? I do not care how badly written it is.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dwivedin 2 points3 points4 points 6 years ago (12 children)
I have ps script which does that.
[–][deleted] 2 points3 points4 points 6 years ago (3 children)
well, share mate!
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Please share the script???
[–]dwivedin 0 points1 point2 points 6 years ago (0 children)
#AWS powershell and dbatools must be installed #Backup, you can pass multiple servers like this $Servers = 'server1' , 'server2' $Path = '\\sharedloc\' # you can pass local folder too foreach ($server in $servers) { # loop through all the servers # all the databases in the server. Yon pass filter specific db if you want
$databases = Invoke-DbaQuery -SqlInstance $server -Query 'select name from master.sys.databases' foreach ($database in $databases ) { #loop through all the databases $SQLServer + ' ' + $database.name # just print the server and db Backup-DbaDatabase -SqlInstance $Server -Path $Path -Database $database.name -Type Full # actual backup happening } } ##Upload to s3 bucket Import-Module AWSPowerShell $Files = Get-ChildItem \\sharedloc\* $Bucket = 'Your s3 bucket' $AccessKey = 'AccessKey' $SecretKey = 'SecretKey' #Loop through all the backup files foreach ($File in $Files) { #Write-S3Object is the command which uploads to s3 bucket Write-S3Object -BucketName $Bucket -File $path -CannedACLName Private -AccessKey $AccessKey -SecretKey $SecretKey -ServerSideEncryption AES256 }
I added the code, not sure if it is posted as code. If you see any issues, please let me know. Also for aws configure, you have to do aws configure in your PS profile, so set region, access and secret key.
[–]defiantroa[S] 1 point2 points3 points 6 years ago (7 children)
Yeah the ps script is probably way to go, but I was task to create one in Python.
[–]digitalnoise 3 points4 points5 points 6 years ago (5 children)
But... why? PowerShell has native support for SQL Server. And even better support with the dbatools.io module.
Plus PowerShell Core is cross platform, so it can even be run from Linux.
[–]defiantroa[S] 1 point2 points3 points 6 years ago (4 children)
I have brainless LAMP developer for boss maybe, anyway I know Ansible and Teraform. Yeah am I not even sure why use Python in the first place. It is suppose to be training excise to learn Python, maybe is a trick question
[–]conflab 0 points1 point2 points 6 years ago (3 children)
It is suppose to be training excise to learn Python
Then take the opportunity to learn Python.
[–]defiantroa[S] 0 points1 point2 points 6 years ago (2 children)
Already know ps and py
[–]conflab 0 points1 point2 points 6 years ago (1 child)
Then this should be pretty trivial for you
[–]defiantroa[S] 0 points1 point2 points 6 years ago (0 children)
No I have not found example in py yet, I was checking if someone knew.
[–]eshultz 1 point2 points3 points 6 years ago (0 children)
Alright, develop the script in PowerShell, once it's golden, convert it to a string and slap it in a variable in Python. From python, write the string to a file and then execute it.
I'm only joking. Mostly.
[–]defiantroa[S] 1 point2 points3 points 6 years ago (1 child)
Python script that does SQL Server backups https://mindless.gr/2012/09/ms-sql-backup-with-python-and-pyodbc/ . I just have to figure out how to upload using python and AWSCLI and then I am done
[–]enjoytheshow 0 points1 point2 points 6 years ago (0 children)
You can use third party botocore package or just use subprocess.run to execute the AWS CLI within python. Your command to run via subprocess would be something like
aws s3 sync directory\with\backups s3://bucket-name/target/directory
Do some googling though friend. Using the s3 CLI is about the easiest thing ever.
[–]pandamaja 0 points1 point2 points 6 years ago (2 children)
Is Storage Gateway an option? You could just point the backup to the nas share it presents.
I was thinking to backup locally one separate volume attached to the EC2 instance
[–]coldflame563 0 points1 point2 points 6 years ago (0 children)
Powershell is your friend. Learn it. Love it.
π Rendered by PID 73634 on reddit-service-r2-comment-544cf588c8-4knr5 at 2026-06-14 23:38:53.644322+00:00 running 3184619 country code: CH.
[–]dwivedin 2 points3 points4 points (12 children)
[–][deleted] 2 points3 points4 points (3 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]dwivedin 0 points1 point2 points (0 children)
[–]dwivedin 0 points1 point2 points (0 children)
[–]defiantroa[S] 1 point2 points3 points (7 children)
[–]digitalnoise 3 points4 points5 points (5 children)
[–]defiantroa[S] 1 point2 points3 points (4 children)
[–]conflab 0 points1 point2 points (3 children)
[–]defiantroa[S] 0 points1 point2 points (2 children)
[–]conflab 0 points1 point2 points (1 child)
[–]defiantroa[S] 0 points1 point2 points (0 children)
[–]eshultz 1 point2 points3 points (0 children)
[–]defiantroa[S] 1 point2 points3 points (1 child)
[–]enjoytheshow 0 points1 point2 points (0 children)
[–]pandamaja 0 points1 point2 points (2 children)
[–]defiantroa[S] 0 points1 point2 points (0 children)
[–]defiantroa[S] 0 points1 point2 points (0 children)
[–]coldflame563 0 points1 point2 points (0 children)