Giter VIP home page Giter VIP logo

rails-backup-migrate's Introduction

Rails Backup Migrate

A gem that provides a rake task for backing up your database and uploaded files to an archive and restoring them from an archive.

You can archive schema, schema+data, files, or schema+data+files. Each archive action has a restore counterpart. The data from the database is backed up to a .yml file for each table that is database independent.

So you can use Rails Backup Migrate to get data out of one kind of database and easily load it into another kind.

Quick Start

Installing the gem:

  $ gem install rails-backup-migrate

Add the following line to your rails application’s Rakefile

  require 'rails-backup-migrate'

To backup everything in a rails instance:

  $ rake site:backup

Everything is saved in an archive file, named by default ‘site-backup.tgz’. Copy/move this to another rails instance

  $ rake site:restore

More info

The backup file can be specified with a command line argument in rake’s (wierd) format:

  $ rake site:backup[/path/to/file.tgz]

Compatibility

Tested initially on ‘redmine’ using rails 2.3.11 and some simpler tests with rails 3. Has been tested with MySQL and Sqlite3 databases. Further testing with postgres to be done.

Also tested with a dummy rails 3.0 app using sqlite3 driver in ruby 1.8.7, 1.9.2 and jruby 1.6.2.

This requires a system with access to the `tar` command in your path. (Easy for Mac & *nixes, may require a posix environment such as cygwin under Windows.)

Known Issues:

- under ruby 1.9.2, the YAML export (in the `rake site:backup` task fails extended characters in ASCII to UTF8 conversion) (Github Issue #4) Changes made in 0.0.9 that look like this is fixed – any help regressing is welcome!

Contributors

Matt Connolly – main author of gem
Tobias Lütke – wrote a `backup.rake` file that inspired the database backup portion.

License

GPL – See LICENSE

rails-backup-migrate's People

Contributors

halida avatar mattconnolly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rails-backup-migrate's Issues

Tar Wouldn't Accepted Wildcards on Ubuntu

When restoring a database the _restore_db_from_yml task would fail with the following error:

"tar: Pattern matching characters used in file names. Please use --wildcards to enable pattern matching."

This can be fixed by changing line 90 of rails-backup-migrate.rake to:

`tar #{options} #{RailsBackupMigrate.backup_file} --wildcards 'db/backup/*.yml'`

Ubuntu Version = 11.04

File 'files' does not exist

Here is the trace:

iMac-001EC20A3C44-3:suthu steven$ rake site:backup --trace
(in /Users/steven/Code/suthu)
** Invoke site:backup (first_time)
** Invoke site:backup:_save_db_schema (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
** Execute site:backup:_save_db_schema
** Invoke site:backup:_save_db_to_yml (first_time)
** Invoke environment
** Execute site:backup:_save_db_to_yml
** Invoke site:backup:_add_files_directory_to_archive (first_time)
** Execute site:backup:_add_files_directory_to_archive
rake aborted!
File 'files' does not exist
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rails-backup-migrate-0.0.7/lib/rails-backup-migrate.rb:43:in add_to_archive' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rails-backup-migrate-0.0.7/lib/tasks/rails-backup-migrate.rake:38:inblock (3 levels) in <top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in call' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:inblock in execute'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in each' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:inexecute'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:597:in block in invoke_with_call_chain' /Users/steven/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:inmon_synchronize'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:607:inblock in invoke_prerequisites'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:604:in each' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:604:ininvoke_prerequisites'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:596:in block in invoke_with_call_chain' /Users/steven/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:inmon_synchronize'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:583:ininvoke'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:inblock (2 levels) in top_level'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in each' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:inblock in top_level'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2023:intop_level'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2001:in block in run' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:1998:in run' /Users/steven/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/bin/rake:31:in<top (required)>'
/Users/steven/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in load' /Users/steven/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in

'

uninitialized constant Mysql

here is the trace:

 $ rake site:backup:db --trace
(in /data/workspace/gurudigger)
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Gmaps4rails::ActsAsGmappable instead. (called from <top (required)> at /data/workspace/gurudigger/config/application.rb:11)
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/resque-1.20.0/lib/resque/helpers.rb:5:in `<top (required)>': [DEPRECATION] MultiJson.engine is deprecated and will be removed in the next major version. Use MultiJson.adapter instead.
** Invoke site:backup:db (first_time)
** Invoke site:backup:_save_db_schema (first_time)
** Invoke environment (first_time)
** Invoke disable_rails_admin_initializer (first_time)
** Execute disable_rails_admin_initializer
** Execute environment
** Invoke db:schema:dump (first_time)
** Invoke environment 
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:schema:dump
** Execute site:backup:_save_db_schema
** Invoke site:backup:_save_db_to_yml (first_time)
** Invoke environment 
** Execute site:backup:_save_db_to_yml
rake aborted!
uninitialized constant Mysql
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:118:in `block (4 levels) in save_db_to_yml'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:116:in `each'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:116:in `inject'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:116:in `block (3 levels) in save_db_to_yml'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:115:in `map!'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:115:in `block (2 levels) in save_db_to_yml'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:110:in `open'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:110:in `block in save_db_to_yml'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:108:in `each'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/rails-backup-migrate.rb:108:in `save_db_to_yml'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rails-backup-migrate-0.0.11/lib/tasks/rails-backup-migrate.rake:30:in `block (3 levels) in <top (required)>'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/halida/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/home/halida/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/halida/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/halida/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `load'
/home/halida/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `<main>'
Tasks: TOP => site:backup:db => site:backup:_save_db_to_yml

here is my gem:

gem 'mysql2', '>= 0.3'

is it my problem?

require 'rake' line missing from rails-backup-migrate.rake

After installing this gem the rails generator would throw an error:
~/.rvm/gems/ruby-2.6.3/gems/rails-backup-migrate-0.0.12/lib/tasks/rails-backup-migrate.rake:14:in '<main>': undefined method 'namespace' for main:Object (NoMethodError)
I fixed this by adding the line require 'rake' to the file ~/.rvm/gems/ruby-2.6.3/gems/rails-backup-migrate-0.0.12/lib/tasks/rails-backup-migrate.rake before all of the other require statements
This should probably be fixed in the gem itself
for reference, I'm using:
Rails: 5.2.3
Ruby: 2.6.3
Bundler: 1.17.2

README's 'Rakefile' should be 'Gemfile'

The README says:
Add the following line to your rails application’s Rakefile
require 'rails-backup-migrate'

It should say instead
Add the following line to your rails application’s Gemfile
require 'rails-backup-migrate'

MySQL Time is not resolved in YAML

The generated .yml files doesn't contain the right values for time fields in a mysql database. For example the created_at and updated_at fields.

Here is a part from a yml file:
updated_at: !ruby/object:Mysql::Time {}

ActiveRecord::Base.connection.select_all generate an array with hashes. The value for the time fields in the hashes is a Mysql::Time instead of an string. I think YAML.dump can't convert an instance from Mysql::Time into a string.

It would be nice, if you can fix this bug.

Character set conversion

When I tried it in a Ubuntu environment (admittedly hosted via VirtualBox in Windows 7 64-bit), I got::

rake aborted!
“\xE2″ from ASCII-8BIT to UTF-8

I looked at my database.yml and they’re set to utf8 and the collation on the database tables is “utf8_unicode_ci.” Mysql is running in the Ubuntu machine.

The directory with files should be configurable

The folder 'files' that is hardcoded at the moment should be configurable. All my applications use the folder 'system' for alle the files such as user pictures.

So the possibility to define the folder name, which should packed into the backup archive, would be fine :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.