s3_db_assets_backup 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -78,10 +78,6 @@ You need to create a tmp directory in the project root.
78
78
 
79
79
  mkdir tmp
80
80
 
81
- <b>I get "broken pipe" when running the backup</b>
82
-
83
- You need to create the S3 bucket you're trying to backup to.
84
-
85
81
  <b>My crontab doesn't run in development.</b>
86
82
 
87
83
  Deving on a mac? Cron is deprecated in Mountain Lion.
@@ -1,9 +1,7 @@
1
1
  config_file = "#{Rails.root.to_s}/config/s3_backup_config.yml"
2
2
  if FileTest.exists?(config_file)
3
3
  S3_CONFIG = YAML.load_file(config_file)[Rails.env].symbolize_keys
4
- AWS.config(S3_CONFIG)
5
-
6
4
  EMAIL_CONFIG = YAML.load_file(config_file)["email_config"].symbolize_keys
7
5
  else
8
6
  puts "WARNING: Can't find s3_backup_config.yml"
9
- end
7
+ end
@@ -3,21 +3,22 @@ require 'fileutils'
3
3
  require 'aws/s3'
4
4
 
5
5
  namespace :assets do
6
- desc "Backup everything in the public folder."
6
+ desc "Backup everything in the public folder."
7
7
  task :backup => [:environment] do
8
8
 
9
9
  # establish a connection and create the s3 bucket
10
+ AWS.config(S3_CONFIG)
10
11
  s3 = AWS::S3.new
11
12
  bucket = s3.buckets.create(S3_CONFIG[:bucket])
12
13
 
13
14
  # Build the backup directory and filename
14
15
  datestamp = Time.now.strftime("%Y-%m-%d-%H-%M-%S")
15
- base_path = ENV["RAILS_ROOT"] || "."
16
- file_name = "#{Rails.env}_assets-#{datestamp}.sql.gz"
16
+ base_path = ENV["RAILS_ROOT"] || "."
17
+ file_name = "#{Rails.env}_assets-#{datestamp}.sql.gz"
17
18
  backup_file = File.join(base_path, "tmp", file_name)
18
-
19
+
19
20
  sh "tar -cvzpf #{backup_file} public"
20
-
21
+
21
22
  # Upload the backup file to Amazon and remove the file from the local filesystem
22
23
  basename = File.basename(file_name)
23
24
  object = bucket.objects[basename]
@@ -33,16 +34,17 @@ namespace :assets do
33
34
  unwanted_backups = all_backups[max_backups..-1] || []
34
35
  for unwanted_backup in unwanted_backups
35
36
  unwanted_backup.delete
36
- puts "deleted #{unwanted_backup.key}"
37
+ puts "deleted #{unwanted_backup.key}"
37
38
  end
38
- puts "Deleted #{unwanted_backups.length} backups, #{all_backups.length - unwanted_backups.length} backups available"
39
+ puts "Deleted #{unwanted_backups.length} backups, #{all_backups.length - unwanted_backups.length} backups available"
39
40
  end
40
41
 
41
- desc "Restore the public folder from an available backup."
42
+ desc "Restore the public folder from an available backup."
42
43
  task :restore => [:environment] do
43
- base_path = ENV["RAILS_ROOT"] || "."
44
-
44
+ base_path = ENV["RAILS_ROOT"] || "."
45
+
45
46
  # establish a connection and find the s3 bucket
47
+ AWS.config(S3_CONFIG)
46
48
  s3 = AWS::S3.new
47
49
  bucket = s3.buckets[S3_CONFIG[:bucket]]
48
50
 
@@ -5,23 +5,24 @@ require 'pony'
5
5
  require 'unit_converter'
6
6
 
7
7
  namespace :db do
8
- desc "Backup the database to a file. Options: RAILS_ENV=production"
8
+ desc "Backup the database to a file. Options: RAILS_ENV=production"
9
9
  task :backup => [:environment] do
10
-
10
+
11
11
  # establish a connection and create the s3 bucket
12
+ AWS.config(S3_CONFIG)
12
13
  s3 = AWS::S3.new
13
14
  bucket = s3.buckets.create(S3_CONFIG[:bucket])
14
15
 
15
16
  # Build the backup directory and filename
16
17
  datestamp = Time.now.strftime("%Y-%m-%d-%H-%M-%S")
17
- base_path = ENV["RAILS_ROOT"] || "."
18
- file_name = "#{Rails.env}_dump-#{datestamp}.sql.gz"
18
+ base_path = ENV["RAILS_ROOT"] || "."
19
+ file_name = "#{Rails.env}_dump-#{datestamp}.sql.gz"
19
20
  backup_file = File.join(base_path, "tmp", file_name)
20
21
 
21
22
  # Load database configuration and dump the sql database to the backup file
22
23
  db_config = ActiveRecord::Base.configurations[Rails.env]
23
- 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}"
24
-
24
+ 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}"
25
+
25
26
  # Upload the backup file to Amazon and remove the file from the local filesystem
26
27
  basename = File.basename(file_name)
27
28
  object = bucket.objects[basename]
@@ -39,17 +40,18 @@ namespace :db do
39
40
  unwanted_backups = all_backups[max_backups..-1] || []
40
41
  for unwanted_backup in unwanted_backups
41
42
  unwanted_backup.delete
42
- puts "deleted #{unwanted_backup.key}"
43
+ puts "deleted #{unwanted_backup.key}"
43
44
  end
44
- puts "Deleted #{unwanted_backups.length} backups, #{all_backups.length - unwanted_backups.length} backups available"
45
+ puts "Deleted #{unwanted_backups.length} backups, #{all_backups.length - unwanted_backups.length} backups available"
45
46
  end
46
47
 
47
- desc "Restore the database from an available backup. Options: RAILS_ENV=production"
48
+ desc "Restore the database from an available backup. Options: RAILS_ENV=production"
48
49
  task :restore => [:environment] do
49
- base_path = ENV["RAILS_ROOT"] || "."
50
+ base_path = ENV["RAILS_ROOT"] || "."
50
51
  db_config = ActiveRecord::Base.configurations[Rails.env]
51
-
52
+
52
53
  # establish a connection and find the s3 bucket
54
+ AWS.config(S3_CONFIG)
53
55
  s3 = AWS::S3.new
54
56
  bucket = s3.buckets[S3_CONFIG[:bucket]]
55
57
 
@@ -93,8 +95,9 @@ namespace :db do
93
95
  namespace :backup do
94
96
  desc "Email a report of current backups."
95
97
  task :status => [:environment] do
96
-
98
+
97
99
  # establish a connection and find the s3 bucket
100
+ AWS.config(S3_CONFIG)
98
101
  s3 = AWS::S3.new
99
102
  bucket = s3.buckets[S3_CONFIG[:bucket]]
100
103
 
@@ -107,9 +110,9 @@ namespace :db do
107
110
  message << "#{file.key} (#{file_size})\n"
108
111
  end
109
112
 
110
- Pony.mail(
111
- :to => email[:to],
112
- :via => email[:via],
113
+ Pony.mail(
114
+ :to => email[:to],
115
+ :via => email[:via],
113
116
  :subject => email[:subject],
114
117
  :body => message,
115
118
 
metadata CHANGED
@@ -1,86 +1,95 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: s3_db_assets_backup
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
4
5
  prerelease:
5
- version: 0.2.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Chris Barnes
9
9
  - Michael Burk
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2012-12-09 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2012-12-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: pony
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "1.4"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '1.4'
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: aws-sdk
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
31
26
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "1.7"
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '1.4'
31
+ - !ruby/object:Gem::Dependency
32
+ name: aws-sdk
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '1.7'
36
39
  type: :runtime
37
- version_requirements: *id002
38
- 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. Additionally, the plugin can be configured to generate and send a backup status report via email.
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '1.7'
47
+ description: Generates rake tasks for backing up and restoring your database and public
48
+ folder (which should also contain any user uploaded assets) to and from an existing
49
+ bucket in your Amazon S3 account. The rake tasks compresses and uploads each backup
50
+ with a time stamp and the config file allows you to set how many of each backup
51
+ to keep. Additionally, the plugin can be configured to generate and send a backup
52
+ status report via email.
39
53
  email: chris@randomutterings.com
40
54
  executables: []
41
-
42
55
  extensions: []
43
-
44
- extra_rdoc_files:
56
+ extra_rdoc_files:
45
57
  - README.rdoc
46
- files:
58
+ files:
59
+ - lib/generators/s3_backup/USAGE
47
60
  - lib/generators/s3_backup/s3_backup_generator.rb
48
61
  - lib/generators/s3_backup/templates/s3_backup_config.yml
49
- - lib/generators/s3_backup/USAGE
62
+ - lib/s3_db_assets_backup.rb
50
63
  - lib/s3_db_assets_backup/engine.rb
51
64
  - lib/s3_db_assets_backup/railties/assets_backup.rake
52
65
  - lib/s3_db_assets_backup/railties/db_backup.rake
53
- - lib/s3_db_assets_backup.rb
54
66
  - lib/unit_converter.rb
55
67
  - config/initializers/load_s3_backup_config.rb
56
68
  - README.rdoc
57
69
  homepage: http://www.randomutterings.com/projects/s3_db_assets_backup
58
70
  licenses: []
59
-
60
71
  post_install_message:
61
72
  rdoc_options: []
62
-
63
- require_paths:
73
+ require_paths:
64
74
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
75
+ required_ruby_version: !ruby/object:Gem::Requirement
66
76
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
82
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
77
87
  requirements: []
78
-
79
88
  rubyforge_project:
80
89
  rubygems_version: 1.8.24
81
90
  signing_key:
82
91
  specification_version: 3
83
- summary: Rake tasks for backing up and restoring db and public folder to and from an existing S3 bucket with email notifications.
92
+ summary: Rake tasks for backing up and restoring db and public folder to and from
93
+ an existing S3 bucket with email notifications.
84
94
  test_files: []
85
-
86
95
  has_rdoc: