namxam-backup 2.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/CHANGELOG +131 -0
  2. data/LICENSE +20 -0
  3. data/README.md +122 -0
  4. data/bin/backup +108 -0
  5. data/generators/backup/backup_generator.rb +69 -0
  6. data/generators/backup/templates/backup.rake +56 -0
  7. data/generators/backup/templates/backup.rb +253 -0
  8. data/generators/backup/templates/create_backup_tables.rb +18 -0
  9. data/generators/backup_update/backup_update_generator.rb +50 -0
  10. data/generators/backup_update/templates/migrations/update_backup_tables.rb +27 -0
  11. data/lib/backup.rb +132 -0
  12. data/lib/backup/adapters/archive.rb +34 -0
  13. data/lib/backup/adapters/base.rb +167 -0
  14. data/lib/backup/adapters/custom.rb +41 -0
  15. data/lib/backup/adapters/mongo_db.rb +139 -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 +14 -0
  20. data/lib/backup/configuration/adapter.rb +21 -0
  21. data/lib/backup/configuration/adapter_options.rb +8 -0
  22. data/lib/backup/configuration/attributes.rb +19 -0
  23. data/lib/backup/configuration/base.rb +75 -0
  24. data/lib/backup/configuration/helpers.rb +24 -0
  25. data/lib/backup/configuration/mail.rb +20 -0
  26. data/lib/backup/configuration/smtp.rb +8 -0
  27. data/lib/backup/configuration/storage.rb +8 -0
  28. data/lib/backup/connection/cloudfiles.rb +75 -0
  29. data/lib/backup/connection/dropbox.rb +62 -0
  30. data/lib/backup/connection/s3.rb +88 -0
  31. data/lib/backup/core_ext/object.rb +5 -0
  32. data/lib/backup/environment/base.rb +12 -0
  33. data/lib/backup/environment/rails_configuration.rb +15 -0
  34. data/lib/backup/environment/unix_configuration.rb +109 -0
  35. data/lib/backup/mail/base.rb +97 -0
  36. data/lib/backup/mail/mail.txt +7 -0
  37. data/lib/backup/record/base.rb +65 -0
  38. data/lib/backup/record/cloudfiles.rb +28 -0
  39. data/lib/backup/record/dropbox.rb +27 -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 +25 -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/dropbox.rb +12 -0
  48. data/lib/backup/storage/ftp.rb +38 -0
  49. data/lib/backup/storage/local.rb +22 -0
  50. data/lib/backup/storage/s3.rb +15 -0
  51. data/lib/backup/storage/scp.rb +30 -0
  52. data/lib/backup/storage/sftp.rb +31 -0
  53. data/lib/backup/version.rb +3 -0
  54. data/lib/generators/backup/USAGE +10 -0
  55. data/lib/generators/backup/backup_generator.rb +47 -0
  56. data/lib/generators/backup/templates/backup.rake +56 -0
  57. data/lib/generators/backup/templates/backup.rb +236 -0
  58. data/lib/generators/backup/templates/create_backup_tables.rb +18 -0
  59. data/setup/backup.rb +255 -0
  60. data/setup/backup.sqlite3 +0 -0
  61. metadata +278 -0
@@ -0,0 +1,131 @@
1
+ UPDATE
2
+ === 2.4.1 ======================================
3
+
4
+ Dropbox storage added.
5
+
6
+
7
+ BIG UPDATE
8
+ === 2.4.0 =======================================
9
+
10
+ Ruby on Rails 3 support
11
+
12
+
13
+ PATCH
14
+ === 2.3.3.1 =====================================
15
+
16
+ Fixes an issue when trying to use S3. It would try to create a bucket
17
+ when one already exists and this raises an error.
18
+
19
+
20
+ UPDATE
21
+ === 2.3.3 =======================================
22
+
23
+ Set final_file to encrypted_file only when encryption is used.
24
+
25
+
26
+ UPDATE
27
+ === 2.3.2 =======================================
28
+
29
+ - Only load 'pony' and 'optparse' when they need to be utilized.
30
+ - Only uses 'sudo' if BACKUP_PATH is not writable by current user.
31
+ - With Cloud Files storage, it will automatically create the bucket if it does not yet exist.
32
+ - Backup's logger will now display the current time when logging. Now also indicates what S3 bucket it
33
+ is being backed up to, as well as what the filename is.
34
+ - Backup now supports GPG public key encryption which is a new and more safe way to encrypt your data.
35
+
36
+
37
+ MINOR UPDATE
38
+ === 2.3.2.pre3 ==================================
39
+
40
+ - Added support for Rackspace Cloud Files. Backups can now also be stored in Rackspace Cloud Files.
41
+
42
+
43
+ MINOR UPDATE
44
+ === 2.3.2.pre2 ==================================
45
+
46
+ - Added support for Amazon S3 EEUU and European buckets.
47
+
48
+
49
+ BIG UPDATE
50
+ === 2.3.2.pre ==================================
51
+
52
+ - Added Storage Method: Local
53
+ - Added Adapter: SQLite
54
+ - exclude option added for Archive Adapter
55
+ - Internal cleanup
56
+ - Will try to automatically determine the path to mysqldump and pg_dump utilities
57
+ - Option to specify which tables to include for the backup
58
+ - The ability to specify a custom backup (unix environment) installation folder with ENV['BACKUP_PATH']
59
+ - Fixed dependency issue with SQLite3 Ruby Driver (must be 1.2.5)
60
+ - Removed Jeweler from Backup, the Gemspec should be manually updated from now on.
61
+ - Added spec/tests
62
+
63
+
64
+ MINOR UPDATE
65
+ === 2.3.1 ======================================
66
+
67
+ - Added Feature: Email notifications
68
+
69
+
70
+ PATCH
71
+ === 2.3.0.3 ====================================
72
+
73
+ - Small bug was patched. Error would occur when a list of triggers should be shown
74
+
75
+
76
+ BIG UPDATE
77
+ === 2.3.0 ====================================
78
+
79
+ - Backup became independent of Ruby on Rails
80
+ - Backup now supports multiple environments: Rails and Unix
81
+ - Backup is now executable through the command-line when using the Unix environment
82
+
83
+
84
+ SMALL FEATURE UPDATE
85
+ === 2.2.1 ====================================
86
+
87
+ - use_ssl option added for S3 Storage Method
88
+ - additional_options option added for MySQL and PostgreSQL Adapters
89
+
90
+
91
+ PRETTY BIG UPDATE
92
+ === 2.2.0 ====================================
93
+
94
+ - Added Storage Methods: FTP and SFTP
95
+ - Added Adapters: PostgreSQL and Custom
96
+ - Added more options to the MySQL Adapter
97
+ - A couple of bug fixes
98
+
99
+
100
+ MINOR UPDATE
101
+ === 2.1.2 ====================================
102
+
103
+ - The backup generator will now provide you with a step-by-step guide to getting up and running
104
+ - Updated the generator itself
105
+ - Removed SQLite3 dependencies
106
+
107
+
108
+ 2 TABLES 2 1
109
+ === 2.1.1 ====================================
110
+
111
+ - Backup will from now on only utilize one table, instead of one for each storage method
112
+ - Still backwards compatible to 2.1.0
113
+
114
+
115
+ FIXED A CRUCIAL BUG
116
+ === 2.1.0 ====================================
117
+
118
+ - Problem with Backup::Record. It tried to connect to the SQLite3 database.
119
+
120
+
121
+ MAJOR RELEASE
122
+ === 2.0.0 ====================================
123
+
124
+ - Should be a lot more backwards compatible with every update I do.
125
+ - Does not depend on the separate local SQLite3 file any longer.
126
+ - Will provide a db migration file for your Rails Application to store backup record data in.
127
+ - Does not use YAML files to do configuration any longer.
128
+ - Uses a SINGLE ruby file for "all" configuration (config/backup.rb) using elegant block notations!
129
+ - Uses a SINGLE rake task to handle the initialization of any backup setting.
130
+ - Can now configure an unlimited amount of customizable backup settings and run them each "individually"!
131
+ - 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,122 @@
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, Dropbox Web Service, 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
+ ### Contributors
19
+
20
+ * [dtrueman](http://github.com/dtrueman)
21
+ * [Nathan L Smith](http://github.com/smith)
22
+ * [Francesc Esplugas](http://github.com/fesplugas)
23
+ * [wakiki](http://github.com/wakiki)
24
+ * [Dan Hixon](http://github.com/danhixon)
25
+ * [Adam Greene](http://github.com/skippy)
26
+ * [Dmitriy Novotochinov](http://github.com/trybeee)
27
+
28
+
29
+ ## Backup's Current Capabilities
30
+
31
+ ### Storage Methods
32
+
33
+ * Amazon S3
34
+ * Rackspace Cloud Files
35
+ * Dropbox (Using your API key/secret from developers.dropbox.com)
36
+ * Remote Server (Available Protocols: SCP, SFTP, FTP)
37
+ * Local server (Example Locations: Another Hard Drive, Network path)
38
+
39
+ ### Adapters
40
+
41
+ * MySQL
42
+ * PostgreSQL
43
+ * SQLite
44
+ * MongoDB
45
+ * Archive (Any files and/or folders)
46
+ * Custom (Anything you can produce using the command line)
47
+
48
+ ### Archiving
49
+
50
+ Handles archiving for the __Archive__ and __Custom__ adapters.
51
+
52
+ ### Encryption
53
+
54
+ Handles encryption of __all__ backups for __any__ adapter.
55
+ To decrypt a "Backup encrypted file" you can use Backup's built-in utility command:
56
+
57
+ sudo backup --decrypt /path/to/encrypted/file.enc
58
+
59
+ ### Backup Cleaning
60
+
61
+ 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.
62
+
63
+ ### Email Notifications
64
+
65
+ You will be able to specify whether you would like to be notified by email when a backup successfully been stored. Simply fill in the email configuration block and set "notify" to true inside the backup procedure you would like to be notified of.
66
+
67
+ ### Quick Example of a Single Backup Setting/Procedure inside the Backup Configuration File
68
+
69
+ backup 'mysql-backup-s3' do
70
+ adapter :mysql do
71
+ user 'user'
72
+ password 'password'
73
+ database 'database'
74
+ end
75
+ storage :s3 do
76
+ access_key_id 'access_key_id'
77
+ secret_access_key 'secret_access_key'
78
+ host 's3-ap-southeast-1.amazonaws.com'
79
+ bucket '/bucket/backups/mysql/'
80
+ use_ssl true
81
+ end
82
+ keep_backups 25
83
+ encrypt_with_password 'my_password'
84
+ notify true
85
+ end
86
+
87
+ Everything above should be pretty straightforward, so now, using the __trigger__ we specified between
88
+ the `backup` and `do` you can execute this backup procedure like so:
89
+
90
+ __Rails Environment__
91
+
92
+ rake backup:run trigger=mysql-backup-s3
93
+
94
+ __Unix Environment__
95
+
96
+ sudo backup --run mysql-backup-s3
97
+
98
+ That's it. This was a simple example of how it works.
99
+
100
+ ## Want to take Backup for a spin?
101
+
102
+ ### Wiki Pages
103
+
104
+ [Check out our (15) helpful wiki pages](http://github.com/meskyanichi/backup/wiki)
105
+
106
+
107
+ ### Requests
108
+
109
+ If anyone has any requests, please send us a message or post it in the [issue log](http://github.com/meskyanichi/backup/issues)!
110
+
111
+
112
+ ### Suggestions?
113
+
114
+ Send us a message! Fork the project!
115
+
116
+
117
+ ### Found a Bug?
118
+
119
+ [Report it](http://github.com/meskyanichi/backup/issues)
120
+
121
+
122
+ __Michael van Rooijen | Final Creation. ([http://michaelvanrooijen.com/](http://michaelvanrooijen.com))__
@@ -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