onaio / ona-tech

Ona Tech related documentation and discussions
Other
3 stars 0 forks source link

database backup to load into dev machine #41

Closed pld closed 10 years ago

pld commented 10 years ago

@ukanga is there a db dump and any instructions for loading a production dump into my local database?

Thanks, Peter

ukanga commented 10 years ago

Get into ona.io

$ ssh ubuntu@ona.io

Run the backup restore for postgres as root, file is placed in /home/ubuntu/backups/postgres/onadata.sql

$ sudo su -
# onadata_backup restore postgres
# logout

Compress backup sql before tranfering to your local machine

$ tar -czvf onadata.sql.tar.gz backups/postgres/onadata.sql 

import db into an existing database onadata, note, this drops tables and recreates them if any exists

$ tar -xzvf onadata.sql.tar.gz
$ psql -U onadata -h 127.0.0.1 onadata -f backups/postgres/onadata.sql

Alternatively if you can export the gpg keys in the root user on ona.io and import into your local machine, you can use https://github.com/ukanga/duplicity-backup to retrieve backups directly from S3. You will also have to copy over /root/.backup_config and make changes where necessary from ona.io.

pld commented 10 years ago

OK, sweet, in what is probably a predictable fashion I created a script to do the 2nd half of these commands, https://github.com/onaio/onadata/blob/5de89c2d6e5d926947888c9a05dd61bbec727785/script/database/load_backup

It assumes you have an ssh config entry called ona and private key set up correctly, we can improve this in the future, closes #41.

On Tue, Jan 21, 2014 at 3:35 PM, ukanga notifications@github.com wrote:

Get into ona.io

$ ssh ubuntu@ona.io

Run the backup restore for postgres as root, file is placed in /home/ubuntu/backups/postgres/onadata.sql

$ sudo su -

onadata_backup restore postgres

logout

Compress backup sql before tranfering to your local machine

$ tar -czvf onadata.sql.tar.gz backups/postgres/onadata.sql

import db into an existing database onadata, note, this drops tables and recreates them if any exists

$ tar -xzvf onadata.sql.tar.gz $ psql -U onadata -h 127.0.0.1 onadata -f backups/postgres/onadata.sql

Alternatively if you can export the gpg keys in the root user on ona.ioand import into your local machine, you can use https://github.com/ukanga/duplicity-backup to retrieve backups directly from S3. You will also have to copy over /root/.backup_config and make changes where necessary from ona.io.

— Reply to this email directly or view it on GitHubhttps://github.com/onaio/ona-tech/issues/41#issuecomment-32960375 .

pld commented 10 years ago

boo, I thought I could close it with a comment, fine, I'll click the button.