# MySQL backup using rails

**URL:** <https://www.ruby-forum.com/t/mysql-backup-using-rails/117996>\
**Category:** Rails\
**Created:** [October 23, 2007, 10:09am UTC](https://www.ruby-forum.com/t/mysql-backup-using-rails/117996 "2007-10-23T10:09:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [October 23, 2007, 10:09am UTC](https://www.ruby-forum.com/t/mysql-backup-using-rails/117996/1 "2007-10-23T10:09:59Z")

</div>

Hi,

I want to backup and restore my database using Ruby code.

Does any one can give an idea of how to do this.

My requirement is the Admin who is logged in to the application  
should be able to create a backup of the database available.

How can i do this.

Thanks  
Jagan

---

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [October 23, 2007, 10:37am UTC](https://www.ruby-forum.com/t/mysql-backup-using-rails/117996/2 "2007-10-23T10:37:40Z")

</div>

Hi,

2007/10/23, Jagan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,
> 
> I want to backup and restore my database using Ruby code.

Does any one can give an idea of how to do this.

You can use “mysqldump” [1] console program for database backup.  
(execute it  
with right arguments)  
For import you can use “mysqlimport” [2].

My requirement is the Admin who is logged in to the application

> should be able to create a backup of the database available.

When click to backup button, you execute mysqldump program to backup and  
save file to “public/backups/#{date…}”. It is better you save some  
information about backup to “backups” table.

For import, list files in “public/backups” (if you use “backups” table  
it is  
easier to list records). When selected some file, you send it to  
mysqlimport  
as a argument.

Links:  
[1] [http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html](http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html)  
[2] [http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html](http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html)

Regards,  
Murat

–

* * *

Murat Ã‚rif Ã‡ELÄ°KER \< [http://www.ikinoktayazilim.com/wordpress](http://www.ikinoktayazilim.com/wordpress) \>  
Ä°kinokta YazÄ±lÄ±m, Bursa  
[http://www.ikinoktayazilim.com](http://www.ikinoktayazilim.com)

---

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [October 23, 2007, 1:35pm UTC](https://www.ruby-forum.com/t/mysql-backup-using-rails/117996/3 "2007-10-23T13:35:59Z")

</div>

On 10/23/07, Murat Arif ÇELÝKER [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You can use “mysqldump” [1] console program for database backup. (execute it  
> with right arguments)  
> For import you can use “mysqlimport” [2].

Since this seems to be for an online ‘hot’ backup. Careful attention  
needs to be paid to getting a consistent backup in the face of  
concurrency.

I think that this means a little study of the implications of options  
like:

–lock-tables  
–lock-all-tables  
and  
–single-transaction

## on mysqldump. Note also that things change depending on wheter the table is InnoDB, MyIsam or whatever.

Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
