rosie 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -5
- data/lib/rosie.rb +5 -7
- data/lib/rosie/version.rb +1 -1
- data/lib/tasks/rosie.rake +26 -13
- metadata +25 -5
data/README.md
CHANGED
@@ -8,7 +8,7 @@ The gem provides two rake tasks which will backup or restore a MySQL database al
|
|
8
8
|
|
9
9
|
## Requirements
|
10
10
|
|
11
|
-
*
|
11
|
+
* Rails (2.3.x or 3.x)
|
12
12
|
* MySQL > 5 with commandline tools (mysql, mysqladmin, mysqldump)
|
13
13
|
* Unix(ish) system shell with tar
|
14
14
|
|
@@ -26,6 +26,18 @@ Use bundler to install it:
|
|
26
26
|
bundle install
|
27
27
|
</pre>
|
28
28
|
|
29
|
+
### Rails 2.3.x
|
30
|
+
If you're using Rails 2, you'll need to add a couple lines to your `Rakefile`.
|
31
|
+
After all the requires, add the following:
|
32
|
+
|
33
|
+
<code><pre>
|
34
|
+
|
35
|
+
require 'rosie'
|
36
|
+
|
37
|
+
Dir["#{Gem.searcher.find('rosie').full_gem_path}/lib/tasks/**/*.rake"].each { |ext| load ext }
|
38
|
+
|
39
|
+
</pre></code>
|
40
|
+
|
29
41
|
## Configuration
|
30
42
|
|
31
43
|
Configuration values can be set by placing a rosie.yml file in your config directory. Default keys and values are as follows:
|
@@ -34,13 +46,14 @@ Configuration values can be set by placing a rosie.yml file in your config direc
|
|
34
46
|
# sample rosie.yml
|
35
47
|
#
|
36
48
|
backup_dir:backups
|
37
|
-
|
49
|
+
assets_dirs:
|
50
|
+
- public/system
|
38
51
|
mysql_bin_dir:
|
39
52
|
|
40
53
|
</pre>
|
41
54
|
|
42
55
|
* `backup_dir`: This specifies the directory where the backup files will be stored. It should be specified relative to your Rails root. This setting would give you `#{Rails.root}/backups`.
|
43
|
-
* `
|
56
|
+
* `assets_dirs`: This specifies the directorys which hold system assets you want to be added to the backup file. All entries should be specified relative to your Rails root.
|
44
57
|
* `mysql_bin_dir`: If mysql and mysqldump are not on the path of the user running this rake task, you may need to specify the directory where those commandline applications live. This should be an absolute path. By default, Rosie will try to find these in the user's PATH.
|
45
58
|
|
46
59
|
The generated backup files (zipped tarballs) will be named by timestamp and placed in `backup_dir`.
|
@@ -63,7 +76,9 @@ Rosie Config: read from /projects/boilerplate/config/rosie.yml
|
|
63
76
|
mysql: mysql
|
64
77
|
mysqldump: mysqldump
|
65
78
|
backup dir: /projects/boilerplate/my_backups
|
66
|
-
assets
|
79
|
+
assets dirs:
|
80
|
+
- public/my_assets
|
81
|
+
- public/my_other_assets
|
67
82
|
</pre></code>
|
68
83
|
|
69
84
|
|
@@ -92,7 +107,6 @@ Tested with Ruby 1.9.2-p180 on OSX 10.6/Ubuntu 10.10/11
|
|
92
107
|
|
93
108
|
## TODO
|
94
109
|
* add ability to backup remote databases (not on localhost)
|
95
|
-
* make Rails2.3.x compatible
|
96
110
|
* add alternate database support
|
97
111
|
|
98
112
|
## Credits
|
data/lib/rosie.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
rootpath = File.join(File.dirname(__FILE__),'..')
|
2
2
|
require File.join(rootpath, 'lib/rosie/version')
|
3
3
|
|
4
|
-
|
4
|
+
if /^3\./.match Rails.version
|
5
|
+
Dir[File.join(rootpath, "lib/tasks/**/*.rake")].each { |ext| load ext } if defined?(Rake)
|
6
|
+
end
|
5
7
|
|
6
8
|
module Rosie
|
7
9
|
class Config
|
8
|
-
@@allowed_attributes = [:backup_dir, :
|
10
|
+
@@allowed_attributes = [:backup_dir, :assets_dirs, :mysql_bin_dir, :config_file]
|
9
11
|
|
10
12
|
attr_accessor *@@allowed_attributes
|
11
13
|
|
12
14
|
def initialize
|
13
|
-
_config = {"backup_dir"=>"backups", "
|
15
|
+
_config = {"backup_dir"=>"backups", "assets_dirs"=> ["public/system"], "mysql_bin_dir"=>nil}
|
14
16
|
self.config_file = File.join(Rails.root, 'config/rosie.yml')
|
15
17
|
if File.exists? self.config_file
|
16
18
|
_config.merge!(YAML.load(File.open(self.config_file)))
|
@@ -24,10 +26,6 @@ module Rosie
|
|
24
26
|
File.join(Rails.root, @backup_dir)
|
25
27
|
end
|
26
28
|
|
27
|
-
def assets_dir
|
28
|
-
File.join(Rails.root, @assets_dir)
|
29
|
-
end
|
30
|
-
|
31
29
|
def mysql_cmd
|
32
30
|
mysql_bin_dir.present? ? File.join(mysql_bin_dir, 'mysql') : 'mysql'
|
33
31
|
end
|
data/lib/rosie/version.rb
CHANGED
data/lib/tasks/rosie.rake
CHANGED
@@ -32,29 +32,30 @@ namespace :rosie do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
desc "show config"
|
35
|
-
task :config => :init do
|
35
|
+
task :config => 'rosie:init' do
|
36
36
|
puts "Rosie Config: read from #{rosie.config_file}"
|
37
37
|
puts "mysql: #{rosie.mysql_cmd}"
|
38
38
|
puts "mysqldump: #{rosie.mysqldump_cmd}"
|
39
39
|
puts "backup dir: #{rosie.backup_dir}"
|
40
|
-
puts "assets
|
40
|
+
puts "assets dirs: #{rosie.assets_dirs.join(', ')}"
|
41
41
|
end
|
42
42
|
|
43
43
|
desc "restore data from backup tarball"
|
44
|
-
task :restore => :init do
|
44
|
+
task :restore => 'rosie:init' do
|
45
45
|
puts "Restoring data..."
|
46
46
|
tarball = ENV["datafile"]
|
47
47
|
if tarball.present?
|
48
|
-
tarball = File.
|
48
|
+
tarball = File.expand_path(tarball)
|
49
49
|
tmp = File.join(Dir.tmpdir, "rosie-restore")
|
50
50
|
FileUtils.remove_dir(tmp, true)
|
51
51
|
FileUtils.mkdir_p(tmp)
|
52
|
-
if !
|
52
|
+
if !File.exists?(tmp)
|
53
53
|
msg = "Unable to create a temporary directory. Please check your file permissions.\nAttempted to create #{tmp}"
|
54
54
|
raise msg
|
55
55
|
end
|
56
56
|
files_before = Dir.entries(tmp)
|
57
|
-
|
57
|
+
puts "Unpacking backup bundle"
|
58
|
+
`cd #{tmp} && tar -xzf #{tarball}`
|
58
59
|
ts = Dir.entries(tmp).reject{ |f| files_before.include? f }.first
|
59
60
|
unless ts.present?
|
60
61
|
puts "*** Something went wrong while trying to unpack the datafile."
|
@@ -65,7 +66,8 @@ namespace :rosie do
|
|
65
66
|
image_tarball = File.join(data_dir, Dir.entries(data_dir).select{|f| f =~ /#{ts}.*\.tar/}.first)
|
66
67
|
sql_dump = File.join(data_dir, Dir.entries(data_dir).select{|f| f =~ /#{ts}.*\.sql/}.first)
|
67
68
|
args = get_db_cmdline_args
|
68
|
-
|
69
|
+
puts "Restoring assets and database"
|
70
|
+
`tar -C #{Rails.root} -xf #{image_tarball} && #{rosie.mysql_cmd} #{args.join(' ')} #{dbcnf['database']} < #{sql_dump}`
|
69
71
|
|
70
72
|
else
|
71
73
|
puts "*** You must specify the datafile from which to restore"
|
@@ -76,24 +78,35 @@ namespace :rosie do
|
|
76
78
|
|
77
79
|
desc "backup all data"
|
78
80
|
task :backup => ["rosie:backups:db", "rosie:backups:assets"] do
|
79
|
-
|
81
|
+
puts "Bundling backup files into #{ts}.tgz"
|
82
|
+
`cd #{rosie.backup_dir}/#{ts}/../ && tar -czf #{ts}.tgz ./#{ts} && rm -rf #{ts}`
|
80
83
|
end
|
81
84
|
|
82
85
|
namespace :backups do
|
83
86
|
task :init => 'rosie:init' do
|
84
|
-
ts = Time.now.strftime('%Y%m%d%H%
|
87
|
+
ts = Time.now.strftime('%Y%m%d%H%M%S')
|
85
88
|
end
|
86
89
|
|
87
|
-
task :db => :init do
|
90
|
+
task :db => 'rosie:backups:init' do
|
88
91
|
dbcnf = get_db_config
|
89
92
|
db_file = "#{dbcnf['database']}-#{ts}.backup.sql"
|
90
93
|
path = File.join(rosie.backup_dir, ts, db_file)
|
91
94
|
args = get_db_cmdline_args
|
92
|
-
|
95
|
+
puts "Dumping database #{dbcnf['database']}"
|
96
|
+
`mkdir -p #{rosie.backup_dir}/#{ts} && #{rosie.mysqldump_cmd} #{args.join(' ')} --single-transaction #{dbcnf['database']} > #{path}`
|
93
97
|
end
|
94
98
|
|
95
|
-
task :assets => :init do
|
96
|
-
|
99
|
+
task :assets => 'rosie:backups:init' do
|
100
|
+
tarball = "#{rosie.backup_dir}/#{ts}/rosie_backup_#{Rails.env}_#{ts}.tar"
|
101
|
+
rosie.assets_dirs.each_with_index do |dr, idx|
|
102
|
+
if File.exists?(dr)
|
103
|
+
puts "Backing up #{dr}"
|
104
|
+
tarargs = (idx==0) ? 'chf' : 'uhf'
|
105
|
+
sh "tar -C #{Rails.root} -#{tarargs} #{tarball} #{dr}"
|
106
|
+
else
|
107
|
+
puts "No directory #{dr} to backup"
|
108
|
+
end
|
109
|
+
end
|
97
110
|
end
|
98
111
|
|
99
112
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rosie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Jon Rogers
|
@@ -11,7 +16,8 @@ autorequire:
|
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
18
|
|
14
|
-
date: 2011-08-
|
19
|
+
date: 2011-08-21 00:00:00 -07:00
|
20
|
+
default_executable:
|
15
21
|
dependencies:
|
16
22
|
- !ruby/object:Gem::Dependency
|
17
23
|
name: rspec
|
@@ -21,6 +27,9 @@ dependencies:
|
|
21
27
|
requirements:
|
22
28
|
- - ">="
|
23
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
24
33
|
version: "0"
|
25
34
|
type: :development
|
26
35
|
version_requirements: *id001
|
@@ -32,6 +41,10 @@ dependencies:
|
|
32
41
|
requirements:
|
33
42
|
- - ~>
|
34
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 25
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 9
|
35
48
|
version: "0.9"
|
36
49
|
type: :development
|
37
50
|
version_requirements: *id002
|
@@ -55,6 +68,7 @@ files:
|
|
55
68
|
- lib/rosie/version.rb
|
56
69
|
- lib/tasks/rosie.rake
|
57
70
|
- rosie.gemspec
|
71
|
+
has_rdoc: true
|
58
72
|
homepage: http://github.com/2rye/rosie
|
59
73
|
licenses: []
|
60
74
|
|
@@ -68,19 +82,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
82
|
requirements:
|
69
83
|
- - ">="
|
70
84
|
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
71
88
|
version: "0"
|
72
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
90
|
none: false
|
74
91
|
requirements:
|
75
92
|
- - ">="
|
76
93
|
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
77
97
|
version: "0"
|
78
98
|
requirements: []
|
79
99
|
|
80
100
|
rubyforge_project: rosie
|
81
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.3.7
|
82
102
|
signing_key:
|
83
103
|
specification_version: 3
|
84
|
-
summary: rosie-0.0.
|
104
|
+
summary: rosie-0.0.5
|
85
105
|
test_files: []
|
86
106
|
|