Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Ruby) How to dump a database?

I want to do a database dump through Ruby scripting, but I didn't find any class or script for do that.

Ideally the dump should work for MySQL, PostgreSQL, SQLite, etc. (at least MySql and Pg). I tried with DBI but I can't.

Other way is doing table for table ... D:

Edit 1: It's only for backup, no restore. For now I have troubles with hostings, because I need to ask for permits to my IP, so I will try with SSH.

like image 959
José Castro Avatar asked Jan 26 '26 06:01

José Castro


2 Answers

How about using exec in your script to run the mysqldump app?

exec 'mysqlinstalldir/bin/mysqldump -u username -ppassword --databases databasename'

You should be able to do the same with Postgresql and pg_dump

like image 137
Jason Slocomb Avatar answered Jan 27 '26 22:01

Jason Slocomb


you can use your system tools for taking dump of database,run this script in your code may be a rake task

system "mysqldump database_name table1 table2 -u root -p password > path/to/dump/file "
like image 23
Naveed Avatar answered Jan 28 '26 00:01

Naveed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!