简体   繁体   English

将 Google Cloud Storage 备份到另一个 Bucket

[英]Backing up Google Cloud Storage to another Bucket

I know there are cronjob's available to backup google datastore but are there any easy methods of creating a cronjob to make daily backups of Google Cloud Storage to another Cloud Storage bucket?我知道有 cronjob 可用于备份 google 数据存储区,但是否有任何简单的方法可以创建 cronjob 来将 Google Cloud Storage 的每日备份到另一个 Cloud Storage 存储桶?

I know I could use something like this:我知道我可以使用这样的东西:

gsutil cp -D -R gs://<bucket>/* gs://<backup>/folder

Or I've ready something about Object Versioning but not sure if this pertains to what I am trying to do.或者我已经准备好有关Object 版本控制的内容,但不确定这是否与我正在尝试做的有关。

But I'd like to do this in a cronjob using a php appengine and not in a compute engine.但我想在 cronjob 中使用 php appengine 而不是在计算引擎中执行此操作。

I know I can create objects like so: (but is there a way to easily migrate and copy data over?)我知道我可以像这样创建对象:(但是有没有办法轻松地迁移和复制数据?)

$document_data = "123456789";
$object_url = "gs://<bucket>/file.ext";
$options = stream_context_create(['gs'=>['acl'=>'private']]);
$my_file = fopen($object_url, 'w', false, $options);
fwrite($my_file, $document_data);
fclose($my_file);

A little bit late eh, but GCS Transfer is what you are looking for.有点晚了,但是GCS Transfer正是您要找的。

From the doc:从文档:

Transfer data to your Cloud Storage buckets from Amazon Simple Storage Service (S3), HTTP/HTTPS servers, or other buckets.将数据从 Amazon Simple Storage Service (S3)、HTTP/HTTPS 服务器或其他存储桶传输到您的 Cloud Storage 存储桶。 You can schedule one-time or daily transfers, and you can filter files based on name prefix and when they were changed.您可以安排一次性或每日传输,并且您可以根据名称前缀和更改时间来过滤文件。

There is not an equivalent automated GCS tool like datastore's backup/restore tool.没有像数据存储的备份/恢复工具那样等效的自动化 GCS 工具。 A cronjob running on a GCE instance, like you identified, is the easiest way to accomplish such a task.正如您所指出的,在 GCE 实例上运行的 cronjob 是完成此类任务的最简单方法。

Object versioning may suit your needs depending on why you want a backup.对象版本控制可能适合您的需求,具体取决于您为何需要备份。 Object versioning works by keeping multiple copies of an object such that every time you overwrite or delete an object, its previous state stays around as an object with the same name but a different "generation" number.对象版本控制的工作原理是保留一个对象的多个副本,这样每次覆盖或删除一个对象时,其先前的状态都保留为具有相同名称但“世代”编号不同的对象。 You can also configure Google Cloud Storage to periodically delete generations older than a certain amount of time or with a certain number of later generations already existing.您还可以将 Google Cloud Storage 配置为定期删除早于特定时间或已经存在一定数量的后代。

That may be fine if your big worry is accidentally overwriting important data.如果您的主要担忧是意外覆盖重要数据,那可能没问题。 Or it might not be fine if you're worried about accidentally deleting all of the objects in your bucket, including older generations of objects.或者,如果您担心意外删除存储桶中的所有对象(包括较旧的对象),这可能不太好。 Or it might not be fine if you need the ability to reset your bucket to the state of a particular day.或者,如果您需要能够将存储桶重置为特定日期的状态,则可能不太好。

If object versioning doesn't work for you, and you don't want to set up a cronjob running gsutil, and you want to use app engine, then yes, you'd have to write a program that iterates over all of the objects in your bucket and copies them to another bucket.如果对象版本控制对您不起作用,并且您不想设置运行 gsutil 的 cronjob,并且您想使用应用程序引擎,那么是的,您必须编写一个程序来遍历所有对象在您的存储桶中并将它们复制到另一个存储桶。

To copy everything in a source bucket to a destination bucket, you could use a command similar to this:要将源存储桶中的所有内容复制到目标存储桶,您可以使用类似于以下的命令:

$ gsutil cp -r gs://SOURCE_BUCKET_NAME/* gs://DESTINATION_BUCKET_NAME/

Alternatively you could use gsutil rsync with the -r switch to synchronise the contents of a source bucket with a destination bucket.或者,您可以使用带有 -r 开关的 gsutil rsync 将源存储桶的内容与目标存储桶同步。 For example:例如:

$ gsutil rsync -r gs://SOURCE_BUCKET_NAME gs://DESTINATION_BUCKET_NAME/

reference参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Google Cloud Storage 中的文件从一个存储桶移动到另一个存储桶 Python - How to move files in Google Cloud Storage from one bucket to another bucket by Python Google Cloud Storage 对存储桶中的对象进行分页 (PHP) - Google Cloud Storage paginate objects in a bucket (PHP) 从谷歌云存储桶中读取文件 - Reading files from google cloud storage bucket 从 Google Cloud Storage Bucket 下载文件夹 - Downloading folders from Google Cloud Storage Bucket 谷歌云存储:删除存储桶后无法重用存储桶名称 - Google cloud storage: Cannot reuse bucket name after deleting bucket 将文件从 Azure blob 存储移动到 Google 云存储桶 - Moving Files from Azure blob storage to Google cloud storage bucket 如何将 BigQuery 视图作为 csv 文件传输到 Google Cloud Storage 存储桶 - How to Transfer a BigQuery view to a Google Cloud Storage bucket as a csv file 防止 Google Cloud Storage 帐户所有者对用户存储桶对象的可见性 - Preventing Google Cloud Storage account owner visibility into user bucket objects 将 spacy model 保存并加载到谷歌云存储桶 - Save and load a spacy model to a google cloud storage bucket 如何正确初始化谷歌云存储和存储桶和/或初始化 Multer - How to properly initialize google cloud storage and bucket and/or intialize Multer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM