Last active
May 21, 2019 09:04
-
-
Save salekh/098f1130d5f3e961860b9fdb4c76beda to your computer and use it in GitHub Desktop.
Copy blob from one GCS bucket to another
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
def copy_blob(bucket_name, blob_name, new_bucket_name, new_blob_name): | |
"""Copies a blob from one bucket to another with a new name.""" | |
storage_client = storage.Client() | |
source_bucket = storage_client.get_bucket(bucket_name) | |
source_blob = source_bucket.blob(blob_name) | |
destination_bucket = storage_client.get_bucket(new_bucket_name) | |
new_blob = source_bucket.copy_blob( | |
source_blob, destination_bucket, new_blob_name) | |
print('Blob {} in bucket {} copied to blob {} in bucket {}.'.format( | |
source_blob.name, source_bucket.name, new_blob.name, | |
destination_bucket.name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment