Created
June 20, 2024 20:35
-
-
Save velddev/6b66ef11b498a2b348018238cd00d3da to your computer and use it in GitHub Desktop.
super easy downloadable python script to upload my backups from pods
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
import boto3 | |
def upload_to_digitalocean(access_key, secret_key, endpoint_url, bucket_name, object_key, file_path): | |
session = boto3.session.Session() | |
client = session.client( | |
's3', | |
endpoint_url=endpoint_url, | |
aws_access_key_id=access_key, | |
aws_secret_access_key=secret_key, | |
) | |
try: | |
client.upload_file(file_path, bucket_name, object_key) | |
print("Upload successful.") | |
except Exception as e: | |
print(f"Upload failed: {e}") | |
if __name__ == "__main__": | |
import sys | |
import os | |
if len(sys.argv) != 6: | |
print("Usage: python s3_upload_digitalocean.py <access_key> <secret_key> <endpoint_url> <bucket_name> <object_key> <file_path>") | |
sys.exit(1) | |
access_key = sys.argv[1] | |
secret_key = sys.argv[2] | |
endpoint_url = sys.argv[3] | |
object_key = sys.argv[4] | |
file_path = sys.argv[5] | |
if not os.path.isfile(file_path): | |
print(f"Error: File '{file_path}' not found.") | |
sys.exit(1) | |
upload_to_digitalocean(access_key, secret_key, endpoint_url, 'pg-crictl-backup', object_key, file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment