Search code examples
mysqlrubydatabasepostgresqldump

(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.


Solution

  • 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