How to automate backup on AWS S3...?
Prem Choudhary
1 min read
Firstly, connect your local system to AWS via a CLI.
I had already posted a blog on how to connect local system to AWS via a CLI you can check it out.
After connecting. Run this python code.
import boto3
S3=boto3.resource("S3")
def show_buckets(S3):
for buck in S3.buckets.all():
print(buck.name)
def create_buckect(S3,bucket_name,region):
S3.create_bucket(Bucket=bucket_name,CreateBucketConfiguration={'LocationConstraint':region})
print("Bucket created successfully")
def upload_backup(S3,file_name,bucket_name,key_name):
data=open(file_name,'rb')
S3.Bucket(bucket_name).put_object(Key=key_name,Body=data)
print("Backup created successfully")
bucket_name="python-for-devops"
region="us-east-2"
file_name="/path/to/backup file/in the/local system"
upload_backup(S3,file_name,bucket_name,"my_backup.tar.gz")
Your Backup will be automated successfully to AWS S3 bucket.
Thank you.
0
Subscribe to my newsletter
Read articles from Prem Choudhary directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Prem Choudhary
Prem Choudhary
DEVOPS ENGINEER || AWS || JAVA || PYTHON || SPRING BOOT || SPRING SECURITY || REACT.JS || MONGO DB || MYSQL