s3_db_assets_backup 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- config_file = "#{RAILS_ROOT}/config/s3_backup_config.yml"
1
+ config_file = "#{Rails.root.to_s}/config/s3_backup_config.yml"
2
2
  if FileTest.exists?(config_file)
3
- S3_CONFIG = YAML.load_file(config_file)[RAILS_ENV].symbolize_keys
3
+ S3_CONFIG = YAML.load_file(config_file)[Rails.env].symbolize_keys
4
4
  else
5
- raise "Can't find s3_backup_config.yml"
5
+ puts "WARNING: Can't find s3_backup_config.yml"
6
6
  end
@@ -13,6 +13,7 @@ namespace :assets do
13
13
  file_name = "assets-#{datestamp}.tgz"
14
14
  backup_file = File.join(base_path, "tmp", file_name)
15
15
  sh "tar -cvzpf #{backup_file} public"
16
+
16
17
  AWS::S3::S3Object.store(file_name, open(backup_file), BUCKET)
17
18
  puts "Created backup: #{file_name}"
18
19
  FileUtils.rm_rf(backup_file)
@@ -59,7 +60,7 @@ namespace :assets do
59
60
  backup_file = File.join(base_path, file_name)
60
61
  destination = File.join(base_path, "public")
61
62
  puts "downloading backup..."
62
- open(backup_file, 'w') do |file|
63
+ open(backup_file).read.force_encoding('utf-8') do |file|
63
64
  AWS::S3::S3Object.stream(file_name, bucket_name) do |chunk|
64
65
  file.write chunk
65
66
  end
@@ -10,9 +10,9 @@ namespace :db do
10
10
 
11
11
  datestamp = Time.now.strftime("%Y-%m-%d-%H-%M-%S")
12
12
  base_path = ENV["RAILS_ROOT"] || "."
13
- file_name = "#{RAILS_ENV}_dump-#{datestamp}.sql.gz"
13
+ file_name = "#{Rails.env}_dump-#{datestamp}.sql.gz"
14
14
  backup_file = File.join(base_path, "tmp", file_name)
15
- db_config = ActiveRecord::Base.configurations[RAILS_ENV]
15
+ db_config = ActiveRecord::Base.configurations[Rails.env]
16
16
  sh "mysqldump -u #{db_config['username']} -p#{db_config['password']} --default-character-set=latin1 -N -Q --add-drop-table #{db_config['database']} | gzip -c > #{backup_file}"
17
17
  AWS::S3::S3Object.store(file_name, open(backup_file), BUCKET)
18
18
  puts "Created backup: #{file_name}"
@@ -34,7 +34,7 @@ namespace :db do
34
34
  desc "Restore the database from an available backup. Options: RAILS_ENV=production"
35
35
  task :restore => [:environment] do
36
36
  base_path = ENV["RAILS_ROOT"] || "."
37
- db_config = ActiveRecord::Base.configurations[RAILS_ENV]
37
+ db_config = ActiveRecord::Base.configurations[Rails.env]
38
38
  AWS::S3::Base.establish_connection!(:access_key_id => S3_CONFIG[:access_key_id], :secret_access_key => S3_CONFIG[:secret_access_key])
39
39
  bucket_name = S3_CONFIG[:bucket]
40
40
  backups = AWS::S3::Bucket.objects(bucket_name).select { |f| f.key.match(/dump/) }
@@ -65,7 +65,7 @@ namespace :db do
65
65
  file.write chunk
66
66
  end
67
67
  end
68
- puts "download complete, restoring to #{RAILS_ENV} database"
68
+ puts "download complete, restoring to #{Rails.env} database"
69
69
  sh "gzip -dc #{backup_file} | mysql -u #{db_config['username']} -p#{db_config['password']} #{db_config['database']} --default-character-set=latin1 -N"
70
70
  puts "cleaning up..."
71
71
  FileUtils.rm_rf(backup_file)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: s3_db_assets_backup
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chris Barnes
@@ -10,10 +10,10 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-11 00:00:00 Z
13
+ date: 2012-10-09 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
- description: Generates rake tasks for backing up and restoring your database and public folder (which should also contain any uploaded assets) to and from an existing bucket in your Amazon S3 account. The rake tasks compresses and uploads each backup with a time stamp and the config file allows you to set how many of each backup to keep. This gem is based on (http://www.magnionlabs.com/2009/7/7/db-backups).
16
+ description: Generates rake tasks for backing up and restoring your database and public folder (which should also contain any user uploaded assets) to and from an existing bucket in your Amazon S3 account. The rake tasks compresses and uploads each backup with a time stamp and the config file allows you to set how many of each backup to keep. This gem is based on (http://www.magnionlabs.com/2009/7/7/db-backups).
17
17
  email: chris@randomutterings.com
18
18
  executables: []
19
19