Created
March 7, 2020 23:18
-
-
Save brandonrachal/f15419c8aa4b1270133b47295ad87003 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 os | |
from boto.s3.connection import S3Connection | |
def main(): | |
backup_folder = "<your_path>" | |
access_key = "<s3_access_key>" | |
secret_key = "<s3_secret_key>" | |
bucket_name = "<s3_bucket_name>" | |
amazon_s3 = S3Connection(access_key, secret_key) | |
bucket = amazon_s3.get_bucket(bucket_name) | |
# For every file | |
for key in bucket.list(): | |
backup_file_path = os.path.join(backup_folder, bucket_name, key.name) | |
print(backup_file_path) | |
parent_folder = os.path.dirname(backup_file_path) | |
# Create parent folder if missing | |
if not os.path.exists(parent_folder): | |
os.makedirs(parent_folder) | |
# Skip if it's already there | |
if not os.path.isfile(backup_file_path): | |
key.get_contents_to_filename(backup_file_path) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment