How to copy a file from Google Cloud Storage bucket 1 to bucket 2 while keeping ACLs using gsutil

I intend to copy a single file on Google Cloud Storage from bucket 1 to bucket 2 while keeping ACLs (Access Control List) using gsutil.

The following command copies the file over, however it does not copy ACL information over :

gsutil cp -p rsync gs://bucket1/path/file gs://bucket2/path/file

How can I both copy the file and the ACLs ?

1 answer

  • answered 2021-06-17 09:34 Prabir Behera

    • First of all if we want to copy objects from one bucket to another bucket having the ACLs intact we have to use fine grained access control on both the buckets.
    • If we use uniform access control then the object will have permission according to the destination bucket.
    • To learn more about ACLs on bucket and object you can visit this link.

    Now to answer your question the below command should do it if you have fine grained access control on both the buckets.

    gsutil cp -p  gs://source_bucket/file_name gs://destination_bucket/new_file_name 
    
      
    
    • You can find the reference to the above command in this link.