backup_data 1.0.0

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,2 @@
1
+ pkg/**
2
+ nbproject
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Kris Leech
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,18 @@
1
+ Database Backup Plugin
2
+ ======================
3
+
4
+ Engine style plugin which allow a user (usually admin) to manually backup the database and files themselves.
5
+
6
+ It uses the connection details in database.yml.
7
+
8
+ Create a routes like so:
9
+
10
+ map.admin_backup_database '/admin/backup/database', :controller => 'admin/backups', :action => 'database'
11
+ map.admin_backup_files '/admin/backup/files', :controller => 'admin/backups', :action => 'files'
12
+ map.admin_backup '/admin/backup', :controller => 'admin/backups'
13
+
14
+ The Admin::BackupsController inherits from Admin::AdminController, this may not fit with your app.
15
+
16
+ However if you install this as a plugin this is easily changed.
17
+
18
+ Copyright (c) 2010 Kris Leech, released under the MIT license
@@ -0,0 +1,38 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the backup_data plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the backup_data plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'BackupData'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = "backup_data"
29
+ gemspec.summary = "Backup Files and Database Rails Engine"
30
+ gemspec.description = "Backup and Compress Files and Database (mysql only) and send to user as a file (Rails Engine)"
31
+ gemspec.email = "kris.leech@interkonect.com"
32
+ gemspec.homepage = "http://github.com/krisleech/backup_data"
33
+ gemspec.authors = ["Kris Leech"]
34
+ end
35
+ Jeweler::GemcutterTasks.new
36
+ rescue LoadError
37
+ puts "Jeweler not available. Install it with: gem install jeweler"
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,75 @@
1
+ # TODO: Remove inheritence to Admin::AdminController
2
+ # Move to background task
3
+ # Settings prefrences (ie. mysql and zip commands)
4
+ class Admin::BackupsController < Admin::AdminController
5
+ def index
6
+ end
7
+
8
+ def database
9
+ connection = YAML.load_file(File.join(RAILS_ROOT, 'config', 'database.yml'))[params[:env] || RAILS_ENV]
10
+ render :text => 'Database must be MySQL' and return unless connection['adapter'] == 'mysql'
11
+
12
+ target_file = RAILS_ROOT + '/tmp/backup.sql'
13
+ File.delete(target_file) if File.exists? target_file
14
+
15
+ cmd = build_command(connection, target_file)
16
+
17
+ if system("#{cmd}")
18
+ send_file target_file, :filename => "#{connection['database']}_#{Time.now.strftime('%d-%m-%y')}.sql"
19
+ else
20
+ render :text => "#{cmd} <br>Backup failed!" and return
21
+ end
22
+ end
23
+
24
+ def files
25
+ if request.post?
26
+ paths = []
27
+ errors = []
28
+
29
+ params[:paths].each do |path|
30
+ next if path.blank?
31
+ path = File.join(RAILS_ROOT, 'public', path)
32
+ if File.exists? path
33
+ paths << path
34
+ else
35
+ errors << "Path does not exist: #{path}"
36
+ end
37
+
38
+ errors << 'No paths given' if paths.empty?
39
+
40
+ unless errors.empty?
41
+ render :text => errors.inspect and return
42
+ end
43
+ end
44
+
45
+ # archive
46
+ target_file = RAILS_ROOT + '/tmp/backup.zip'
47
+ File.delete(target_file) if File.exists? target_file
48
+
49
+ paths.each do |p|
50
+
51
+ cmd = "zip -r9 #{target_file} #{p}"
52
+ unless system("#{cmd}")
53
+ errors << "Failed to add: #{p}"
54
+ end
55
+ end
56
+
57
+ filename = params[:filename] || 'files'
58
+
59
+ if errors.empty?
60
+ send_file target_file, :filename => "#{filename}_#{Time.now.strftime('%d-%m-%y')}.zip"
61
+ else
62
+ render :text => "#{errors.inspect} <br>Backup failed!" and return
63
+ end
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def build_command(connection, filename)
70
+ pswd = "-p" + connection['password'] unless connection['password'].blank?
71
+ user = "-u" + connection['username'] unless connection['username'].blank?
72
+ options = "#{pswd} #{user}"
73
+ "mysqldump #{options} #{connection['database']} > #{filename}"
74
+ end
75
+ end
@@ -0,0 +1,25 @@
1
+ <% form_tag admin_backup_files_path, :method => :post do %>
2
+ <% 10.times do |ctr| %>
3
+ <p>Path:<input type="text" value="" name="paths[]" /></p>
4
+ <% end %>
5
+ <%= submit_tag 'Backup' %>
6
+ <% end %>
7
+
8
+
9
+ <hr>
10
+
11
+ <% form_tag admin_backup_files_path, :method => :post do %>
12
+
13
+ <input type="hidden" value="stylesheets" name="paths[]" />
14
+ <input type="hidden" value="javascripts" name="paths[]" />
15
+ <input type="hidden" value="js_and_css" name="filename" />
16
+ <p>Stylesheets and Javascript: <%= submit_tag 'Backup' %></p>
17
+ <% end %>
18
+
19
+ <% form_tag admin_backup_files_path, :method => :post do %>
20
+
21
+ <input type="hidden" value="/" name="paths[]" />
22
+ <input type="hidden" value="everything" name="filename" />
23
+ <p>Everything: <%= submit_tag 'Backup' %></p>
24
+ <small><%= File.size(File.join(RAILS_ROOT, 'public')) %> Kb</small>
25
+ <% end %>
@@ -0,0 +1,19 @@
1
+
2
+
3
+ <% form_tag admin_backup_database_path, :method => :post do %>
4
+ <p>Database: <%= submit_tag 'Backup' %></p>
5
+ <% end %>
6
+
7
+ <% form_tag admin_backup_files_path, :method => :post do %>
8
+ <input type="hidden" value="stylesheets" name="paths[]" />
9
+ <input type="hidden" value="javascripts" name="paths[]" />
10
+ <input type="hidden" value="js_and_css" name="filename" />
11
+ <p>Stylesheets and Javascript: <%= submit_tag 'Backup' %></p>
12
+ <% end %>
13
+
14
+ <% form_tag admin_backup_files_path, :method => :post do %>
15
+ <input type="hidden" value="/" name="paths[]" />
16
+ <input type="hidden" value="everything" name="filename" />
17
+ <p>All files: <%= submit_tag 'Backup' %></p>
18
+ <small><%= File.size(File.join(RAILS_ROOT, 'public')) %> Kb</small>
19
+ <% end %>
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{backup_data}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kris Leech"]
12
+ s.date = %q{2010-08-27}
13
+ s.description = %q{Backup and Compress Files and Database (mysql only) and send to user as a file (Rails Engine)}
14
+ s.email = %q{kris.leech@interkonect.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "app/controllers/admin/backups_controller.rb",
25
+ "app/views/admin/backups/files.html.erb",
26
+ "app/views/admin/backups/index.html.erb",
27
+ "backup_data.gemspec",
28
+ "init.rb",
29
+ "install.rb",
30
+ "lib/backup_data.rb",
31
+ "rails/init.rb",
32
+ "test/backup_database_test.rb",
33
+ "test/test_helper.rb",
34
+ "uninstall.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/krisleech/backup_data}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Backup Files and Database Rails Engine}
41
+ s.test_files = [
42
+ "test/backup_database_test.rb",
43
+ "test/test_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ else
52
+ end
53
+ else
54
+ end
55
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,3 @@
1
+ module BackupData
2
+ VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
3
+ end
File without changes
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BackupDatabaseTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backup_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kris Leech
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-08-27 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Backup and Compress Files and Database (mysql only) and send to user as a file (Rails Engine)
17
+ email: kris.leech@interkonect.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - .gitignore
26
+ - MIT-LICENSE
27
+ - README
28
+ - Rakefile
29
+ - VERSION
30
+ - app/controllers/admin/backups_controller.rb
31
+ - app/views/admin/backups/files.html.erb
32
+ - app/views/admin/backups/index.html.erb
33
+ - backup_data.gemspec
34
+ - init.rb
35
+ - install.rb
36
+ - lib/backup_data.rb
37
+ - rails/init.rb
38
+ - test/backup_database_test.rb
39
+ - test/test_helper.rb
40
+ - uninstall.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/krisleech/backup_data
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.5
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Backup Files and Database Rails Engine
69
+ test_files:
70
+ - test/backup_database_test.rb
71
+ - test/test_helper.rb