backup 2.3.0.1 → 2.3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,29 @@ h2. A Backup Ruby Gem
4
4
 
5
5
  Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption and Backup Cleaning (Cycling).
6
6
 
7
+ h2. New Commands as of 2.3.0.2
8
+
9
+ *Finders*
10
+
11
+ Unix Environment:
12
+
13
+ bc. sudo backup --find [trigger]
14
+
15
+ Rails Environment:
16
+
17
+ bc. rake backup:find trigger='trigger'
18
+
19
+ *Finders in Table Format*
20
+
21
+ Unix Environment:
22
+
23
+ bc. sudo backup --table --find [trigger]
24
+
25
+ Rails Environment:
26
+
27
+ bc. rake backup:find trigger='trigger' table=true
28
+
29
+
7
30
  h2. Backup goes independent with the release of version 2.3.0! Ruby on Rails is no longer "required"!
8
31
 
9
32
  *Before you read on, let me tell you that even though all this awesomeness has been added, Backup will still work as it did in the previous version with Ruby on Rails!*
@@ -92,6 +115,9 @@ bc. keep_backups 20
92
115
 
93
116
  h3. Quick Example of a Single Backup Setting inside the Backup Configuration File
94
117
 
118
+ * In *Rails Environments* this file is located in *RAILS_ROOT/config/backup.rb*
119
+ * In *Unix Environments* this file is located in */opt/backup/config/backup.rb*
120
+
95
121
  bc. backup 'mysql-backup-s3' do
96
122
  adapter :mysql do
97
123
  user 'user'
@@ -108,7 +134,6 @@ bc. backup 'mysql-backup-s3' do
108
134
  encrypt_with_password 'password'
109
135
  end
110
136
 
111
-
112
137
  The (backup 'mysql-backup-s3' do) is what I call a "backup setting". The first argument of the block is the so called "trigger".
113
138
 
114
139
  bc. backup 'mysql-backup-s3' do
@@ -118,12 +143,18 @@ end
118
143
  This acts as an "identifier" for the "backup setting". The (above) "backup setting" is all pretty straightforward.
119
144
  So now that we've set up a "backup setting", we can run it using a rake task, like so:
120
145
 
146
+ *If you're using this inside a Unix Environment, use the Backup utility:*
147
+
148
+ bc. sudo backup --run mysql-backup-s3
149
+
150
+ *If you're using this inside a Ruby on Rails Environment, use the Backup rake task:*
151
+
121
152
  bc. rake backup:run trigger="mysql-backup-s3"
122
153
 
123
154
  *That's it, the MySQL database has been "backed up" to Amazon S3. It has been dumped, compressed and encrypted with password.*
124
- Note: You can add as many "backup setting" blocks as you want inside the "config/backup.rb" configuration file and invoke each of them by their own "trigger". This means you can have as many backup setups as you want, which "don't" all run simultaneously when you initialize a backup.
155
+ Note: You can add as many "backup setting" blocks as you want inside the ("/opt/backup/config/backup.rb" for Unix) or ("RAILS_ROOT/config/backup.rb" for Ruby on Rails) configuration file and invoke each of them by their own "trigger". This means you can have as many backup setups as you want, which "don't" all run simultaneously when you initialize a backup.
125
156
 
126
- *Depending on what environment you're running backup on, you will use different commands. Rails uses Rake Tasks, while Unix uses regular executable commands. See below!*
157
+ *Depending on what environment you're running backup on, you will use different commands. Rails uses Rake Tasks, while Unix uses Backup's utility commands. See below!*
127
158
 
128
159
  *Runs the backup setting with the trigger "backup-logs"*
129
160
 
@@ -181,7 +212,9 @@ h3. Backup Configuration File (All Adapters, Storage Methods and Options)
181
212
  "http://wiki.github.com/meskyanichi/backup/configuration-file":http://wiki.github.com/meskyanichi/backup/configuration-file
182
213
 
183
214
 
184
- h3. Rake Tasks
215
+ h3. Utility Commands and Rake Tasks
216
+
217
+ "http://wiki.github.com/meskyanichi/backup/utility-commands":http://wiki.github.com/meskyanichi/backup/utility-commands
185
218
 
186
219
  "http://wiki.github.com/meskyanichi/backup/rake-tasks":http://wiki.github.com/meskyanichi/backup/rake-tasks
187
220
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0.1
1
+ 2.3.0.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backup}
8
- s.version = "2.3.0.1"
8
+ s.version = "2.3.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael van Rooijen"]
12
- s.date = %q{2009-12-08}
12
+ s.date = %q{2009-12-12}
13
13
  s.default_executable = %q{backup}
14
14
  s.description = %q{
15
15
  Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the
data/bin/backup CHANGED
@@ -13,11 +13,13 @@ optparse = OptionParser.new do |opts|
13
13
 
14
14
  opts.on('-r', '--run [trigger]', "Runs backup process by trigger") do |trigger|
15
15
  confirm_configuration_file_existence
16
+ puts "Running: #{trigger}."
16
17
  Backup::Setup.new(trigger, @backup_procedures).initialize_adapter
17
18
  end
18
19
 
19
20
  opts.on('-f', '--find [trigger]', "Finds backup records by trigger") do |trigger|
20
21
  confirm_configuration_file_existence
22
+ puts "Finding backup records with trigger: #{trigger}."
21
23
  backup = Backup::Setup.new(trigger, @backup_procedures)
22
24
  records = Array.new
23
25
  case backup.procedure.storage_name.to_sym
@@ -37,19 +39,16 @@ optparse = OptionParser.new do |opts|
37
39
  end
38
40
 
39
41
  opts.on('-t', '--truncate [trigger]', "Truncates backup records for specified trigger") do |trigger|
40
- confirm_configuration_file_existence
41
- puts "Truncating backups with trigger: #{trigger}."
42
- backup = Backup::Setup.new(trigger, @backup_procedures)
43
- case backup.procedure.storage_name.to_sym
44
- when :s3 then Backup::Record::S3.destroy_all :trigger => trigger, :storage => 's3'
45
- when :scp then Backup::Record::SCP.destroy_all :trigger => trigger, :storage => 'scp'
46
- when :ftp then Backup::Record::FTP.destroy_all :trigger => trigger, :storage => 'ftp'
47
- when :sftp then Backup::Record::SFTP.destroy_all :trigger => trigger, :storage => 'sftp'
48
- end
42
+ puts "Truncating backup records with trigger: #{trigger}."
43
+ Backup::Record::S3.destroy_all :trigger => trigger, :storage => 's3'
44
+ Backup::Record::SCP.destroy_all :trigger => trigger, :storage => 'scp'
45
+ Backup::Record::FTP.destroy_all :trigger => trigger, :storage => 'ftp'
46
+ Backup::Record::SFTP.destroy_all :trigger => trigger, :storage => 'sftp'
49
47
  end
50
48
 
51
49
  opts.on('-d', '--destroy [trigger]', "Destroys backup records and files for specified trigger") do |trigger|
52
50
  confirm_configuration_file_existence
51
+ puts "Destroying backup records with trigger: #{trigger}."
53
52
  backup = Backup::Setup.new(trigger, @backup_procedures)
54
53
  case backup.procedure.storage_name.to_sym
55
54
  when :s3 then Backup::Record::S3.destroy_all_backups backup.procedure, trigger
@@ -60,7 +59,7 @@ optparse = OptionParser.new do |opts|
60
59
  end
61
60
 
62
61
  opts.on('--truncate-all', "Truncates all backup records") do
63
- confirm_configuration_file_existence
62
+ puts "Truncating all backup records."
64
63
  Backup::Record::S3.destroy_all
65
64
  Backup::Record::SCP.destroy_all
66
65
  Backup::Record::FTP.destroy_all
@@ -69,6 +68,7 @@ optparse = OptionParser.new do |opts|
69
68
 
70
69
  opts.on('--destroy-all', "Destroys all backup records and files") do
71
70
  confirm_configuration_file_existence
71
+ puts "Destroying all backup records."
72
72
  backup = Backup::Setup.new(false, @backup_procedures)
73
73
  backup.procedures.each do |backup_procedure|
74
74
  case backup_procedure.storage_name.to_sym
@@ -81,6 +81,7 @@ optparse = OptionParser.new do |opts|
81
81
  end
82
82
 
83
83
  opts.on('--decrypt [file]', "Decrypts a \"Backup\" encrypted file") do |file|
84
+ puts "Attempting to decrypt: #{file}."
84
85
  %x{ openssl enc -des-cbc -d -in #{file} -out #{file.gsub('.enc', '')} }
85
86
  end
86
87
 
@@ -2,22 +2,43 @@ namespace :backup do
2
2
 
3
3
  desc "Run Backup Procedure."
4
4
  task :run => :environment do
5
+ puts "Running: #{ENV['trigger']}."
5
6
  Backup::Setup.new(ENV['trigger'], @backup_procedures).initialize_adapter
6
7
  end
7
8
 
8
- desc "Truncates all records for the specified \"trigger\", excluding the physical files on s3 or the remote server."
9
- task :truncate => :environment do
9
+ desc "Finds backup records by trigger"
10
+ task :find => :environment do
11
+ puts "Finding backup records with trigger: #{ENV['trigger']}."
10
12
  backup = Backup::Setup.new(ENV['trigger'], @backup_procedures)
13
+ records = Array.new
11
14
  case backup.procedure.storage_name.to_sym
12
- when :s3 then Backup::Record::S3.destroy_all :trigger => ENV['trigger'], :storage => 's3'
13
- when :scp then Backup::Record::SCP.destroy_all :trigger => ENV['trigger'], :storage => 'scp'
14
- when :ftp then Backup::Record::FTP.destroy_all :trigger => ENV['trigger'], :storage => 'ftp'
15
- when :sftp then Backup::Record::SFTP.destroy_all :trigger => ENV['trigger'], :storage => 'sftp'
15
+ when :s3 then records = Backup::Record::S3.all :conditions => {:trigger => ENV['trigger']}
16
+ when :scp then records = Backup::Record::SCP.all :conditions => {:trigger => ENV['trigger']}
17
+ when :ftp then records = Backup::Record::FTP.all :conditions => {:trigger => ENV['trigger']}
18
+ when :sftp then records = Backup::Record::SFTP.all :conditions => {:trigger => ENV['trigger']}
19
+ end
20
+
21
+ if ENV['table'].eql?("true")
22
+ puts Hirb::Helpers::AutoTable.render(records)
23
+ else
24
+ records.each do |record|
25
+ puts record.to_yaml
26
+ end
16
27
  end
17
28
  end
18
29
 
30
+ desc "Truncates all records for the specified \"trigger\", excluding the physical files on s3 or the remote server."
31
+ task :truncate => :environment do
32
+ puts "Truncating backup records with trigger: #{ENV['trigger']}."
33
+ Backup::Record::S3.destroy_all :trigger => ENV['trigger'], :storage => 's3'
34
+ Backup::Record::SCP.destroy_all :trigger => ENV['trigger'], :storage => 'scp'
35
+ Backup::Record::FTP.destroy_all :trigger => ENV['trigger'], :storage => 'ftp'
36
+ Backup::Record::SFTP.destroy_all :trigger => ENV['trigger'], :storage => 'sftp'
37
+ end
38
+
19
39
  desc "Truncates everything."
20
40
  task :truncate_all => :environment do
41
+ puts "Truncating all backup records."
21
42
  Backup::Record::S3.destroy_all
22
43
  Backup::Record::SCP.destroy_all
23
44
  Backup::Record::FTP.destroy_all
@@ -26,6 +47,7 @@ namespace :backup do
26
47
 
27
48
  desc "Destroys all records for the specified \"trigger\", including the physical files on s3 or the remote server."
28
49
  task :destroy => :environment do
50
+ puts "Destroying backup records with trigger: #{ENV['trigger']}."
29
51
  backup = Backup::Setup.new(ENV['trigger'], @backup_procedures)
30
52
  case backup.procedure.storage_name.to_sym
31
53
  when :s3 then Backup::Record::S3.destroy_all_backups backup.procedure, ENV['trigger']
@@ -37,6 +59,7 @@ namespace :backup do
37
59
 
38
60
  desc "Destroys all records for the specified \"trigger\", including the physical files on s3 or the remote server."
39
61
  task :destroy_all => :environment do
62
+ puts "Destroying all backup records."
40
63
  backup = Backup::Setup.new(false, @backup_procedures)
41
64
  backup.procedures.each do |backup_procedure|
42
65
  case backup_procedure.storage_name.to_sym
@@ -91,7 +91,9 @@ module Backup
91
91
  when :postgresql then Backup::Adapters::PostgreSQL.new trigger, procedure
92
92
  when :archive then Backup::Adapters::Archive.new trigger, procedure
93
93
  when :custom then Backup::Adapters::Custom.new trigger, procedure
94
- else raise "Unknown Adapter: \"#{procedure.adapter_name}\"."
94
+ else
95
+ puts "Unknown Adapter: \"#{procedure.adapter_name}\"."
96
+ exit
95
97
  end
96
98
  end
97
99
 
@@ -106,7 +108,8 @@ module Backup
106
108
  end
107
109
  end
108
110
  available_triggers = procedures.each.map {|procedure| "- #{procedure.trigger}\n" }
109
- raise "Could not find a backup procedure with the trigger \"#{trigger}\". \nHere's a list of available triggers:\n#{available_triggers}"
111
+ puts "Could not find a backup procedure with the trigger \"#{trigger}\". \nHere's a list of available triggers:\n#{available_triggers}"
112
+ exit
110
113
  end
111
114
 
112
115
  end
@@ -2,26 +2,23 @@ module Backup
2
2
  module Connection
3
3
  class S3
4
4
 
5
- attr_accessor :adapter, :access_key_id, :secret_access_key, :s3_bucket, :use_ssl, :final_file, :tmp_path
5
+ attr_accessor :adapter, :procedure, :access_key_id, :secret_access_key, :s3_bucket, :use_ssl, :final_file, :tmp_path
6
6
 
7
7
  # Initializes the S3 connection, setting the values using the S3 adapter
8
8
  def initialize(adapter = false)
9
9
  if adapter
10
+ self.adapter = adapter
11
+ self.procedure = adapter.procedure
10
12
  self.final_file = adapter.final_file
11
13
  self.tmp_path = adapter.tmp_path.gsub('\ ', ' ')
12
- self.access_key_id = adapter.procedure.get_storage_configuration.attributes['access_key_id']
13
- self.secret_access_key = adapter.procedure.get_storage_configuration.attributes['secret_access_key']
14
- self.s3_bucket = adapter.procedure.get_storage_configuration.attributes['bucket']
15
- self.use_ssl = adapter.procedure.get_storage_configuration.attributes['use_ssl']
14
+ load_storage_configuration_attributes
16
15
  end
17
16
  end
18
17
 
19
18
  # Sets values from a procedure, rather than from the adapter object
20
19
  def static_initialize(procedure)
21
- self.access_key_id = procedure.get_storage_configuration.attributes['access_key_id']
22
- self.secret_access_key = procedure.get_storage_configuration.attributes['secret_access_key']
23
- self.s3_bucket = procedure.get_storage_configuration.attributes['bucket']
24
- self.use_ssl = procedure.get_storage_configuration.attributes['use_ssl']
20
+ self.procedure = procedure
21
+ load_storage_configuration_attributes(true)
25
22
  end
26
23
 
27
24
  # Establishes a connection with Amazon S3 using the credentials provided by the user
@@ -65,6 +62,24 @@ module Backup
65
62
  bucket )
66
63
  end
67
64
 
65
+ private
66
+
67
+ def load_storage_configuration_attributes(static = false)
68
+ %w(access_key_id secret_access_key use_ssl).each do |attribute|
69
+ if static
70
+ send("#{attribute}=", procedure.get_storage_configuration.attributes[attribute])
71
+ else
72
+ send("#{attribute}=", adapter.procedure.get_storage_configuration.attributes[attribute])
73
+ end
74
+ end
75
+
76
+ if static
77
+ self.s3_bucket = procedure.get_storage_configuration.attributes['bucket']
78
+ else
79
+ self.s3_bucket = adapter.procedure.get_storage_configuration.attributes['bucket']
80
+ end
81
+ end
82
+
68
83
  end
69
84
  end
70
85
  end
@@ -24,6 +24,34 @@ module Backup
24
24
  %x{ sudo mkdir -p #{File.join(BACKUP_PATH, 'config')} }
25
25
  %x{ sudo cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.sqlite3')} #{BACKUP_PATH} }
26
26
  %x{ sudo cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.rb')} #{File.join(BACKUP_PATH, 'config')} }
27
+ puts <<-MESSAGE
28
+
29
+ ==============================================================
30
+ Backup has been set up!
31
+ ==============================================================
32
+
33
+ 1: Set up some "Backup Settings" inside the configuration file!
34
+
35
+ /opt/backup/config/backup.rb
36
+
37
+
38
+ 2: Run the backups!
39
+
40
+ sudo backup --run [trigger]
41
+
42
+
43
+ For a list of Backup commands:
44
+
45
+ sudo backup --help
46
+
47
+
48
+ For More Information:
49
+
50
+ http://github.com/meskyanichi/backup
51
+
52
+ ==============================================================
53
+
54
+ MESSAGE
27
55
  else
28
56
  puts "\nBackup is already installed in #{BACKUP_PATH}..\n"
29
57
  puts "If you want to reset it, run:\n\nbackup --reset\n\n"
@@ -61,12 +61,8 @@ module Backup
61
61
  end
62
62
 
63
63
  unless backups_to_destroy.empty?
64
- # Create a new Amazon S3 Object
65
64
  s3 = Backup::Connection::S3.new(adapter_config)
66
- # Connect to Amazon S3 with provided credentials
67
65
  s3.connect
68
-
69
- # Loop through all backups that should be destroyed and remove them from S3.
70
66
  backups_to_destroy.each do |backup|
71
67
  puts "\nDestroying backup \"#{backup.filename}\" from bucket \"#{backup.bucket}\"."
72
68
  s3.destroy(backup.filename, backup.bucket)
@@ -7,7 +7,7 @@ module Backup
7
7
  # Stores the backup file on the remote server using FTP
8
8
  def initialize(adapter)
9
9
  %w(ip user password path).each do |method|
10
- send(:"#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
10
+ send("#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
11
11
  end
12
12
 
13
13
  final_file = adapter.final_file
@@ -17,14 +17,16 @@ module Backup
17
17
  begin
18
18
  ftp.chdir(path)
19
19
  rescue
20
- raise "Could not find or access \"#{path}\" on \"#{ip}\", please ensure this directory exists and is accessible by the user \"#{user}\"."
20
+ puts "Could not find or access \"#{path}\" on \"#{ip}\", please ensure this directory exists and is accessible by the user \"#{user}\"."
21
+ exit
21
22
  end
22
23
 
23
24
  begin
24
25
  puts "Storing \"#{final_file}\" to path \"#{path}\" on remote server (#{ip})."
25
26
  ftp.putbinaryfile(File.join(tmp_path, final_file).gsub('\ ', ' '), File.join(path, final_file))
26
27
  rescue
27
- raise "Could not save file to backup server. Is the \"#{path}\" directory writable?"
28
+ puts "Could not save file to backup server. Is the \"#{path}\" directory writable?"
29
+ exit
28
30
  end
29
31
  end
30
32
  end
@@ -7,7 +7,7 @@ module Backup
7
7
  # Stores the backup file on the remote server using SCP
8
8
  def initialize(adapter)
9
9
  %w(ip user password path).each do |method|
10
- send(:"#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
10
+ send("#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
11
11
  end
12
12
 
13
13
  final_file = adapter.final_file
@@ -7,7 +7,7 @@ module Backup
7
7
  # Stores the backup file on the remote server using SFTP
8
8
  def initialize(adapter)
9
9
  %w(ip user password path).each do |method|
10
- send(:"#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
10
+ send("#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
11
11
  end
12
12
 
13
13
  final_file = adapter.final_file
@@ -18,7 +18,8 @@ module Backup
18
18
  puts "Storing \"#{final_file}\" to path \"#{path}\" on remote server (#{ip})."
19
19
  sftp.upload!(File.join(tmp_path, final_file).gsub('\ ', ' '), File.join(path, final_file))
20
20
  rescue
21
- raise "Could not find \"#{path}\" on \"#{ip}\", please ensure this directory exists."
21
+ puts "Could not find \"#{path}\" on \"#{ip}\", please ensure this directory exists."
22
+ exit
22
23
  end
23
24
  end
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0.1
4
+ version: 2.3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-08 00:00:00 +01:00
12
+ date: 2009-12-12 00:00:00 +01:00
13
13
  default_executable: backup
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency