rails_simple_backup_restore 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_simple_backup_restore.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Michael Witrant
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,96 @@
1
+ # RailsSimpleBackupRestore
2
+
3
+ A simple backup/restore gem for Rails.
4
+
5
+ How it works:
6
+
7
+ `SimpleBackup.backup`:
8
+
9
+ * the database is dumped to `db/data.yml` with [yaml_db](http://rubygems.org/gems/yaml_db)
10
+ * a temporary zip file is created with:
11
+ * `config/backup_version`
12
+ * `db/data.yml`
13
+ * all files listed in `config/backup_files` (each line being expanded with `Dir[line_of_backup_files]`)
14
+ * the temporary file object is returned (it may already have been removed from disk, but you can `#read` it)
15
+
16
+ `SimpleBackup.restore(file)`:
17
+
18
+ * check that the file is a ZIP and contains the same `config/backup_version`
19
+ * delete all files listed in `config/backup_files` (each line being expanded with `Dir[line_of_backup_files]`)
20
+ * extract all files included in the ZIP file
21
+ * load the database dump
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'rails_simple_backup_restore'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install rails_simple_backup_restore
36
+
37
+ ## Usage
38
+
39
+ Create a file config/backup_version with, for example :
40
+
41
+ my rails app backup v1
42
+
43
+ Create a file config/backup_files with, for example :
44
+
45
+ public/system/**/*
46
+
47
+ In your controller:
48
+
49
+ def backup
50
+ send_data SimpleBackup.backup.read, :filename => "Backup.zip"
51
+ end
52
+
53
+ def restore
54
+ if params[:file]
55
+ @done = true
56
+ begin
57
+ SimpleBackup.restore(params[:file])
58
+ @success = true
59
+ rescue => e
60
+ @error = e.message
61
+ end
62
+ end
63
+ end
64
+
65
+ In the restore view (haml syntax, twitter bootstrap style):
66
+
67
+ - if @done
68
+ - if @success
69
+ .alert.alert-block.alert-success
70
+ %p
71
+ %strong Restauration done!
72
+ - else
73
+ .alert.alert-block.alert-error
74
+ %p
75
+ %strong= "An error occured during restore"
76
+ %p
77
+ = @error
78
+
79
+ = form_tag restore_path, :class => "form-horizontal", :multipart => true do
80
+ %fieldset
81
+ %legend Restore
82
+ .control-group
83
+ = label_tag :file, "Backup file", :class => "control-label"
84
+ .controls
85
+ = file_field_tag :file, :class => "input-file"
86
+ .form-actions
87
+ = submit_tag "Restore backup", :class => "btn btn-primary"
88
+
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require "rails_simple_backup_restore/version"
2
+
3
+ module RailsSimpleBackupRestore
4
+ class Engine < Rails::Engine
5
+ config.autoload_paths << File.expand_path("../rails_simple_backup_restore", __FILE__)
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ module SimpleBackup
2
+ def self.init
3
+ require 'tmpdir'
4
+ require 'zip/zip'
5
+ require 'yaml_db'
6
+ end
7
+
8
+ def self.current_backup_files
9
+ files = []
10
+ backup_files_path = Rails.root.join("config", "backup_files")
11
+ if backup_files_path.exist?
12
+ backup_files_path.each_line do |line|
13
+ Dir[line.strip].each do |path|
14
+ next if File.directory?(path)
15
+ files << path
16
+ end
17
+ end
18
+ end
19
+ files
20
+ end
21
+
22
+ def self.db_dump_path
23
+ "db/data.yml"
24
+ end
25
+
26
+ def self.backup
27
+ init
28
+
29
+ input_filenames = ["config/backup_version"]
30
+
31
+ SerializationHelper::Base.new(YamlDb::Helper).dump db_dump_path
32
+
33
+ input_filenames << db_dump_path
34
+
35
+ input_filenames += current_backup_files
36
+
37
+ zip = nil
38
+ Dir.mktmpdir 'simple_backup' do |dir|
39
+ zip_path = File.join(dir, "backup.zip")
40
+ Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) do |zipfile|
41
+ input_filenames.each do |filename|
42
+ zipfile.add(filename, Rails.root.join(filename))
43
+ end
44
+ end
45
+ zip = File.open(zip_path, 'r')
46
+ end
47
+ zip
48
+ end
49
+
50
+ def self.restore(file)
51
+ init
52
+
53
+ Dir.mktmpdir 'simple_restore' do |dir|
54
+ Zip::ZipFile.open(file.path) do |zip|
55
+ version = zip.find_entry "config/backup_version"
56
+ raise "Invalid a backup file" unless version
57
+ current_version = File.read("config/backup_version")
58
+ raise "Backup version mismatch" if current_version != zip.read("config/backup_version")
59
+
60
+ current_backup_files.each do |file|
61
+ File.delete(file)
62
+ end
63
+
64
+ zip.each do |entry|
65
+ File.open(entry.name, "wb") { |f| f.write entry.get_input_stream.read }
66
+ end
67
+
68
+ SerializationHelper::Base.new(YamlDb::Helper).load db_dump_path
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ module RailsSimpleBackupRestore
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rails_simple_backup_restore/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ouvrages"]
6
+ gem.email = ["contact@ouvrages-web.fr"]
7
+ gem.description = %q{A simple backup/restore gem for Rails}
8
+ gem.summary = %q{Backup the database and custom paths into a single file and allow restore}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "rails_simple_backup_restore"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = RailsSimpleBackupRestore::VERSION
17
+ gem.add_dependency 'yaml_db'
18
+ gem.add_dependency 'rails', '>= 3.0'
19
+ gem.add_dependency 'rubyzip'
20
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_simple_backup_restore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ouvrages
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yaml_db
16
+ requirement: &88584140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *88584140
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &88583870 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *88583870
36
+ - !ruby/object:Gem::Dependency
37
+ name: rubyzip
38
+ requirement: &88583620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *88583620
47
+ description: A simple backup/restore gem for Rails
48
+ email:
49
+ - contact@ouvrages-web.fr
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/rails_simple_backup_restore.rb
60
+ - lib/rails_simple_backup_restore/simple_backup.rb
61
+ - lib/rails_simple_backup_restore/version.rb
62
+ - rails_simple_backup_restore.gemspec
63
+ homepage: ''
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.11
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Backup the database and custom paths into a single file and allow restore
87
+ test_files: []