Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making DB backups in rails 4 [closed]

There is a gem db2fog but it works only with Rails 3.
Is there anyting suitable for making databases backups in Rails 4?

like image 269
Alex Tonkonozhenko Avatar asked Mar 04 '14 23:03

Alex Tonkonozhenko


1 Answers

Take a look to Backup gem. It provides a very nice set of features like:

  • Databases support: MySQL, MongoDB, PostgreSQL, Redis ...
  • Compression
  • Encryption
  • Storages: Amazon S3, Local, RSync, Dropbox ...
  • Notifiers: Email, Twitter, Hipchat ...
  • Friendly DSL

The plugin is totally independent to Rails, so you can use it for other applications.

Backup model example (MySQL, Amazon, Gzip and email notifications):

Model.new(:my_backup, 'My backup description') do
  database MySQL do |db|
    db.name     = "database_name"
    db.username = "username"
    db.password = "pass"
    db.host     = "localhost"
    db.port     = 3306
  end

  store_with S3 do |s3|
    s3.access_key_id     = "access_key_id"
    s3.secret_access_key = "secret_access_key"
    s3.bucket            = "bucket_name"
    s3.path              = "path/to/your/backups"
  end

  compress_with Gzip

  notify_by Mail do |mail|
    mail.on_success     = true
    mail.on_warning     = true
    mail.on_failure     = true

    mail.from           = "[email protected]"
    mail.to             = "[email protected]"
    mail.address        = "smtp.gmail.com"
    mail.port           = 587
    mail.domain         = "your.host.name"
    mail.user_name      = "[email protected]"
    mail.password       = "pass"
    mail.authentication = "plain"
  end
end

Perform the backup:

$ backup perform --trigger my_backup

Schedule your backups with a cron job (for example with whenever gem) and you'll achieve a simple and effective solution:

every 1.day, :at => '1:00 am' do
  command "backup perform --trigger my_backup"
end

Hope this can help you.

like image 102
markets Avatar answered Oct 07 '22 21:10

markets