Thursday, December 6, 2018

[google-cloud-sql-discuss] Re: Backup restore to different instance, in different project

Found a way, you can do:
gcloud sql export sql db-production gs://someproject-development-bucket/db-production_dump.sql --project someproject-production && \
gcloud sql import sql db-development gs://someproject-development-bucket/db-production_dump.sql --project someproject-development

As long as permissions are set, you can import/export to/from any project to/from any project.

---

Our setup:
  
project-development:
- Cloud SQL: db-development
- Cloud Storage: bucket-development
- Cloud Build: clone-prod-to-dev

project-production:
- Cloud SQL: db-production

// YAML from Cloud Build trigger:
steps:
  
  # export SQL databases
  - name: 'gcr.io/cloud-builders/gcloud'
    args: [
      'sql', 'export', 'sql',
      'db-production',
      'gs://someproject-development-bucket/db-production_dump-$BUILD_ID.sql',
      '--project', 'someproject-production'
    ]
    waitFor: ['-']
    id: 'sql-export'
    
  # import SQL databases
  - name: 'gcr.io/cloud-builders/gcloud'
    args: [
      'sql', 'import', 'sql',
      'db-development',
      'gs://someproject-development-bucket/db-production_dump-$BUILD_ID.sql',
      '--project', 'someproject-development'
    ]
    waitFor: ['sql-export']


On Tuesday, January 24, 2017 at 6:25:52 PM UTC+1, Dan Gardner wrote:
I'm failing to restore a backup from a source instance to a target instance when each instance is in a different project.  Is this simply not supported ?

I get ambiguous permissions error from the target instance restore cmd**.   Also if I look in the console no option is offered to target instances in diff projects,  resonable I suppose for thr console.  

I guess unless you can pass a project in the restoreBackupContext json, as below, this isn't supported yet ?
  
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     
--header 'Content-Type: application/json' \
     
--data '{ "restoreBackupContext": {"backupRunId": "[BACKUP_ID]", "instanceId": "[SOURCE_INSTANCE_NAME]", "kind": "sql#restoreBackupContext"}}' \
     
-X POST \
     https
://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[TARGET_INSTANCE_NAME]/restoreBackup

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/e42b0387-9395-417a-a98b-44c849061ae2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment