简体   繁体   English

从谷歌云 sql 上的备份创建实例

[英]Create instance from backup on google cloud sql

I would have two questions related to cloud sql backups:我有两个与云 sql 备份相关的问题:

  1. Are backups removed together with instance or maybe they are left for some days?备份是否与实例一起删除,或者它们可能会保留几天?
  2. If no, is it possible to create new instance from backup of already gone instance?如果不是,是否可以从已经消失的实例的备份中创建新实例?

I would expect it possible but looks like backups are only listable under the specific instance and there is no option to start new instance from existing backup.我希望这是可能的,但看起来备份只能在特定实例下列出,并且没有从现有备份启动新实例的选项。

Extracted from Google Cloud SQL - Backups and recovery提取自Google Cloud SQL - 备份和恢复

Restoring from a backup restores to the instance from which the backup was taken.从备份还原会还原到从中获取备份的实例。

So the answer to (1) is they're gone and with regards to (2) if you didn't export a copy of the DB to your Cloud Storage, then No, you can't recover your deleted Cloud sQL instance content .所以 (1) 的答案是它们消失了,关于 (2) 如果你没有将数据库的副本导出到你的云存储,那么不,你不能恢复你删除的云 SQL 实例内容

Regarding to (2): It's actually possible to recover them if you are quick enough.关于(2):如果你足够快,实际上可以恢复它们。 They should still be there, even when Google says they're deleted.它们应该仍然存在,即使 Google 说它们已被删除。

If you know the name of the deleted DB run the following command to check if they are still there如果您知道已删除数据库的名称,请运行以下命令以检查它们是否仍然存在

gcloud sql backups list --instance=deleted-db-name --project your-project-name

If you can see any results, you are lucky.如果你能看到任何结果,那你就很幸运了。 Restore them ASAP!尽快恢复它们!

gcloud sql backups restore <backup-ID> --restore-instance=new-db-from-scratch-name --project your-project

And that's it!就是这样!

Further info: https://geko.cloud/gcp-cloud-sql-how-to-recover-an-accidentally-deleted-database/更多信息: https : //geko.cloud/gcp-cloud-sql-how-to-recover-an-accidentally-deleted-database/

I noticed a change in this behavior recently (July 28, 2022).我最近注意到这种行为发生了变化(2022 年 7 月 28 日)。 Part of our application update process was to run an on-demand backup on the existing deployment, tear down our stack, create a new stack, and then populate the NEW database from the contents of the backup.我们的应用程序更新过程的一部分是在现有部署上运行按需备份,拆除我们的堆栈,创建一个新堆栈,然后从备份的内容填充新数据库。

Until now, this worked perfectly.到目前为止,这工作得很好。

However, as of today, I'm unable to restore from the backup since the original database ( dummy-db-19e2df4f ) was deleted when we destroyed the old stack.但是,截至今天,我无法从备份中恢复,因为在我们销毁旧堆栈时删除了原始数据库( dummy-db-19e2df4f )。 Obviously the workaround is to not delete our original database until the new one has been populated, but this apparent change in behavior was unexpected.显然,解决方法是在填充新数据库之前不要删除我们的原始数据库,但这种明显的行为变化是出乎意料的。

Since the backup is listed, it seems like there are some "mixed messages" below.由于列出了备份,因此下面似乎有一些“混合消息”。

List the backups for my old instance:列出我的旧实例的备份:

$ gcloud sql backups list --instance=- | grep dummy-db-19e2df4f
1659019144744  2022-07-28T14:39:04.744+00:00  -      SUCCESSFUL  dummy-db-19e2df4f
1658959200000  2022-07-27T22:00:00.000+00:00  -      SUCCESSFUL  dummy-db-19e2df4f
1658872800000  2022-07-26T22:00:00.000+00:00  -      SUCCESSFUL  dummy-db-19e2df4f
1658786400000  2022-07-25T22:00:00.000+00:00  -      SUCCESSFUL  dummy-db-19e2df4f

Attempt a restore to a new instance (that is, replacing the contents of new-db-13d63593 with that of the backup/snapshot 1659019144744 ).尝试还原到新实例(即将new-db-13d63593的内容替换为备份/快照1659019144744的内容)。 Until now this worked :到目前为止,这有效

$ gcloud sql backups restore 1659019144744 --restore-instance=new-db-13d63593
All current data on the instance will be lost when the backup is 
restored.

Do you want to continue (Y/n)?  y

ERROR: (gcloud.sql.backups.restore) HTTPError 400: Invalid request: Backup run does not exist..

(uh oh...) (呃哦……)

Out of curiosity, ask it to describe the backup:出于好奇,请它描述备份:

$ gcloud sql backups describe 1659019144744 --instance=dummy-db-19e2df4f
ERROR: (gcloud.sql.backups.describe) HTTPError 400: Invalid request: Invalid request since instance is deleted.

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM