Tuesday 20 September 2016

Ruby On Rails Database Backup and Restore


MySQL


You can backup your MySQL data by using the mysqldump command. This command connects to the MySQL server and creates an SQL dump file. The dump file contains the SQL statements necessary to re-create the database.


Backup:

mysqldump -u user -p database_name > dump.sql
(Enter password)

Restore:

mysql -u user -p new_database_name < dump.sql
(Enter password)



Postgres Database backup and Restore to dump file

Here is the quick snippet of how backup and restore postgres database 

Backup:

1

"pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"

Restore:

1

"pg_restore --verbose --host #{host} --username #{user} --clean --no-owner --no-acl --dbname #{db} #{Rails.root}/db/#{app}.dump”


Postgres Database backup and Restore to sql file



Backup:

1

$ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}

Restore:

1

psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}


No comments:

Post a Comment