dmitryv-backup 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGELOG +125 -0
  2. data/LICENSE +20 -0
  3. data/README.md +180 -0
  4. data/VERSION +1 -0
  5. data/bin/backup +108 -0
  6. data/generators/backup/backup_generator.rb +69 -0
  7. data/generators/backup/templates/backup.rake +56 -0
  8. data/generators/backup/templates/backup.rb +229 -0
  9. data/generators/backup/templates/create_backup_tables.rb +18 -0
  10. data/generators/backup_update/backup_update_generator.rb +50 -0
  11. data/generators/backup_update/templates/migrations/update_backup_tables.rb +27 -0
  12. data/lib/backup.rb +131 -0
  13. data/lib/backup/adapters/archive.rb +34 -0
  14. data/lib/backup/adapters/base.rb +138 -0
  15. data/lib/backup/adapters/custom.rb +41 -0
  16. data/lib/backup/adapters/mysql.rb +60 -0
  17. data/lib/backup/adapters/postgresql.rb +56 -0
  18. data/lib/backup/adapters/sqlite.rb +25 -0
  19. data/lib/backup/command_helper.rb +11 -0
  20. data/lib/backup/compressors/base.rb +7 -0
  21. data/lib/backup/compressors/gzip.rb +9 -0
  22. data/lib/backup/compressors/seven_zip.rb +9 -0
  23. data/lib/backup/configuration/adapter.rb +21 -0
  24. data/lib/backup/configuration/adapter_options.rb +8 -0
  25. data/lib/backup/configuration/attributes.rb +19 -0
  26. data/lib/backup/configuration/base.rb +77 -0
  27. data/lib/backup/configuration/helpers.rb +24 -0
  28. data/lib/backup/configuration/mail.rb +20 -0
  29. data/lib/backup/configuration/smtp.rb +8 -0
  30. data/lib/backup/configuration/storage.rb +8 -0
  31. data/lib/backup/connection/cloudfiles.rb +75 -0
  32. data/lib/backup/connection/s3.rb +85 -0
  33. data/lib/backup/environment/base.rb +12 -0
  34. data/lib/backup/environment/rails_configuration.rb +15 -0
  35. data/lib/backup/environment/unix_configuration.rb +109 -0
  36. data/lib/backup/mail/base.rb +97 -0
  37. data/lib/backup/mail/mail.txt +7 -0
  38. data/lib/backup/record/base.rb +65 -0
  39. data/lib/backup/record/cloudfiles.rb +28 -0
  40. data/lib/backup/record/ftp.rb +39 -0
  41. data/lib/backup/record/local.rb +26 -0
  42. data/lib/backup/record/s3.rb +26 -0
  43. data/lib/backup/record/scp.rb +33 -0
  44. data/lib/backup/record/sftp.rb +38 -0
  45. data/lib/backup/storage/base.rb +10 -0
  46. data/lib/backup/storage/cloudfiles.rb +16 -0
  47. data/lib/backup/storage/ftp.rb +38 -0
  48. data/lib/backup/storage/local.rb +22 -0
  49. data/lib/backup/storage/s3.rb +17 -0
  50. data/lib/backup/storage/scp.rb +30 -0
  51. data/lib/backup/storage/sftp.rb +31 -0
  52. data/lib/generators/backup/USAGE +10 -0
  53. data/lib/generators/backup/backup_generator.rb +47 -0
  54. data/lib/generators/backup/templates/backup.rake +56 -0
  55. data/lib/generators/backup/templates/backup.rb +229 -0
  56. data/lib/generators/backup/templates/create_backup_tables.rb +18 -0
  57. data/setup/backup.rb +231 -0
  58. data/setup/backup.sqlite3 +0 -0
  59. metadata +271 -0
@@ -0,0 +1,125 @@
1
+ BIG UPDATE
2
+ === 2.4.0 =======================================
3
+
4
+ Ruby on Rails 3 support
5
+
6
+
7
+ PATCH
8
+ === 2.3.3.1 =====================================
9
+
10
+ Fixes an issue when trying to use S3. It would try to create a bucket
11
+ when one already exists and this raises an error.
12
+
13
+
14
+ UPDATE
15
+ === 2.3.3 =======================================
16
+
17
+ Set final_file to encrypted_file only when encryption is used.
18
+
19
+
20
+ UPDATE
21
+ === 2.3.2 =======================================
22
+
23
+ - Only load 'pony' and 'optparse' when they need to be utilized.
24
+ - Only uses 'sudo' if BACKUP_PATH is not writable by current user.
25
+ - With Cloud Files storage, it will automatically create the bucket if it does not yet exist.
26
+ - Backup's logger will now display the current time when logging. Now also indicates what S3 bucket it
27
+ is being backed up to, as well as what the filename is.
28
+ - Backup now supports GPG public key encryption which is a new and more safe way to encrypt your data.
29
+
30
+
31
+ MINOR UPDATE
32
+ === 2.3.2.pre3 ==================================
33
+
34
+ - Added support for Rackspace Cloud Files. Backups can now also be stored in Rackspace Cloud Files.
35
+
36
+
37
+ MINOR UPDATE
38
+ === 2.3.2.pre2 ==================================
39
+
40
+ - Added support for Amazon S3 EEUU and European buckets.
41
+
42
+
43
+ BIG UPDATE
44
+ === 2.3.2.pre ==================================
45
+
46
+ - Added Storage Method: Local
47
+ - Added Adapter: SQLite
48
+ - exclude option added for Archive Adapter
49
+ - Internal cleanup
50
+ - Will try to automatically determine the path to mysqldump and pg_dump utilities
51
+ - Option to specify which tables to include for the backup
52
+ - The ability to specify a custom backup (unix environment) installation folder with ENV['BACKUP_PATH']
53
+ - Fixed dependency issue with SQLite3 Ruby Driver (must be 1.2.5)
54
+ - Removed Jeweler from Backup, the Gemspec should be manually updated from now on.
55
+ - Added spec/tests
56
+
57
+
58
+ MINOR UPDATE
59
+ === 2.3.1 ======================================
60
+
61
+ - Added Feature: Email notifications
62
+
63
+
64
+ PATCH
65
+ === 2.3.0.3 ====================================
66
+
67
+ - Small bug was patched. Error would occur when a list of triggers should be shown
68
+
69
+
70
+ BIG UPDATE
71
+ === 2.3.0 ====================================
72
+
73
+ - Backup became independent of Ruby on Rails
74
+ - Backup now supports multiple environments: Rails and Unix
75
+ - Backup is now executable through the command-line when using the Unix environment
76
+
77
+
78
+ SMALL FEATURE UPDATE
79
+ === 2.2.1 ====================================
80
+
81
+ - use_ssl option added for S3 Storage Method
82
+ - additional_options option added for MySQL and PostgreSQL Adapters
83
+
84
+
85
+ PRETTY BIG UPDATE
86
+ === 2.2.0 ====================================
87
+
88
+ - Added Storage Methods: FTP and SFTP
89
+ - Added Adapters: PostgreSQL and Custom
90
+ - Added more options to the MySQL Adapter
91
+ - A couple of bug fixes
92
+
93
+
94
+ MINOR UPDATE
95
+ === 2.1.2 ====================================
96
+
97
+ - The backup generator will now provide you with a step-by-step guide to getting up and running
98
+ - Updated the generator itself
99
+ - Removed SQLite3 dependencies
100
+
101
+
102
+ 2 TABLES 2 1
103
+ === 2.1.1 ====================================
104
+
105
+ - Backup will from now on only utilize one table, instead of one for each storage method
106
+ - Still backwards compatible to 2.1.0
107
+
108
+
109
+ FIXED A CRUCIAL BUG
110
+ === 2.1.0 ====================================
111
+
112
+ - Problem with Backup::Record. It tried to connect to the SQLite3 database.
113
+
114
+
115
+ MAJOR RELEASE
116
+ === 2.0.0 ====================================
117
+
118
+ - Should be a lot more backwards compatible with every update I do.
119
+ - Does not depend on the separate local SQLite3 file any longer.
120
+ - Will provide a db migration file for your Rails Application to store backup record data in.
121
+ - Does not use YAML files to do configuration any longer.
122
+ - Uses a SINGLE ruby file for "all" configuration (config/backup.rb) using elegant block notations!
123
+ - Uses a SINGLE rake task to handle the initialization of any backup setting.
124
+ - Can now configure an unlimited amount of customizable backup settings and run them each "individually"!
125
+ - HIGHLY IMPROVED USABILITY!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Michael van Rooijen - Final Creation (http://michaelvanrooijen.com/)
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.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ 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.
@@ -0,0 +1,180 @@
1
+ # Backup
2
+
3
+ ## A Backup Ruby Gem
4
+
5
+ __Backup__ is a Ruby Gem written for __Unix__ and __Ruby on Rails (2 and 3)__ 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/SQLite and Files/Folders. All backups can be transferred to Amazon S3, Rackspace Cloud Files, any remote server you have access to (using either SCP, SFTP or regular FTP), or a Local server. Backup handles Compression, Archiving, Encryption, Backup Cleaning (Cycling) and supports Email Notifications.
6
+
7
+ ## Written for Environments
8
+
9
+ * UNIX (Ubuntu, OSX, etc.)
10
+ * Ruby on Rails 3
11
+ * Ruby on Rails 2
12
+
13
+ ## Authors/Maintainers
14
+
15
+ * [Meskyanichi - Michael van Rooijen](http://github.com/meskyanichi)
16
+ * [Fernandoluizao - Fernando Migliorini Luizão](http://github.com/fernandoluizao)
17
+
18
+ ## Backup's Current Capabilities
19
+
20
+ ### Storage Methods
21
+
22
+ * Amazon S3
23
+ * Rackspace Cloud Files
24
+ * Remote Server (Available Protocols: SCP, SFTP, FTP)
25
+ * Local server (Example Locations: Another Hard Drive, Network path)
26
+
27
+ ### Adapters
28
+
29
+ * MySQL
30
+ * PostgreSQL
31
+ * SQLite
32
+ * Archive (Any files and/or folders)
33
+ * Custom (Anything you can produce using the command line)
34
+
35
+ ### Archiving
36
+
37
+ Handles archiving for the __Archive__ and __Custom__ adapters.
38
+
39
+ ### Encryption
40
+
41
+ Handles encryption of __all__ backups for __any__ adapter.
42
+ To decrypt a "Backup encrypted file" you can use Backup's built-in utility command:
43
+
44
+ sudo backup --decrypt /path/to/encrypted/file.enc
45
+
46
+ ### Backup Cleaning
47
+
48
+ With Backup you can very easily specify how many backups you would like to have stored (per backup procedure!) on your Amazon S3, Remote or Local server. When the limit you specify gets exceeded, the oldest backup will automatically be cleaned up.
49
+
50
+ ### Email Notifications
51
+
52
+ You will be able to specify whether you would like to be notified by email when a backup successfully been stored.
53
+ Simply fill in the email configuration block and set "notify" to true inside the backup procedure you would like to be notified of.
54
+
55
+ ### Quick Example of a Single Backup Setting/Procedure inside the Backup Configuration File
56
+
57
+ backup 'mysql-backup-s3' do
58
+ adapter :mysql do
59
+ user 'user'
60
+ password 'password'
61
+ database 'database'
62
+ end
63
+ storage :s3 do
64
+ access_key_id 'access_key_id'
65
+ secret_access_key 'secret_access_key'
66
+ bucket '/bucket/backups/mysql/'
67
+ use_ssl true
68
+ end
69
+ keep_backups 25
70
+ encrypt_with_password 'my_password'
71
+ notify true
72
+ end
73
+
74
+ Everything above should be pretty straightforward, so now, using the __trigger__ we specified between
75
+ the `backup` and `do` you can execute this backup procedure like so:
76
+
77
+ __Rails Environment__
78
+
79
+ rake backup:run trigger=mysql-backup-s3
80
+
81
+ __Unix Environment__
82
+
83
+ sudo backup --run mysql-backup-s3
84
+
85
+ That's it. This was a simple example of how it works.
86
+
87
+ ## Interested in trying out Backup?
88
+
89
+ ### Getting started with Backup for the *Unix Environment*
90
+
91
+ [http://wiki.github.com/meskyanichi/backup/getting-started-unix](http://wiki.github.com/meskyanichi/backup/getting-started-unix)
92
+
93
+
94
+ ### Getting started with Backup for the *Rails Environment*
95
+
96
+ [http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails](http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails)
97
+
98
+
99
+ ### Production Mode __RAILS_ENV___
100
+
101
+ [http://wiki.github.com/meskyanichi/backup/production-mode](http://wiki.github.com/meskyanichi/backup/production-mode)
102
+
103
+
104
+ ### Encrypting and Decrypting
105
+
106
+ [http://wiki.github.com/meskyanichi/backup/encrypting-and-decrypting](http://wiki.github.com/meskyanichi/backup/encrypting-and-decrypting)
107
+
108
+
109
+ ### Backup Configuration File (All Adapters, Storage Methods, Mail Settings and Options)
110
+
111
+ [http://wiki.github.com/meskyanichi/backup/configuration-file](http://wiki.github.com/meskyanichi/backup/configuration-file)
112
+
113
+
114
+ ### Unix Utility Commands and Rails Rake Tasks
115
+
116
+ [http://wiki.github.com/meskyanichi/backup/utility-commands](http://wiki.github.com/meskyanichi/backup/utility-commands)
117
+
118
+ [http://wiki.github.com/meskyanichi/backup/rake-tasks](http://wiki.github.com/meskyanichi/backup/rake-tasks)
119
+
120
+
121
+ ### Automatic Backups
122
+
123
+ [http://wiki.github.com/meskyanichi/backup/automatic-backups](http://wiki.github.com/meskyanichi/backup/automatic-backups)
124
+
125
+
126
+ ### Capistrano Recipes
127
+
128
+ [http://wiki.github.com/meskyanichi/backup/capistrano-recipes](http://wiki.github.com/meskyanichi/backup/capistrano-recipes)
129
+
130
+
131
+ ### Capistrano, Whenever!
132
+
133
+ [http://wiki.github.com/meskyanichi/backup/capistrano-whenever](http://wiki.github.com/meskyanichi/backup/capistrano-whenever)
134
+
135
+
136
+ ### Understanding "The Backup Database"
137
+
138
+ [http://wiki.github.com/meskyanichi/backup/the-backup-database](http://wiki.github.com/meskyanichi/backup/the-backup-database)
139
+
140
+
141
+ ### Trouble Shooting
142
+
143
+ [http://wiki.github.com/meskyanichi/backup/troubleshooting](http://wiki.github.com/meskyanichi/backup/troubleshooting)
144
+
145
+
146
+ ### Requirements
147
+
148
+ [http://wiki.github.com/meskyanichi/backup/requirements](http://wiki.github.com/meskyanichi/backup/requirements)
149
+
150
+
151
+ ### Resources
152
+
153
+ [http://wiki.github.com/meskyanichi/backup/resources](http://wiki.github.com/meskyanichi/backup/resources)
154
+
155
+
156
+ ### Requests
157
+
158
+ If anyone has any requests, please send us a message or post it in the [issue log](http://github.com/meskyanichi/backup/issues)!
159
+
160
+
161
+ ### Suggestions?
162
+
163
+ Send us a message! Fork the project!
164
+
165
+
166
+ ### Found a Bug?
167
+
168
+ [Report it](http://github.com/meskyanichi/backup/issues)
169
+
170
+
171
+ ### Contributors
172
+
173
+ * [dtrueman](http://github.com/dtrueman)
174
+ * [Nathan L Smith](http://github.com/smith)
175
+ * [Francesc Esplugas](http://github.com/fesplugas)
176
+ * [wakiki](http://github.com/wakiki)
177
+ * [Dan Hixon](http://github.com/danhixon)
178
+ * [Adam Greene](http://github.com/skippy)
179
+
180
+ __Michael van Rooijen | Final Creation. ([http://michaelvanrooijen.com](http://michaelvanrooijen.com))__
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.4.0
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'backup'
5
+
6
+ Backup::System.boot!
7
+
8
+ include Backup::Environment::UnixConfiguration::Commands
9
+ include Backup::Environment::UnixConfiguration::Helpers
10
+
11
+ options = {}
12
+
13
+ optparse = OptionParser.new do |opts|
14
+
15
+ opts.banner = "\nUsage: backup [options]\n "
16
+
17
+ opts.on('-r', '--run [trigger]', "Runs backup process by trigger") do |trigger|
18
+ confirm_configuration_file_existence
19
+ puts "Running: #{trigger}."
20
+ Backup::Setup.new(trigger, @backup_procedures).initialize_adapter
21
+ end
22
+
23
+ opts.on('-f', '--find [trigger]', "Finds backup records by trigger") do |trigger|
24
+ confirm_configuration_file_existence
25
+ puts "Finding backup records with trigger: #{trigger}."
26
+ backup = Backup::Setup.new(trigger, @backup_procedures)
27
+ records = backup.procedure.record_class.all( :conditions => {:trigger => trigger} )
28
+
29
+ if options[:table]
30
+ puts Hirb::Helpers::AutoTable.render(records)
31
+ else
32
+ records.each do |record|
33
+ puts record.to_yaml
34
+ end
35
+ end
36
+ end
37
+
38
+ opts.on('-t', '--truncate [trigger]', "Truncates backup records for specified trigger") do |trigger|
39
+ puts "Truncating backup records with trigger: #{trigger}."
40
+ Backup::Record::Base.destroy_all :trigger => trigger
41
+ end
42
+
43
+ opts.on('-d', '--destroy [trigger]', "Destroys backup records and files for specified trigger") do |trigger|
44
+ confirm_configuration_file_existence
45
+ puts "Destroying backup records with trigger: #{trigger}."
46
+ backup = Backup::Setup.new(trigger, @backup_procedures)
47
+ backup.procedure.record_class.destroy_all_backups( backup.procedure, trigger )
48
+ end
49
+
50
+ opts.on('--truncate-all', "Truncates all backup records") do
51
+ puts "Truncating all backup records."
52
+ Backup::Record::Base.destroy_all
53
+ end
54
+
55
+ opts.on('--destroy-all', "Destroys all backup records and files") do
56
+ confirm_configuration_file_existence
57
+ puts "Destroying all backup records."
58
+ backup = Backup::Setup.new(false, @backup_procedures)
59
+ backup.procedures.each do |backup_procedure|
60
+ backup_procedure.record_class.destroy_all_backups( backup_procedure, backup_procedure.trigger )
61
+ end
62
+ end
63
+
64
+ opts.on('--decrypt [file]', "Decrypts a \"Backup\" encrypted file") do |file|
65
+ puts "Attempting to decrypt: #{file}."
66
+ %x{ openssl enc -des-cbc -d -in #{file} -out #{file.gsub('.enc', '')} }
67
+ end
68
+
69
+ options[:table] = false
70
+ opts.on('--table', "Shows records in table format") do |format|
71
+ options[:table] = true
72
+ end
73
+
74
+ opts.on('--setup', "Sets up Backup") do
75
+ setup
76
+ end
77
+
78
+ opts.on('--reset', "Reinstalls Backup (This will remove ALL current settings!)") do
79
+ reset
80
+ end
81
+
82
+ opts.on('--remove', "Removes Backup (This will remove ALL current settings!)") do
83
+ remove
84
+ end
85
+
86
+ opts.on('-v', '--version', 'Displays installed Backup version') do
87
+ File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')) do |file|
88
+ puts "Backup version #{file.read}"
89
+ end
90
+ exit
91
+ end
92
+
93
+ opts.on('-h', '--help', 'Display help screen') do
94
+ puts opts
95
+ puts "\n "
96
+ exit
97
+ end
98
+
99
+ end
100
+
101
+ begin
102
+ optparse.parse!
103
+ rescue OptionParser::InvalidOption
104
+ puts "\nInvalid Option. See the list of available options below.\n"
105
+ puts optparse
106
+ puts "\n "
107
+ exit
108
+ end
@@ -0,0 +1,69 @@
1
+ class BackupGenerator < Rails::Generator::Base
2
+
3
+ # This method gets initialized when the generator gets run.
4
+ # It will receive an array of arguments inside @args
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ end
8
+
9
+ # Processes the file generation/templating
10
+ # This will automatically be run after the initialize method
11
+ def manifest
12
+ record do |m|
13
+
14
+ # Generates the Rake Tasks and Backup Database
15
+ m.directory "lib/tasks"
16
+ m.file "backup.rake", "lib/tasks/backup.rake"
17
+
18
+ # Generates the configuration file
19
+ m.directory "config"
20
+ m.file "backup.rb", "config/backup.rb"
21
+
22
+ # Generates the database migration file
23
+ m.migration_template "create_backup_tables.rb",
24
+ "db/migrate",
25
+ :migration_file_name => "create_backup_tables"
26
+
27
+ # Outputs the generators message to the terminal
28
+ puts message
29
+ end
30
+ end
31
+
32
+ def message
33
+ <<-MESSAGE
34
+
35
+
36
+ ==============================================================
37
+ Backup's files have been generated!
38
+ ==============================================================
39
+
40
+ 1: Add the "Backup" gem to the config/environment.rb file!
41
+
42
+ config.gem "backup"
43
+
44
+
45
+ 2: Migrate the database!
46
+
47
+ rake db:migrate
48
+
49
+
50
+ 3: Set up some "Backup Settings" inside the backup configuration file!
51
+
52
+ config/backup.rb
53
+
54
+
55
+ 4: Run the backups! Enjoy.
56
+
57
+ rake backup:run trigger="your-specified-trigger"
58
+
59
+
60
+ For More Information:
61
+ http://github.com/meskyanichi/backup
62
+
63
+ ==============================================================
64
+
65
+
66
+ MESSAGE
67
+ end
68
+
69
+ end