Google cloud storage Gsutil批量复制/移动文件

Google cloud storage Gsutil批量复制/移动文件,google-cloud-storage,gsutil,Google Cloud Storage,Gsutil,是否有方法使用gsutil命令批量复制或移动文件? 例如,如果我想将100个文件从给定文件夹复制到另一个文件夹。另一种方法是使用。例如,在Python中: from google.cloud import storage storage_client = storage.Client() bucket_name = 'my_bucket' bucket = storage_client.get_bucket(bucket_name) blobs_to_move = [blob for bl

是否有方法使用gsutil命令批量复制或移动文件?
例如,如果我想将100个文件从给定文件夹复制到另一个文件夹。

另一种方法是使用。例如,在Python中:

from google.cloud import storage

storage_client = storage.Client()

bucket_name = 'my_bucket'
bucket = storage_client.get_bucket(bucket_name)

blobs_to_move = [blob for blob in bucket.list_blobs(prefix="folder1/")]

with storage_client.batch():
    for blob in blobs_to_move[:100]:
        # copy to new destination
        new_blob = bucket.copy_blob(blob, bucket, "folder2/" + blob.name[8:])
        # delete in old destination
        blob.delete()   
这将把GCS bucket
my_bucket
中的
folder1
中的前100个文件移动到
folder2
尝试以下操作:

gsutil ls gs://bucketA | head-n 100 | shuf | gsutil cp-m-I gs://bucketB

这将从bucketA获得一个文件列表,获取前100个项目,使用随机化,并将它们导入
gsutil
以复制到bucketB。
-I
标志从
stdin

读取文件列表并不准确。我要寻找的是一种只复制整个内容子集的方法。例如,1000个文件中只有100个文件。是的,随机查找命令所做的类似于此处的内容-find-maxdepth 1-类型f | head-500 | xargsy您可以自己生成一个文件列表,并使用
-I
标志将它们导入gsutil。@user101010您也可以使用Python客户端库来完成此操作。我已经更新了我的答案。我认为-m标志应该在cp命令之前。