rails-backup-migrate 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .DS_Store
6
+ .idea/
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ *0.0.9 (2011-08-18)*
2
+
3
+ * Improvements to help with character set issues in Ruby 1.9.2
4
+
5
+ *0.0.8 (2011-07-25)*
6
+
7
+ * Added check to only include 'files' directory if it is used by the rails app.
8
+
1
9
  *0.0.7 (2011-07-17)*
2
10
 
3
11
  * Removed wildcard path when using `tar` to load database files as this required an option for GnuTar but not on BSD Tar. [Matt Connolly]
data/README.textile CHANGED
@@ -25,7 +25,7 @@ h2. More info
25
25
 
26
26
  The backup file can be specified with a command line argument in rake's (wierd) format:
27
27
 
28
- <pre></code> $ rake site:backup[/path/to/file.tgz]</code></pre>
28
+ <pre><code> $ rake site:backup[/path/to/file.tgz]</code></pre>
29
29
 
30
30
  h2. Compatibility
31
31
 
@@ -20,12 +20,13 @@ module RailsBackupMigrate
20
20
  @archive_file = nil
21
21
  @files_to_archive = []
22
22
 
23
- if ENV['verbose'] || ENV['VERBOSE']
24
- VERBOSE = true
25
- else
26
- VERBOSE = false
27
- end
28
-
23
+ VERBOSE =
24
+ if ENV['verbose'] || ENV['VERBOSE']
25
+ true
26
+ else
27
+ false
28
+ end
29
+
29
30
  # singleton methods for Module `RailsBackupMigrate`
30
31
  class << self
31
32
  attr_accessor :backup_file
@@ -37,19 +38,21 @@ module RailsBackupMigrate
37
38
  end
38
39
  end
39
40
 
40
- # add a path to be archived. Expected path to be relative to RAILS_ROOT. This is where the archive
41
+ # add a path to be archived. Expected path to be relative to Rails.root. This is where the archive
41
42
  # will be created so that uploaded files (the 'files' dir) can be reference in place without needing to be copied.
42
43
  def add_to_archive path
43
- # check it's relative to RAILS_ROOT
44
- raise "File '#{path}' does not exist" unless File::exist? path
44
+ # check it's relative to Rails.root
45
+ raise "File '#{path}' does not exist" unless File.exist? path
45
46
 
46
- if File::expand_path(path).start_with? RAILS_ROOT
47
- # remove RAILS_ROOT from absolute path
48
- relative = File::expand_path(path).sub(RAILS_ROOT,'')
49
- # remove leading slash
50
- relative.gsub! /^#{File::SEPARATOR}/,''
47
+ expanded_path = File.expand_path(path)
48
+ if expanded_path.start_with?(rails_root.to_s)
49
+ # remove rails_root from absolute path
50
+ relative = expanded_path.sub(rails_root + File::SEPARATOR,'')
51
51
  # add to list
52
+ puts "Adding relative path: '#{relative}'" if VERBOSE
52
53
  @files_to_archive << relative
54
+ else
55
+ raise "Cannot add a file that is not under Rails root directory. (#{expanded_path} not under #{rails_root})"
53
56
  end
54
57
  end
55
58
 
@@ -87,14 +90,14 @@ module RailsBackupMigrate
87
90
  def create_archive backup_file
88
91
  puts "creating archive..." if VERBOSE
89
92
  absolute = File::expand_path backup_file
90
- Dir::chdir RAILS_ROOT
93
+ Dir::chdir rails_root
91
94
  `tar -czf #{absolute} #{files_to_archive.join ' '}`
92
95
  end
93
96
 
94
97
 
95
98
  # save the required database tables to .yml files in a folder 'yml' and add them to the backup
96
99
  def save_db_to_yml
97
- FileUtils.chdir RAILS_ROOT
100
+ FileUtils.chdir rails_root
98
101
  FileUtils.mkdir_p 'db/backup'
99
102
  FileUtils.chdir 'db/backup'
100
103
 
@@ -107,7 +110,7 @@ module RailsBackupMigrate
107
110
  end
108
111
 
109
112
  # simply add the whole yml folder to the archive
110
- FileUtils.chdir RAILS_ROOT
113
+ FileUtils.chdir rails_root
111
114
  add_to_archive 'db/backup'
112
115
  end
113
116
 
@@ -126,6 +129,12 @@ module RailsBackupMigrate
126
129
  end
127
130
  end
128
131
  end
132
+
133
+ def rails_root
134
+ # in ruby 1.9.3, `Rails.root` is a Pathname object, that plays mess with string comparisons
135
+ # so we'll ensure we have a string
136
+ Rails.root.to_s
137
+ end
129
138
  end
130
139
  end
131
140
 
@@ -1,3 +1,3 @@
1
1
  module RailsBackupMigrate
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -17,7 +17,11 @@ namespace :site do
17
17
  # private task: save the db/schema.rb file, calls 'db:schema:dump' as a dependency
18
18
  task :_save_db_schema, [:backup_file] => [:environment, 'db:schema:dump'] do |t, args|
19
19
  puts "adding db/schema.rb to archive list." if RailsBackupMigrate::VERBOSE
20
- Dir::chdir RAILS_ROOT
20
+ Dir::chdir Rails.root
21
+ if RailsBackupMigrate::VERBOSE
22
+ puts "Checking if the db/schema file exists: " + (File.exist?('db/schema.rb') ? 'YES' : 'NO')
23
+ puts "Full path expands to: " + File.expand_path('db/schema.rb')
24
+ end
21
25
  RailsBackupMigrate.add_to_archive 'db/schema.rb'
22
26
  end
23
27
 
@@ -81,7 +85,7 @@ namespace :site do
81
85
  # private task: restore db/schema.rb, expected to be a dependency before 'db:schema:load'
82
86
  task :_restore_db_schema, [:backup_file] => [:_set_backup_file] do |t, args|[]
83
87
  puts "restoring db/schema.rb from archive." if RailsBackupMigrate::VERBOSE
84
- Dir::chdir RAILS_ROOT
88
+ Dir::chdir Rails.root
85
89
  # extract the schema.rb file in place
86
90
  options = RailsBackupMigrate::VERBOSE ? '-xvzf' : '-xzf'
87
91
  `tar #{options} #{RailsBackupMigrate.backup_file} db/schema.rb`
@@ -98,7 +102,7 @@ namespace :site do
98
102
 
99
103
  # private task: restore 'files' directory. Should we delete the contents of it?? not for now...
100
104
  task :_restore_files_directory, [:backup_file] => [:_set_backup_file] do |t, args|
101
- Dir::chdir RAILS_ROOT
105
+ Dir::chdir Rails.root
102
106
  # extract the 'files' directory in place
103
107
 
104
108
  # check if there is 'files/' in the archive file (perhaps this app doesn't have downloads)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-backup-migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-18 00:00:00.000000000 +10:00
13
- default_executable:
12
+ date: 2011-12-13 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
- requirement: &2153793800 !ruby/object:Gem::Requirement
16
+ requirement: &70155964458440 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,7 +21,7 @@ dependencies:
22
21
  version: '2.3'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2153793800
24
+ version_requirements: *70155964458440
26
25
  description: ! "Creates a directory db/backup in the rails app and creates / loads
27
26
  YML files from there. \n After a backup, the db/backups directory is archived
28
27
  into a .tgz file and then deleted.\n When restoring, the db/backup directory
@@ -51,7 +50,6 @@ files:
51
50
  - lib/rails-backup-migrate/version.rb
52
51
  - lib/tasks/rails-backup-migrate.rake
53
52
  - rails-backup-migrate.gemspec
54
- has_rdoc: true
55
53
  homepage: ''
56
54
  licenses: []
57
55
  post_install_message:
@@ -72,8 +70,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
70
  version: '0'
73
71
  requirements: []
74
72
  rubyforge_project: rails-backup-migrate
75
- rubygems_version: 1.6.2
73
+ rubygems_version: 1.8.10
76
74
  signing_key:
77
75
  specification_version: 3
78
76
  summary: Backup and restore a rails application including database data and files
79
77
  test_files: []
78
+ has_rdoc: