简体   繁体   中英

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

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

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 "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM