backup 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,17 @@
1
+ BIG UPDATE
2
+ === 2.3.0 ====================================
3
+
4
+ - Backup became independent of Ruby on Rails
5
+ - Backup now supports multiple environments: Rails and Unix
6
+ - Backup is now executable through the command-line when using the Unix environment
7
+
8
+ SMALL FEATURE UPDATE
9
+ === 2.2.1 ====================================
10
+
11
+ - use_ssl option added for S3 Storage Method
12
+ - additional_options option added for MySQL and PostgreSQL Adapters
13
+
14
+
1
15
  PRETTY BIG UPDATE
2
16
  === 2.2.0 ====================================
3
17
 
data/LICENSE CHANGED
@@ -1,15 +1,4 @@
1
- Copyright (c) 2009 meskyanichi
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
1
+ Copyright (c) 2009 Michael van Rooijen - Final Creation (http://final-creation.com)
13
2
 
14
3
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
4
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
@@ -17,4 +6,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
6
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
7
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
8
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,66 +1,42 @@
1
1
  h1. Backup
2
2
 
3
- h2. A Backup Ruby Gem for Rails
3
+ h2. A Backup Ruby Gem
4
4
 
5
- Backup is a Ruby Gem, written specifically for Ruby on Rails applications. This gem offers a quick and easy way to configure and run backups of your
6
- MySQL/PostgreSQL databases *(and practically even any other database you can dump through the command line)*. It can also make backups of your *archives* (any files or folders).
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).
7
6
 
8
- All backups can be transferred to either *"Amazon S3"* or "any remotely accessible server using the *SCP, SFTP or FTP* transfer methods".
7
+ h2. Backup goes independent with the release of version 2.3.0! Ruby on Rails is no longer "required"!
9
8
 
10
- *Backup handles: Compression, Archiving, Encryption and Backup Cleaning.*
9
+ *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!*
11
10
 
11
+ I am pleased to announce that Backup (version 2.3.0+) has been released and am very satisfied with this update. Backup can now make use of an executable bin file! Why is this so awesome? Because now Backup is Ruby on Rails independent! This means you can make use of Backup whether you use Rails or not, and with the same simplicity! *(pshh.. It's actually simpler to be honest!)*.
12
12
 
13
- h2. What's new in 2.2.0?
13
+ Imagine you have one or more web applications written in another language on the same server, for example, a Python or PHP application. It'd be nice if you could also back up these databases in the same way you are used to, using Backup. Or what about having a MySQL Server running on a separate remove server? It'd be nice to be able to backup directly from that server instead of create a dump from there to the application's server and then push it to Amazon S3 or elsewhere. Previously this wasn't really possible. But now it is! Check this out.
14
14
 
15
- *(S)FTP*
16
- FTP and SFTP Storage Methods have been added. This will allow you to transfer your backups
17
- through a (S)FTP if you cannot make use of SCP.
15
+ *Install Backup Gem version 2.3.0 or later!*
18
16
 
19
- *MySQL*
20
- The following options have been added to the MySQL Adapter
21
-
22
- * host
23
- * socket
24
- * port
25
- * skip_tables
17
+ bc. sudo gem install backup
26
18
 
27
- *PostgreSQL*
28
- The PostgreSQL Adapter has been added! It has about the same options as the MySQL Adapter
19
+ *Setup Backup*
29
20
 
30
- * host/socket
31
- * port
32
- * skip_tables
21
+ bc. sudo backup --setup
33
22
 
34
- If you are using PostgreSQL and the Adapter isn't working correctly, please notify me of this.
35
- I personally never used PostgreSQL, so I don't really have any experience with it, but since there are people that do use it, I wanted to implement it.
23
+ *New folders and files are created in /opt/backup, these will look familiar if you've been using Backup.. Edit the config file!*
24
+ The configuration file works *100% the same as the Ruby on Rails configuration file*, so no need to re-understand it!
36
25
 
37
- *Custom*
38
- This adapter will enable you, regardless of your database, to make SQL dumps. It's very simple.
39
- *Simply put: If you don't use MySQL or PostgreSQL then you can use Custom to backup your database format, regardless.*
40
- What the Custom Adapter does is it allows you to input one or more *commands* to execute (think of *mysqldump* or *pg_dump*, but for other databases).
26
+ bc. sudo nano /opt/backup/config/backup.rb
41
27
 
42
- *The benefit of doing this through Backup* is that you will still gain all the other features that it provides, such as Archiving, Compression, Encryption and Backup Cleaning, even though Backup doesn't officially support your specific database format! You can basically see the Custom adapter as any other adapter, except that you have to *write the sql dump command yourself*. And then Backup handles the rest!
28
+ *And now just run it like so!*
43
29
 
44
- *More info on the adapters:*
30
+ bc. sudo backup --run mytrigger
45
31
 
46
- "http://wiki.github.com/meskyanichi/backup/configuration-file":http://wiki.github.com/meskyanichi/backup/configuration-file
32
+ *For a full list of commands:*
47
33
 
48
- *A few bug fixes*
34
+ bc. backup --help
49
35
 
50
- * Issue where two backup settings would conflict if they were using the same Adapter at the same second! (which can happens when running cronjobs!)
51
- * The temporary files will now be nicely name spaced by "trigger" so no conflict between two different triggers can occur
52
- * When an exception is raised during the backup process, the temporary files would not be removed. This is now fixed.
53
- * And some other minor patches have been applied.
54
36
 
55
- *Updated the Wiki based on this release.*
37
+ *Another handy command I added to this backup utility, is the ability to decrypt files that were encrypted by Backup.*
56
38
 
57
- h3. Get Backup 2.2.x+ now!
58
-
59
- bc. sudo gem install backup
60
-
61
- And get up and running with Backup 2.2.x+ by reading the *Getting Started* Wiki Page!
62
-
63
- "http://wiki.github.com/meskyanichi/backup/getting-started":http://wiki.github.com/meskyanichi/backup/getting-started
39
+ bc. sudo backup --decrypt /path/to/encrypted/file
64
40
 
65
41
 
66
42
  h2. (Current) Backup's Capabilities
@@ -72,7 +48,6 @@ h3. Storage Methods
72
48
  * Remote Server (SFTP)
73
49
  * Remote Server (FTP)
74
50
 
75
-
76
51
  h3. Adapters
77
52
 
78
53
  * MySQL
@@ -80,7 +55,6 @@ h3. Adapters
80
55
  * Archive (any files or folders)
81
56
  * Custom (any database format other than MySQL or PostgreSQL!)
82
57
 
83
-
84
58
  h3. Archiving
85
59
 
86
60
  *Backup supports Archiving.*
@@ -96,6 +70,9 @@ of which you wish to encrypt, and it will encrypt it with the specified password
96
70
 
97
71
  bc. encrypt_with_password "mypassword"
98
72
 
73
+ As of *Backup 2.3.0*, backup is executable through the command line. To decrypt an encrypted file, backup provides you with a handy utility to do this:
74
+
75
+ bc. sudo backup --decrypt /path/to/encrypted/file
99
76
 
100
77
  h3. Backup Cleaning
101
78
 
@@ -142,17 +119,22 @@ bc. rake backup:run trigger="mysql-backup-s3"
142
119
  *That's it, the MySQL database has been "backed up" to Amazon S3. It has been dumped, compressed and encrypted with password.*
143
120
  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.
144
121
 
122
+ *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!*
123
+
145
124
  *Runs the backup setting with the trigger "backup-logs"*
146
125
 
147
126
  bc. rake backup:run trigger="backup-logs"
127
+ sudo backup --run backup-logs
148
128
 
149
129
  *Runs the backup setting with the trigger "backup-mysql"*
150
130
 
151
131
  bc. rake backup:run trigger="backup-mysql"
132
+ sudo backup --run backup-mysql
152
133
 
153
134
  *Runs the backup setting with the trigger "backup-assets"*
154
135
 
155
136
  bc. rake backup:run trigger="backup-assets"
137
+ sudo backup --run backup-assets
156
138
 
157
139
  h3. Additional Options for MySQL and PostgreSQL
158
140
 
@@ -169,17 +151,20 @@ bc. backup 'mysql-backup-s3' do
169
151
  .
170
152
  end
171
153
 
172
- etc. etc. etc. etc. etc. etc...
173
-
174
-
175
154
 
176
155
  h2. Interested in trying out Backup?
177
156
 
178
157
  h3. Check out the following Wiki pages to get up and running:
179
158
 
180
- h3. Getting started
181
159
 
182
- "http://wiki.github.com/meskyanichi/backup/getting-started":http://wiki.github.com/meskyanichi/backup/getting-started
160
+ h3. Getting started (Unix Environment)
161
+
162
+ "http://wiki.github.com/meskyanichi/backup/getting-started-unix":http://wiki.github.com/meskyanichi/backup/getting-started-unix
163
+
164
+
165
+ h3. Getting started (Rails Environment)
166
+
167
+ "http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails":http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails
183
168
 
184
169
 
185
170
  h3. Production Mode (important)
data/Rakefile CHANGED
@@ -5,21 +5,26 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "backup"
8
- gem.summary = %Q{Backup is a gem/plugin that enables you to very easily create backups and transfer these to Amazon S3 or another server with SSH.}
8
+ gem.summary = %Q{Backup is a Ruby Gem that simplifies making backups for databases, files and folders.}
9
9
  gem.description = %Q{
10
- Backup is a Ruby Gem, written specifically for Ruby on Rails applications. This gem offers a quick and easy way to configure and run backups of your
11
- MySQL/PostgreSQL databases (and practically even any other database you can dump through the command line). It can also make backups of your archives (any files or folders).
12
- All backups can be transferred to either "Amazon S3" or "any remotely accessible server using the SCP, SFTP or FTP transfer methods".
13
- Backup handles: Compression, Archiving, Encryption and Backup Cleaning.
10
+ Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the
11
+ Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as
12
+ MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you
13
+ have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption
14
+ and Backup Cleaning (Cycling).
14
15
  }
15
16
 
16
17
  gem.email = "meskyan@gmail.com"
17
18
  gem.homepage = "http://final-creation.com/open-source"
18
19
  gem.authors = ["Michael van Rooijen"]
19
- gem.add_dependency "aws-s3", ">= 0.6.2"
20
- gem.add_dependency "net-ssh", ">= 2.0.15"
21
- gem.add_dependency "net-scp", ">= 1.0.2"
22
- gem.add_dependency "net-sftp", ">= 2.0.4"
20
+ gem.add_dependency "aws-s3", ">= 0.6.2"
21
+ gem.add_dependency "net-ssh", ">= 2.0.15"
22
+ gem.add_dependency "net-scp", ">= 1.0.2"
23
+ gem.add_dependency "net-sftp", ">= 2.0.4"
24
+ gem.add_dependency "activerecord", ">= 2.3.5"
25
+ gem.add_dependency "sqlite3-ruby", ">= 1.2.5"
26
+ # gem.add_dependency "hirb", ">= 0.2.9"
27
+
23
28
  end
24
29
  rescue LoadError
25
30
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.1
1
+ 2.3.0
@@ -5,18 +5,21 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backup}
8
- s.version = "2.2.1"
8
+ s.version = "2.3.0"
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-06}
12
+ s.date = %q{2009-12-08}
13
+ s.default_executable = %q{backup}
13
14
  s.description = %q{
14
- Backup is a Ruby Gem, written specifically for Ruby on Rails applications. This gem offers a quick and easy way to configure and run backups of your
15
- MySQL/PostgreSQL databases (and practically even any other database you can dump through the command line). It can also make backups of your archives (any files or folders).
16
- All backups can be transferred to either "Amazon S3" or "any remotely accessible server using the SCP, SFTP or FTP transfer methods".
17
- Backup handles: Compression, Archiving, Encryption and Backup Cleaning.
15
+ Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the
16
+ Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as
17
+ MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you
18
+ have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption
19
+ and Backup Cleaning (Cycling).
18
20
  }
19
21
  s.email = %q{meskyan@gmail.com}
22
+ s.executables = ["backup"]
20
23
  s.extra_rdoc_files = [
21
24
  "LICENSE",
22
25
  "README.textile"
@@ -30,6 +33,7 @@ Gem::Specification.new do |s|
30
33
  "Rakefile",
31
34
  "VERSION",
32
35
  "backup.gemspec",
36
+ "bin/backup",
33
37
  "generators/backup/backup_generator.rb",
34
38
  "generators/backup/templates/config/backup.rb",
35
39
  "generators/backup/templates/migrations/create_backup_tables.rb",
@@ -46,6 +50,9 @@ Gem::Specification.new do |s|
46
50
  "lib/backup/configuration/helpers.rb",
47
51
  "lib/backup/configuration/storage.rb",
48
52
  "lib/backup/connection/s3.rb",
53
+ "lib/backup/environment/base.rb",
54
+ "lib/backup/environment/rails.rb",
55
+ "lib/backup/environment/unix.rb",
49
56
  "lib/backup/record/ftp.rb",
50
57
  "lib/backup/record/s3.rb",
51
58
  "lib/backup/record/scp.rb",
@@ -53,13 +60,15 @@ Gem::Specification.new do |s|
53
60
  "lib/backup/storage/ftp.rb",
54
61
  "lib/backup/storage/s3.rb",
55
62
  "lib/backup/storage/scp.rb",
56
- "lib/backup/storage/sftp.rb"
63
+ "lib/backup/storage/sftp.rb",
64
+ "setup/backup.rb",
65
+ "setup/backup.sqlite3"
57
66
  ]
58
67
  s.homepage = %q{http://final-creation.com/open-source}
59
68
  s.rdoc_options = ["--charset=UTF-8"]
60
69
  s.require_paths = ["lib"]
61
70
  s.rubygems_version = %q{1.3.5}
62
- s.summary = %q{Backup is a gem/plugin that enables you to very easily create backups and transfer these to Amazon S3 or another server with SSH.}
71
+ s.summary = %q{Backup is a Ruby Gem that simplifies making backups for databases, files and folders.}
63
72
 
64
73
  if s.respond_to? :specification_version then
65
74
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -70,17 +79,23 @@ Gem::Specification.new do |s|
70
79
  s.add_runtime_dependency(%q<net-ssh>, [">= 2.0.15"])
71
80
  s.add_runtime_dependency(%q<net-scp>, [">= 1.0.2"])
72
81
  s.add_runtime_dependency(%q<net-sftp>, [">= 2.0.4"])
82
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.3.5"])
83
+ s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
73
84
  else
74
85
  s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
75
86
  s.add_dependency(%q<net-ssh>, [">= 2.0.15"])
76
87
  s.add_dependency(%q<net-scp>, [">= 1.0.2"])
77
88
  s.add_dependency(%q<net-sftp>, [">= 2.0.4"])
89
+ s.add_dependency(%q<activerecord>, [">= 2.3.5"])
90
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
78
91
  end
79
92
  else
80
93
  s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
81
94
  s.add_dependency(%q<net-ssh>, [">= 2.0.15"])
82
95
  s.add_dependency(%q<net-scp>, [">= 1.0.2"])
83
96
  s.add_dependency(%q<net-sftp>, [">= 2.0.4"])
97
+ s.add_dependency(%q<activerecord>, [">= 2.3.5"])
98
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
84
99
  end
85
100
  end
86
101
 
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'backup'
4
+
5
+ include Backup::Environment::Unix::Commands
6
+ include Backup::Environment::Unix::Helpers
7
+
8
+ options = {}
9
+
10
+ optparse = OptionParser.new do |opts|
11
+
12
+ opts.banner = "\nUsage: backup [options]\n "
13
+
14
+ opts.on('-r', '--run [trigger]', "Runs backup process by trigger") do |trigger|
15
+ confirm_configuration_file_existence
16
+ Backup::Setup.new(trigger, @backup_procedures).initialize_adapter
17
+ end
18
+
19
+ opts.on('-f', '--find [trigger]', "Finds backup records by trigger") do |trigger|
20
+ confirm_configuration_file_existence
21
+ backup = Backup::Setup.new(trigger, @backup_procedures)
22
+ records = Array.new
23
+ case backup.procedure.storage_name.to_sym
24
+ when :s3 then records = Backup::Record::S3.all :conditions => {:trigger => trigger}
25
+ when :scp then records = Backup::Record::SCP.all :conditions => {:trigger => trigger}
26
+ when :ftp then records = Backup::Record::FTP.all :conditions => {:trigger => trigger}
27
+ when :sftp then records = Backup::Record::SFTP.all :conditions => {:trigger => trigger}
28
+ end
29
+
30
+ if options[:table]
31
+ puts Hirb::Helpers::AutoTable.render(records)
32
+ else
33
+ records.each do |record|
34
+ puts record.to_yaml
35
+ end
36
+ end
37
+ end
38
+
39
+ 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
49
+ end
50
+
51
+ opts.on('-d', '--destroy [trigger]', "Destroys backup records and files for specified trigger") do |trigger|
52
+ confirm_configuration_file_existence
53
+ backup = Backup::Setup.new(trigger, @backup_procedures)
54
+ case backup.procedure.storage_name.to_sym
55
+ when :s3 then Backup::Record::S3.destroy_all_backups backup.procedure, trigger
56
+ when :scp then Backup::Record::SCP.destroy_all_backups backup.procedure, trigger
57
+ when :ftp then Backup::Record::FTP.destroy_all_backups backup.procedure, trigger
58
+ when :sftp then Backup::Record::SFTP.destroy_all_backups backup.procedure, trigger
59
+ end
60
+ end
61
+
62
+ opts.on('--truncate-all', "Truncates all backup records") do
63
+ confirm_configuration_file_existence
64
+ Backup::Record::S3.destroy_all
65
+ Backup::Record::SCP.destroy_all
66
+ Backup::Record::FTP.destroy_all
67
+ Backup::Record::SFTP.destroy_all
68
+ end
69
+
70
+ opts.on('--destroy-all', "Destroys all backup records and files") do
71
+ confirm_configuration_file_existence
72
+ backup = Backup::Setup.new(false, @backup_procedures)
73
+ backup.procedures.each do |backup_procedure|
74
+ case backup_procedure.storage_name.to_sym
75
+ when :s3 then Backup::Record::S3.destroy_all_backups backup_procedure, backup_procedure.trigger
76
+ when :scp then Backup::Record::SCP.destroy_all_backups backup_procedure, backup_procedure.trigger
77
+ when :ftp then Backup::Record::FTP.destroy_all_backups backup_procedure, backup_procedure.trigger
78
+ when :sftp then Backup::Record::SFTP.destroy_all_backups backup_procedure, backup_procedure.trigger
79
+ end
80
+ end
81
+ end
82
+
83
+ opts.on('--decrypt [file]', "Decrypts a \"Backup\" encrypted file") do |file|
84
+ %x{ openssl enc -des-cbc -d -in #{file} -out #{file.gsub('.enc', '')} }
85
+ end
86
+
87
+ options[:table] = false
88
+ opts.on('--table', "Shows records in table format") do |format|
89
+ options[:table] = true
90
+ end
91
+
92
+ opts.on('--setup', "Sets up Backup") do
93
+ setup
94
+ end
95
+
96
+ opts.on('--reset', "Reinstalls Backup (This will remove ALL current settings!)") do
97
+ reset
98
+ end
99
+
100
+ opts.on('--remove', "Removes Backup (This will remove ALL current settings!)") do
101
+ remove
102
+ end
103
+
104
+ opts.on('-v', '--version', 'Displays installed Backup version') do
105
+ File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')) do |file|
106
+ puts "Backup version #{file.read}"
107
+ end
108
+ exit
109
+ end
110
+
111
+ opts.on('-h', '--help', 'Display help screen') do
112
+ puts opts
113
+ puts "\n "
114
+ exit
115
+ end
116
+
117
+ end
118
+
119
+ begin
120
+ optparse.parse!
121
+ rescue OptionParser::InvalidOption
122
+ puts "\nInvalid Option. See the list of available options below.\n"
123
+ puts optparse
124
+ puts "\n "
125
+ exit
126
+ end
@@ -1,46 +1,74 @@
1
- # Load in Connectivity and Transfer Gems
1
+ #
2
+ # Load Gems
3
+ #
2
4
  require 'net/ssh'
3
5
  require 'net/scp'
4
6
  require 'net/ftp'
5
7
  require 'net/sftp'
6
8
  require 'aws/s3'
9
+ require 'hirb'
7
10
 
8
- # Load in Adapters
11
+ #
12
+ # Load Environments
13
+ #
14
+ require 'backup/environment/base'
15
+ require 'backup/environment/unix'
16
+ require 'backup/environment/rails'
17
+
18
+ #
19
+ # Load Configuration
20
+ #
21
+ require 'backup/configuration/base'
22
+ require 'backup/configuration/adapter'
23
+ require 'backup/configuration/adapter_options'
24
+ require 'backup/configuration/storage'
25
+ require 'backup/configuration/helpers'
26
+
27
+ # Include the Configuration adn Environment Helpers
28
+ include Backup::Configuration::Helpers
29
+ include Backup::Environment::Base
30
+
31
+ # Load either UNIX or RAILS environment configuration
32
+ case current_environment
33
+ when :unix then include Backup::Environment::Unix
34
+ when :rails then include Backup::Environment::Rails
35
+ end
36
+
37
+ # Load configuration
38
+ if File.exist?(File.join(BACKUP_PATH, 'config', 'backup.rb'))
39
+ require File.join(BACKUP_PATH, 'config', 'backup.rb')
40
+ end
41
+
42
+ #
43
+ # Load Adapters
44
+ #
9
45
  require 'backup/adapters/base'
10
46
  require 'backup/adapters/mysql'
11
47
  require 'backup/adapters/postgresql'
12
48
  require 'backup/adapters/archive'
13
49
  require 'backup/adapters/custom'
14
50
 
15
- # Load in Connectors
51
+ #
52
+ # Load Connectors
53
+ #
16
54
  require 'backup/connection/s3'
17
55
 
18
- # Load in Storage
56
+ #
57
+ # Load Storage
58
+ #
19
59
  require 'backup/storage/s3'
20
60
  require 'backup/storage/scp'
21
61
  require 'backup/storage/ftp'
22
62
  require 'backup/storage/sftp'
23
63
 
24
- # Load in Backup Recorders
64
+ #
65
+ # Backup Recorders
66
+ #
25
67
  require 'backup/record/s3'
26
68
  require 'backup/record/scp'
27
69
  require 'backup/record/ftp'
28
70
  require 'backup/record/sftp'
29
71
 
30
- # Load in Configuration
31
- require 'backup/configuration/base'
32
- require 'backup/configuration/adapter'
33
- require 'backup/configuration/adapter_options'
34
- require 'backup/configuration/storage'
35
- require 'backup/configuration/helpers'
36
-
37
- # Load Backup Configuration Helpers
38
- include Backup::Configuration::Helpers
39
-
40
- # Load in User Configured Backup Procedures if the file exists
41
- if File.exist?(File.join(RAILS_ROOT, 'config', 'backup.rb'))
42
- require File.join(RAILS_ROOT, 'config', 'backup.rb')
43
- end
44
72
 
45
73
  # Backup Module
46
74
  module Backup
@@ -19,7 +19,7 @@ module Backup
19
19
  self.trigger = trigger
20
20
  self.procedure = procedure
21
21
  self.timestamp = Time.now.strftime("%Y%m%d%H%M%S")
22
- self.tmp_path = File.join(RAILS_ROOT.gsub(' ', '\ '), 'tmp', 'backup', trigger)
22
+ self.tmp_path = File.join(BACKUP_PATH.gsub(' ', '\ '), 'tmp', 'backup', trigger)
23
23
  self.encrypt_with_password = procedure.attributes['encrypt_with_password']
24
24
  self.keep_backups = procedure.attributes['keep_backups']
25
25
  create_tmp_folder
@@ -0,0 +1,12 @@
1
+ module Backup
2
+ module Environment
3
+ module Base
4
+
5
+ def current_environment
6
+ return :rails if defined?(RAILS_ENV)
7
+ return :unix
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Backup
2
+ module Environment
3
+ module Rails
4
+
5
+ if defined? RAILS_ENV
6
+
7
+ # Sets BACKUP_PATH equal to RAILS_ROOT
8
+ BACKUP_PATH = RAILS_ROOT
9
+
10
+ # Sets DB_CONNECTION_SETTINGS to false
11
+ DB_CONNECTION_SETTINGS = false
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,66 @@
1
+ module Backup
2
+ module Environment
3
+ module Unix
4
+
5
+ require 'active_record'
6
+ require 'optparse'
7
+
8
+ # Sets BACKUP_PATH equal to /opt/backup
9
+ BACKUP_PATH = "/opt/backup"
10
+
11
+ # Sets DB_CONNECTION_SETTINGS
12
+ DB_CONNECTION_SETTINGS = {
13
+ :adapter => "sqlite3",
14
+ :database => "/opt/backup/backup.sqlite3",
15
+ :pool => 5,
16
+ :timeout => 5000
17
+ }
18
+
19
+ module Commands
20
+
21
+ def setup
22
+ unless File.directory?(BACKUP_PATH)
23
+ puts "Installing Backup in #{BACKUP_PATH}.."
24
+ %x{ sudo mkdir -p #{File.join(BACKUP_PATH, 'config')} }
25
+ %x{ sudo cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.sqlite3')} #{BACKUP_PATH} }
26
+ %x{ sudo cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.rb')} #{File.join(BACKUP_PATH, 'config')} }
27
+ else
28
+ puts "\nBackup is already installed in #{BACKUP_PATH}..\n"
29
+ puts "If you want to reset it, run:\n\nbackup --reset\n\n"
30
+ puts "This will reinstall it."
31
+ puts "Warning: All configuration will be lost!\n\n"
32
+ end
33
+ end
34
+
35
+ def reset
36
+ if File.directory?(BACKUP_PATH)
37
+ remove
38
+ setup
39
+ else
40
+ puts "Backup is not installed.\n"
41
+ puts "Run the following command to install it:\n\nbackup --setup"
42
+ end
43
+ end
44
+
45
+ def remove
46
+ puts "Removing Backup..\n"
47
+ %x{ sudo rm -rf #{BACKUP_PATH} }
48
+ end
49
+ end
50
+
51
+ module Helpers
52
+
53
+ def confirm_configuration_file_existence
54
+ unless File.exist?(File.join(BACKUP_PATH, 'config', 'backup.rb'))
55
+ puts "\nBackup could not find the Backup Configuration File."
56
+ puts "Did you set up Backup? Do so if you haven't yet:"
57
+ puts "\nbackup --setup\n "
58
+ exit
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -1,7 +1,11 @@
1
1
  module Backup
2
2
  module Record
3
3
  class FTP < ActiveRecord::Base
4
-
4
+
5
+ if DB_CONNECTION_SETTINGS
6
+ establish_connection(DB_CONNECTION_SETTINGS)
7
+ end
8
+
5
9
  set_table_name 'backup'
6
10
  default_scope \
7
11
  :order => 'created_at desc',
@@ -2,18 +2,15 @@ module Backup
2
2
  module Record
3
3
  class S3 < ActiveRecord::Base
4
4
 
5
- if connection.table_exists?('backup')
6
- set_table_name 'backup'
7
- default_scope \
8
- :order => 'created_at desc',
9
- :conditions => {:storage => 's3'}
10
- else
11
- set_table_name 'backup_s3'
12
- attr_accessor :storage
13
- default_scope \
14
- :order => 'created_at desc'
5
+ if DB_CONNECTION_SETTINGS
6
+ establish_connection(DB_CONNECTION_SETTINGS)
15
7
  end
16
8
 
9
+ set_table_name 'backup'
10
+ default_scope \
11
+ :order => 'created_at desc',
12
+ :conditions => {:storage => 's3'}
13
+
17
14
  # Callbacks
18
15
  after_save :clean_backups
19
16
 
@@ -1,18 +1,15 @@
1
1
  module Backup
2
2
  module Record
3
3
  class SCP < ActiveRecord::Base
4
-
5
- if connection.table_exists?('backup')
6
- set_table_name 'backup'
7
- default_scope \
8
- :order => 'created_at desc',
9
- :conditions => {:storage => 'scp'}
10
- else
11
- set_table_name 'backup_scp'
12
- attr_accessor :storage
13
- default_scope \
14
- :order => 'created_at desc'
15
- end
4
+
5
+ if DB_CONNECTION_SETTINGS
6
+ establish_connection(DB_CONNECTION_SETTINGS)
7
+ end
8
+
9
+ set_table_name 'backup'
10
+ default_scope \
11
+ :order => 'created_at desc',
12
+ :conditions => {:storage => 'scp'}
16
13
 
17
14
  # Callbacks
18
15
  after_save :clean_backups
@@ -2,6 +2,10 @@ module Backup
2
2
  module Record
3
3
  class SFTP < ActiveRecord::Base
4
4
 
5
+ if DB_CONNECTION_SETTINGS
6
+ establish_connection(DB_CONNECTION_SETTINGS)
7
+ end
8
+
5
9
  set_table_name 'backup'
6
10
  default_scope \
7
11
  :order => 'created_at desc',
@@ -0,0 +1,150 @@
1
+ # Backup Configuration File
2
+ #
3
+ # Use the "backup" block to add backup settings to the configuration file.
4
+ # The argument before the "do" in (backup "argument" do) is called a "trigger".
5
+ # This acts as the identifier for the configuration.
6
+ #
7
+ # In the example below we have a "mysql-backup-s3" trigger for the backup setting.
8
+ # All the configuration is done inside this block. To initialize the backup process for this block,
9
+ # you invoke it using the following rake task:
10
+ #
11
+ # rake backup:run trigger="mysql-backup-s3"
12
+ #
13
+ # You can add as many backup block settings as you want, just be sure every trigger is unique and you can run
14
+ # each of them separately.
15
+ #
16
+ # ADAPTERS
17
+ # - MySQL
18
+ # - PostgreSQL
19
+ # - Archive
20
+ # - Custom
21
+ #
22
+ # STORAGE METHODS
23
+ # - S3 (Amazon)
24
+ # - SCP (Remote Server)
25
+ # - FTP (Remote Server)
26
+ # - SFTP (Remote Server)
27
+ #
28
+ # GLOBAL OPTIONS
29
+ # - Keep Backups (keep_backups)
30
+ # - Encrypt With Pasword (encrypt_with_password)
31
+ #
32
+ # This is the "decrypt" command for all encrypted backups:
33
+ # openssl enc -des-cbc -d -in encrypted_file -out decrypted_file
34
+ #
35
+ # Each Backup Setting can contain:
36
+ # - 1 Adapter
37
+ # - 1 Storage Method
38
+ # - Multiple Global Options
39
+ #
40
+ # The combination of these, however, do not matter! So experiment with it.
41
+ #
42
+ # For more information on "Backup", please refer to the wiki on github
43
+ # http://wiki.github.com/meskyanichi/backup/configuration-file
44
+
45
+
46
+ # Initialize with:
47
+ # rake backup:run trigger='mysql-backup-s3'
48
+ backup 'mysql-backup-s3' do
49
+
50
+ adapter :mysql do
51
+ user 'user'
52
+ password 'password'
53
+ database 'database'
54
+
55
+ # skip_tables ['table1', 'table2', 'table3']
56
+ #
57
+ # options do
58
+ # host '123.45.678.90'
59
+ # port '80'
60
+ # socket '/tmp/socket.sock'
61
+ # end
62
+ end
63
+
64
+ storage :s3 do
65
+ access_key_id 'access_key_id'
66
+ secret_access_key 'secret_access_key'
67
+ bucket '/bucket/backups/mysql/'
68
+ use_ssl true
69
+ end
70
+
71
+ keep_backups 25
72
+ encrypt_with_password 'password'
73
+
74
+ end
75
+
76
+
77
+ # Initialize with:
78
+ # rake backup:run trigger='postgresql-backup-s3'
79
+ backup 'postgresql-backup-scp' do
80
+
81
+ adapter :postgresql do
82
+ user 'user'
83
+ database 'database'
84
+
85
+ # skip_tables ['table1', 'table2', 'table3']
86
+
87
+ # options do
88
+ # host '123.45.678.90'
89
+ # port '80'
90
+ # socket '/tmp/socket.sock'
91
+ # end
92
+ end
93
+
94
+ storage :scp do
95
+ ip 'example.com'
96
+ user 'user'
97
+ password 'password'
98
+ path '/var/backups/postgresql/'
99
+ end
100
+
101
+ keep_backups :all
102
+ encrypt_with_password false
103
+
104
+ end
105
+
106
+
107
+ # Initialize with:
108
+ # rake backup:run trigger='archive-backup-ftp'
109
+ backup 'archive-backup-ftp' do
110
+
111
+ adapter :archive do
112
+ files ["log", "db"]
113
+ # files "log"
114
+ end
115
+
116
+ storage :ftp do
117
+ ip 'example.com'
118
+ user 'user'
119
+ password 'password'
120
+ path '/var/backups/archive/'
121
+ end
122
+
123
+ keep_backups 10
124
+ encrypt_with_password false
125
+
126
+ end
127
+
128
+
129
+ # Initialize with:
130
+ # rake backup:run trigger='custom-backup-sftp'
131
+ backup 'custom-backup-sftp' do
132
+
133
+ adapter :custom do
134
+ commands \
135
+ [ "mysqldump [options] [database] > :tmp_path/my_mysql_dump.sql",
136
+ "pg_dump [options] [database] > :tmp_path/my_postgresql_dump.sql",
137
+ "any_other_db_format [options] [database] > :tmp_path/my_any_other_db_format.sql" ]
138
+ end
139
+
140
+ storage :sftp do
141
+ ip 'example.com'
142
+ user 'user'
143
+ password 'password'
144
+ path '/var/backups/custom/'
145
+ end
146
+
147
+ keep_backups :all
148
+ encrypt_with_password 'password'
149
+
150
+ end
Binary file
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.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-06 00:00:00 +01:00
13
- default_executable:
12
+ date: 2009-12-08 00:00:00 +01:00
13
+ default_executable: backup
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-s3
@@ -52,10 +52,30 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 2.0.4
54
54
  version:
55
- description: "\n Backup is a Ruby Gem, written specifically for Ruby on Rails applications. This gem offers a quick and easy way to configure and run backups of your\n MySQL/PostgreSQL databases (and practically even any other database you can dump through the command line). It can also make backups of your archives (any files or folders).\n All backups can be transferred to either \"Amazon S3\" or \"any remotely accessible server using the SCP, SFTP or FTP transfer methods\".\n Backup handles: Compression, Archiving, Encryption and Backup Cleaning.\n "
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.5
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: sqlite3-ruby
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.2.5
74
+ version:
75
+ description: "\n Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the\n Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as\n MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you\n have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption\n and Backup Cleaning (Cycling).\n "
56
76
  email: meskyan@gmail.com
57
- executables: []
58
-
77
+ executables:
78
+ - backup
59
79
  extensions: []
60
80
 
61
81
  extra_rdoc_files:
@@ -70,6 +90,7 @@ files:
70
90
  - Rakefile
71
91
  - VERSION
72
92
  - backup.gemspec
93
+ - bin/backup
73
94
  - generators/backup/backup_generator.rb
74
95
  - generators/backup/templates/config/backup.rb
75
96
  - generators/backup/templates/migrations/create_backup_tables.rb
@@ -86,6 +107,9 @@ files:
86
107
  - lib/backup/configuration/helpers.rb
87
108
  - lib/backup/configuration/storage.rb
88
109
  - lib/backup/connection/s3.rb
110
+ - lib/backup/environment/base.rb
111
+ - lib/backup/environment/rails.rb
112
+ - lib/backup/environment/unix.rb
89
113
  - lib/backup/record/ftp.rb
90
114
  - lib/backup/record/s3.rb
91
115
  - lib/backup/record/scp.rb
@@ -94,6 +118,8 @@ files:
94
118
  - lib/backup/storage/s3.rb
95
119
  - lib/backup/storage/scp.rb
96
120
  - lib/backup/storage/sftp.rb
121
+ - setup/backup.rb
122
+ - setup/backup.sqlite3
97
123
  has_rdoc: true
98
124
  homepage: http://final-creation.com/open-source
99
125
  licenses: []
@@ -121,6 +147,6 @@ rubyforge_project:
121
147
  rubygems_version: 1.3.5
122
148
  signing_key:
123
149
  specification_version: 3
124
- summary: Backup is a gem/plugin that enables you to very easily create backups and transfer these to Amazon S3 or another server with SSH.
150
+ summary: Backup is a Ruby Gem that simplifies making backups for databases, files and folders.
125
151
  test_files: []
126
152