retrieving automated backup from google sql - google-cloud-platform

I would like to download an automated backup of my google cloud sql, my issue is, I have a client who accidentally deleted some data, and I am hoping using the latest automated backup I can pick and choose which to restore, by either restoring it to a different DB or some janky regex
From the options I see, I can only restore the whole thing.
Is there a way? I am in dire need of this capability.

So turns out you can do it by:
Creating a new instance (not a new database)
Restore this instance to the backup you want

Related

How to copy an AWS RDS database, NOT the entire instance

I am somewhat new to AWS RDS and their terminology. What they call a "database" seems to me to be an SQL Server instance. I have a database (as defined by SSMS--with tables, data, stored procedures, etc.) on RDS named "prod" and I want to duplicate it for testing purposes to be named "test" with all the content, and leave "prod" as-is.
All the instructions I've found by doing many, many searches seem to be related to duplicating the entire instance. Can someone help me with instructions on how to create a duplicate of just the (ssms term) database?
Thanks in advance for any help!
P.S. What does AWS/RDS call the object that is equivalent to an SSMS database?
I've found multiple posts here about duplicating an entire instance. It could be that I don't fully understand the terminology because I know this must be a common task but I am not understanding how to do it.
This is a production environment so I am proceeding very cautiously. I do have nightly snapshots made so I know I could recover but would rather do it right the first time.
I usually use a command like this to backup a single database to s3:
exec msdb.dbo.rds_backup_database #source_db_name='<mydatabasename>', #S3_arn_to_backup_to='arn:aws:s3:::<mys3objectname>', #type='FULL'
There is a bit of one-time configuration you need to do first, see the link below , and then its as simple as executing commands from SSMS to backup a database to S3 and then restoring it from S3 - maybe not exactly what you are looking for, but it works great.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html
What you are looking for can't really be done via any RDS commands/tools/interface. RDS only concerns itself with the database server itself, and isn't really even aware of the different databases, schemas, tables, etc. you may have created on the server.
You will need to use the tools for the DBMS you are using, in this case it sounds like you are using Microsoft SQL Server, so you will need to use MS SQL Server tools (perhaps running on an EC2 instance) to dump a single database to a file, and then load it into another database.
P.S. What does AWS/RDS call the object that is equivalent to an SSMS database?
An RDS database is a "database server". You might also see it called a "database instance". AWS/RDS calls the object equivalent to an SSMS database simply a database. The terminology is confusing because both the physical server/computer running the database software, and the logical grouping of tables/logs/data inside the software are both generally referred to as a "database".

Can I tell Google Cloud SQL to restore my backup to a completely different database?

Since there is a nightly backup of SQL we are wondering of a good way to restore this backup to a different database in the same MySQL server instance. We have prod_xxxx for all our production databases AND we have staging_xxxx for all our staging databases (yes not that good in that they are all on the same mysql instance right now).
Anyways, we would love to restore all tables/constraints/etc and data from prod_incomingdb to staging_incomingdb. Is this possible in cloud SQL?
Since this is over a productive instance I recommend you to perform a backup before start, in order to avoid any data corruption.
To clone a database within the same instance, there is not a direct way to perform the task (this is a missing feature on MySQL).
I followed this path in order to successfully clone a database within same MySQL Cloud SQL instance.
1.- Create a dump of the desired database using the Google Cloud Console (Web UI) by follow these steps
*it is very important to only dump the desired database in format SQL, please not select multiple databases on the dump.
After finish the process, the dump will be available in a Google Cloud Storage Bucket.
2.- Download the dump file to a Compute Engine VM or to any local machine with linux.
3.- please replace the database name (the old one) in the USE clauses.
I used this sed command over my downloaded dump to change the names of the databases
sed -i 's/USE `employees`;/USE `emp2`;/g' employees.sql
*this can take some seconds depending the size of your file.
4.- Upload the updated file to the Cloud storage bucket.
5.- Create a new empty database on your Cloud SQL instance, in this case my target instance is called emp2.
6.- Import the modified dump by following these steps
I could not figure out the nightly backups as it seems to restore an entire instance. I think the answer to the above is no. I did find out that I can export and then import (not exactly what I wanted though as I didn't want to be exporting our DB during the day but for now, we may go with that and automate a nightly export later).

Share and restore cloud sql backup files across account ( project )

How can I Share and restore cloud sql backup files across account ( project )
For those that stumble across this post 2018. It is now possible to restore cloudSQL between projects. As of this post you still need to use curl but it does work. The link below is to the mysql docs but I got it to work fine with SQL Server.
https://cloud.google.com/sql/docs/mysql/backup-recovery/restoring#projectid
Unfortunately, you cannot restore an instance using a backup created in a different project, as stated in the documentation for instance restoration:
When you are restoring a backup to a different instance, keep in mind
the following restrictions and best practices:
You cannot restore an instance using a backup taken in a different GCP project.
...
Maybe the following is not your specific use case, but should you replicate your instance in a new project, you should follow these steps: export your data to a SQL dump or CSV file, and then import it in a new instance in your other project. Here it is a more detailed guide on how to achieve that:
Export data from your current Cloud SQL instance in a format that can be later usable by Cloud SQL.
Create a new Cloud SQL instance in the project of your choice. Select the same characteristics as the one in your current instance, or the ones that fit your future requirements better.
Create the databases and tables in your new instance.
Import the previously created dump/CSV file to the new instance [4].
Once these steps are completed, you should have a new Cloud SQL instance with the same data as the one in the old instance at the moment of creation of the export files.
However, as I already said, this is not restoring from a backup, so you cannot recover a previous instance state into an instance in a different project.

Django:Backup and restore

I have been reading about process to do backup and restore in django.
The best i could come up with was to dumpdata.
i.e. python manage.py dumpdata >foo.json
Now to restore this data we will have to delete or drop the present table, then restore this json file using it as a fixture. i.e. do syncdb
Is there any particular way of doing this ? i.e. is there any process which can be used every-time we do backup and restore?
I am looking for a tool like south, which can used for database backup and restore.
I am planning to get my site online.So any help will be highly appreciated.
The django-dbbackup package can do database backups and restores.
For proper backup and restore, use the tools that came with your database.
If you must use django, write your own custom management commands (but again, I question the wisdom of this).

How to copy a database using RDS

I have a database instance on RDS with 2 databases on it. Is there a good way using the RDS command line tools to copy the one database to the other? If not, what is the recommended way of doing it?
This is not an exact solution to the OP, but if all you need is to clone an existing database for a new purpose, there's an easier way. You can take a snapshot from the original RDS instance, then restore it to a new instance. You can even use the web console.
I'd use mysqldump to get the tables and then mysql to import them.
Update 2014/07/08: Depending on what you're planning to do here, another solution today is to setup replication and then to promote the slave to be the master. That is for example if you want to update your database's release/version:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html
If you're looking to backup externally, there's also replication:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Exporting.NonRDSRepl.html
RDS has come a long way.
it depends on which database you are hosting there - for SQL Server I have used the SQL Azure Migration wizard (free download from CodePlex).
To get full RDBMS functionality the trick is to use the DNS name of your SQL Server instance in the wizard, but select 'SQL Server v2008' (or eventually v2012 after AWS RDS makes instances with 2012 available) and do NOT select to-->'SQL Azure'. I did a short screencast on this on my blog as well.