backup 3.0.3.build.0 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. data/.gitignore +2 -0
  2. data/.infinity_test +7 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +17 -0
  5. data/Gemfile.lock +88 -0
  6. data/LICENSE.md +24 -0
  7. data/README.md +236 -0
  8. data/backup.gemspec +41 -0
  9. data/bin/backup +191 -12
  10. data/lib/backup.rb +162 -0
  11. data/lib/backup/archive.rb +54 -0
  12. data/lib/backup/cli.rb +50 -0
  13. data/lib/backup/compressor/base.rb +17 -0
  14. data/lib/backup/compressor/gzip.rb +61 -0
  15. data/lib/backup/configuration/base.rb +15 -0
  16. data/lib/backup/configuration/compressor/base.rb +10 -0
  17. data/lib/backup/configuration/compressor/gzip.rb +23 -0
  18. data/lib/backup/configuration/database/base.rb +18 -0
  19. data/lib/backup/configuration/database/mongodb.rb +37 -0
  20. data/lib/backup/configuration/database/mysql.rb +37 -0
  21. data/lib/backup/configuration/database/postgresql.rb +37 -0
  22. data/lib/backup/configuration/database/redis.rb +35 -0
  23. data/lib/backup/configuration/encryptor/base.rb +10 -0
  24. data/lib/backup/configuration/encryptor/gpg.rb +17 -0
  25. data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
  26. data/lib/backup/configuration/helpers.rb +54 -0
  27. data/lib/backup/configuration/notifier/base.rb +39 -0
  28. data/lib/backup/configuration/notifier/mail.rb +52 -0
  29. data/lib/backup/configuration/storage/base.rb +18 -0
  30. data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
  31. data/lib/backup/configuration/storage/dropbox.rb +25 -0
  32. data/lib/backup/configuration/storage/ftp.rb +25 -0
  33. data/lib/backup/configuration/storage/rsync.rb +25 -0
  34. data/lib/backup/configuration/storage/s3.rb +25 -0
  35. data/lib/backup/configuration/storage/scp.rb +25 -0
  36. data/lib/backup/configuration/storage/sftp.rb +25 -0
  37. data/lib/backup/configuration/syncer/rsync.rb +45 -0
  38. data/lib/backup/database/base.rb +33 -0
  39. data/lib/backup/database/mongodb.rb +137 -0
  40. data/lib/backup/database/mysql.rb +104 -0
  41. data/lib/backup/database/postgresql.rb +111 -0
  42. data/lib/backup/database/redis.rb +105 -0
  43. data/lib/backup/encryptor/base.rb +17 -0
  44. data/lib/backup/encryptor/gpg.rb +78 -0
  45. data/lib/backup/encryptor/open_ssl.rb +67 -0
  46. data/lib/backup/finder.rb +39 -0
  47. data/lib/backup/logger.rb +86 -0
  48. data/lib/backup/model.rb +272 -0
  49. data/lib/backup/notifier/base.rb +29 -0
  50. data/lib/backup/notifier/binder.rb +32 -0
  51. data/lib/backup/notifier/mail.rb +141 -0
  52. data/lib/backup/notifier/templates/notify_failure.erb +31 -0
  53. data/lib/backup/notifier/templates/notify_success.erb +16 -0
  54. data/lib/backup/storage/base.rb +67 -0
  55. data/lib/backup/storage/cloudfiles.rb +95 -0
  56. data/lib/backup/storage/dropbox.rb +82 -0
  57. data/lib/backup/storage/ftp.rb +114 -0
  58. data/lib/backup/storage/object.rb +45 -0
  59. data/lib/backup/storage/rsync.rb +99 -0
  60. data/lib/backup/storage/s3.rb +108 -0
  61. data/lib/backup/storage/scp.rb +105 -0
  62. data/lib/backup/storage/sftp.rb +106 -0
  63. data/lib/backup/syncer/rsync.rb +119 -0
  64. data/lib/backup/version.rb +72 -0
  65. data/lib/templates/archive +4 -0
  66. data/lib/templates/compressor/gzip +4 -0
  67. data/lib/templates/database/mongodb +10 -0
  68. data/lib/templates/database/mysql +11 -0
  69. data/lib/templates/database/postgresql +11 -0
  70. data/lib/templates/database/redis +10 -0
  71. data/lib/templates/encryptor/gpg +9 -0
  72. data/lib/templates/encryptor/openssl +5 -0
  73. data/lib/templates/notifier/mail +14 -0
  74. data/lib/templates/readme +15 -0
  75. data/lib/templates/storage/cloudfiles +7 -0
  76. data/lib/templates/storage/dropbox +8 -0
  77. data/lib/templates/storage/ftp +8 -0
  78. data/lib/templates/storage/rsync +7 -0
  79. data/lib/templates/storage/s3 +8 -0
  80. data/lib/templates/storage/scp +8 -0
  81. data/lib/templates/storage/sftp +8 -0
  82. data/lib/templates/syncer/rsync +14 -0
  83. data/spec/archive_spec.rb +53 -0
  84. data/spec/backup_spec.rb +11 -0
  85. data/spec/compressor/gzip_spec.rb +59 -0
  86. data/spec/configuration/base_spec.rb +35 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +28 -0
  88. data/spec/configuration/database/base_spec.rb +16 -0
  89. data/spec/configuration/database/mongodb_spec.rb +30 -0
  90. data/spec/configuration/database/mysql_spec.rb +32 -0
  91. data/spec/configuration/database/postgresql_spec.rb +32 -0
  92. data/spec/configuration/database/redis_spec.rb +30 -0
  93. data/spec/configuration/encryptor/gpg_spec.rb +25 -0
  94. data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
  95. data/spec/configuration/notifier/mail_spec.rb +32 -0
  96. data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
  97. data/spec/configuration/storage/dropbox_spec.rb +40 -0
  98. data/spec/configuration/storage/ftp_spec.rb +40 -0
  99. data/spec/configuration/storage/rsync_spec.rb +37 -0
  100. data/spec/configuration/storage/s3_spec.rb +37 -0
  101. data/spec/configuration/storage/scp_spec.rb +40 -0
  102. data/spec/configuration/storage/sftp_spec.rb +40 -0
  103. data/spec/configuration/syncer/rsync_spec.rb +46 -0
  104. data/spec/database/base_spec.rb +30 -0
  105. data/spec/database/mongodb_spec.rb +144 -0
  106. data/spec/database/mysql_spec.rb +150 -0
  107. data/spec/database/postgresql_spec.rb +164 -0
  108. data/spec/database/redis_spec.rb +122 -0
  109. data/spec/encryptor/gpg_spec.rb +57 -0
  110. data/spec/encryptor/open_ssl_spec.rb +102 -0
  111. data/spec/logger_spec.rb +46 -0
  112. data/spec/model_spec.rb +236 -0
  113. data/spec/notifier/mail_spec.rb +97 -0
  114. data/spec/spec_helper.rb +21 -0
  115. data/spec/storage/base_spec.rb +33 -0
  116. data/spec/storage/cloudfiles_spec.rb +102 -0
  117. data/spec/storage/dropbox_spec.rb +89 -0
  118. data/spec/storage/ftp_spec.rb +133 -0
  119. data/spec/storage/object_spec.rb +74 -0
  120. data/spec/storage/rsync_spec.rb +115 -0
  121. data/spec/storage/s3_spec.rb +110 -0
  122. data/spec/storage/scp_spec.rb +129 -0
  123. data/spec/storage/sftp_spec.rb +125 -0
  124. data/spec/syncer/rsync_spec.rb +156 -0
  125. data/spec/version_spec.rb +32 -0
  126. metadata +195 -6
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
@@ -0,0 +1,7 @@
1
+ infinity_test do
2
+ heuristics do
3
+ add('lib/') do |file|
4
+ run :all => :tests
5
+ end
6
+ end
7
+ end
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format Fuubar
2
+ --color
3
+ --tty
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ ##
2
+ # RubyGems Source
3
+ source 'http://rubygems.org'
4
+
5
+ ##
6
+ # Bundle gems definde inside the gemspec file
7
+ gemspec
8
+
9
+ ##
10
+ # Define gems to be used in the 'test' environment
11
+ group :test do
12
+ gem 'rspec'
13
+ gem 'mocha'
14
+ gem 'infinity_test'
15
+ gem 'fuubar'
16
+ gem 'timecop'
17
+ end
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ backup (3.0.3)
5
+ dropbox (~> 1.2.3)
6
+ fog (~> 0.5.3)
7
+ mail (~> 2.2.15)
8
+ net-scp (~> 1.0.4)
9
+ net-sftp (~> 2.0.5)
10
+ thor (~> 0.14.6)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ activesupport (3.0.5)
16
+ builder (3.0.0)
17
+ diff-lcs (1.1.2)
18
+ dropbox (1.2.3)
19
+ json (>= 1.2.0)
20
+ mechanize (>= 1.0.0)
21
+ multipart-post (>= 1.0)
22
+ oauth (>= 0.3.6)
23
+ excon (0.5.6)
24
+ fog (0.5.3)
25
+ builder
26
+ excon (>= 0.5.2)
27
+ formatador (>= 0.0.16)
28
+ json
29
+ mime-types
30
+ net-ssh (>= 2.0.23)
31
+ nokogiri (>= 1.4.4)
32
+ ruby-hmac
33
+ formatador (0.0.16)
34
+ fuubar (0.0.3)
35
+ rspec (~> 2.0)
36
+ rspec-instafail (~> 0.1.4)
37
+ ruby-progressbar (~> 0.0.9)
38
+ i18n (0.5.0)
39
+ infinity_test (1.0.2)
40
+ notifiers (>= 1.1.0)
41
+ watchr (>= 0.7)
42
+ json (1.5.1)
43
+ mail (2.2.15)
44
+ activesupport (>= 2.3.6)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mechanize (1.0.0)
49
+ nokogiri (>= 1.2.1)
50
+ mime-types (1.16)
51
+ mocha (0.9.12)
52
+ multipart-post (1.1.0)
53
+ net-scp (1.0.4)
54
+ net-ssh (>= 1.99.1)
55
+ net-sftp (2.0.5)
56
+ net-ssh (>= 2.0.9)
57
+ net-ssh (2.1.3)
58
+ nokogiri (1.4.4)
59
+ notifiers (1.1.0)
60
+ oauth (0.4.4)
61
+ polyglot (0.3.1)
62
+ rspec (2.5.0)
63
+ rspec-core (~> 2.5.0)
64
+ rspec-expectations (~> 2.5.0)
65
+ rspec-mocks (~> 2.5.0)
66
+ rspec-core (2.5.1)
67
+ rspec-expectations (2.5.0)
68
+ diff-lcs (~> 1.1.2)
69
+ rspec-instafail (0.1.6)
70
+ rspec-mocks (2.5.0)
71
+ ruby-hmac (0.4.0)
72
+ ruby-progressbar (0.0.9)
73
+ thor (0.14.6)
74
+ timecop (0.3.5)
75
+ treetop (1.4.9)
76
+ polyglot (>= 0.3.1)
77
+ watchr (0.7)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ backup!
84
+ fuubar
85
+ infinity_test
86
+ mocha
87
+ rspec
88
+ timecop
@@ -0,0 +1,24 @@
1
+
2
+ Copyright (c) 2009-2011 Michael van Rooijen ( [@meskyanichi](http://twitter.com/#!/meskyanichi) )
3
+ =================================================================================================
4
+
5
+ The "Backup" RubyGem is released under the **MIT LICENSE**
6
+ ----------------------------------------------------------
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
@@ -0,0 +1,236 @@
1
+ Backup 3
2
+ ========
3
+
4
+ Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL. It supports various databases (MySQL, PostgreSQL, MongoDB and Redis), it supports various storage locations (Amazon S3, Rackspace Cloud Files, Dropbox, any remote server through FTP, SFTP, SCP and RSync), it can archive files and folders, it can cycle backups, it can do incremental backups, it can compress backups, it can encrypt backups (OpenSSL or GPG), it can notify you about successful and/or failed backups. It is very extensible and easy to add new functionality to. It's easy to use.
5
+
6
+ Author
7
+ ------
8
+
9
+ Michael van Rooijen ( [@meskyanichi](http://twitter.com/#!/meskyanichi) )
10
+
11
+ Drop me a message for any questions, suggestions, requests, bugs or submit them to the [issue log](https://github.com/meskyanichi/backup/issues).
12
+
13
+ Installation
14
+ ------------
15
+
16
+ To get the latest stable version
17
+
18
+ gem install backup
19
+
20
+ To get the latest *build* of the latest stable version
21
+
22
+ gem install backup --pre
23
+
24
+ Builds **aim** to be stable, but cannot guarantee it. Builds tend to be released a lot more frequent than the stable versions. So if you want to live on the edge and want the latest improvements, install the build gems.
25
+
26
+ You can view the list of released versions over at [RubyGems.org (Backup)](https://rubygems.org/gems/backup/versions)
27
+
28
+
29
+ What Backup 3 currently supports
30
+ ================================
31
+
32
+ **Below you find a summary of what the Backup gem currently supports. Each of the items below is more or less isolated from each other, meaning that adding new databases, storage locations, compressors, encryptors, notifiers, and such is relatively easy to do.**
33
+
34
+ Database Support
35
+ ----------------
36
+
37
+ - MySQL
38
+ - PostgreSQL
39
+ - MongoDB
40
+ - Redis
41
+
42
+ [Database Wiki Page](https://github.com/meskyanichi/backup/wiki/Databases)
43
+
44
+ Filesystem Support
45
+ ------------------
46
+
47
+ - Files
48
+ - Folders
49
+
50
+ [Archive Wiki Page](https://github.com/meskyanichi/backup/wiki/Archives)
51
+
52
+ Storage Locations
53
+ -----------------
54
+
55
+ - Amazon Simple Storage Service (S3)
56
+ - Rackspace Cloud Files (Mosso)
57
+ - Dropbox
58
+ - Remote Servers *(Available Protocols: FTP, SFTP, SCP and RSync)*
59
+
60
+ [Storage Wiki Page](https://github.com/meskyanichi/backup/wiki/Storages)
61
+
62
+ Storage Features
63
+ ----------------
64
+
65
+ - Backup Cycling, applies to:
66
+ - Amazon Simple Storage Service (S3)
67
+ - Rackspace Cloud Files (Mosso)
68
+ - Dropbox
69
+ - Remote Servers *(Only Protocols: FTP, SFTP, SCP)*
70
+ - Incremental Backups, applies to:
71
+ - Remote Servers *(Only Protocols: RSync)*
72
+
73
+ [Storage Wiki Page](https://github.com/meskyanichi/backup/wiki/Storages)
74
+
75
+ Compressors
76
+ -----------
77
+
78
+ - Gzip
79
+
80
+ [Compressors Wiki Page](https://github.com/meskyanichi/backup/wiki/Compressors)
81
+
82
+ Encryptors
83
+ ----------
84
+
85
+ - OpenSSL
86
+ - GPG
87
+
88
+ [Encryptors Wiki Page](https://github.com/meskyanichi/backup/wiki/Encryptors)
89
+
90
+ Notifiers
91
+ ---------
92
+
93
+ - Mail
94
+
95
+ [Notifiers Wiki Page](https://github.com/meskyanichi/backup/wiki/Notifiers)
96
+
97
+ Supported Ruby versions (Tested with RSpec)
98
+ -------------------------------------------
99
+
100
+ - Ruby 1.9.2
101
+ - Ruby 1.8.7
102
+ - Ruby Enterprise Edition 1.8.7
103
+
104
+ Environments
105
+ ------------
106
+
107
+ Backup **3** runs in **UNIX**-based operating systems: Linux, Mac OSX, etc. It does **NOT** run on the Windows operating system, and there are currently no plans to support it.
108
+
109
+ Compatibility
110
+ -------------
111
+
112
+ Backup **3** is **NOT** backwards compatible with Backup **2**. The command line interface has changed. The DSL has changed. And a lot more has changed. All for the better.
113
+
114
+
115
+ A sample "Backup" configuration file
116
+ ====================================
117
+
118
+ Below you see a sample configuration file you could create for Backup 3. Just read through it slowly and I'm quite sure you will already know what's going to happen before I explain it to you. **(see explanation after the example)**
119
+
120
+ Backup::Model.new(:sample_backup, 'A sample backup configuration') do
121
+
122
+ database MySQL do |database|
123
+ database.name = 'my_sample_mysql_db'
124
+ database.username = 'my_username'
125
+ database.password = 'my_password'
126
+ database.skip_tables = ['logs']
127
+ database.additional_options = ['--single-transaction', '--quick']
128
+ end
129
+
130
+ database MongoDB do |database|
131
+ database.name = 'my_sample_mongo_db'
132
+ database.only_collections = ['users', 'events', 'posts']
133
+ end
134
+
135
+ archive :user_avatars do |archive|
136
+ archive.add '/var/apps/my_sample_app/public/avatars'
137
+ end
138
+
139
+ archive :logs do |archive|
140
+ archive.add '/var/apps/my_sample_app/logs/production.log'
141
+ archive.add '/var/apps/my_sample_app/logs/newrelic_agent.log'
142
+ archive.add '/var/apps/my_sample_app/logs/other.log'
143
+ end
144
+
145
+ encrypt_with OpenSSL do |encryption|
146
+ encryption.password = 'my_secret_password'
147
+ end
148
+
149
+ compress_with Gzip do |compression|
150
+ compression.best = true
151
+ end
152
+
153
+ store_with S3 do |s3|
154
+ s3.access_key_id = 'my_access_key_id'
155
+ s3.secret_access_key = 'my_secret_access_key'
156
+ s3.region = 'us-east-1'
157
+ s3.bucket = 'my_bucket/backups'
158
+ s3.keep = 20
159
+ end
160
+
161
+ store_with RSync do |server|
162
+ server.username = 'my_username'
163
+ server.password = 'my_password'
164
+ server.ip = '123.45.678.90'
165
+ server.path = '~/backups/'
166
+ end
167
+
168
+ notify_by Mail do |mail|
169
+ mail.on_success = false
170
+ mail.on_failure = true
171
+ end
172
+ end
173
+
174
+ ### Explanation for the above example
175
+
176
+ First it dumps all the tables inside the MySQL database "my_sample_mysql_db", except for the "logs" table. It also dumps the MongoDB database "my_sample_mongo_db", but only the collections "users", "events" and "posts". After that it'll create a "user_avatars.tar" archive with all the uploaded avatars of the users. After that it'll create a "logs.tar" archive with the "production.log", "newrelic_agent.log" and "other.log" logs. After that it'll compress the backup file using Gzip (with the mode set to "best", rather than "fast" for best compression). After that it'll encrypt the whole backup file (everything included: databases, archives) using "OpenSSL". Now the Backup can only be extracted when you know the password to decrypt it ("my_secret_password" in this case). Then it'll store the backup file to Amazon S3 in to 'my_bucket/backups'. Next it'll also transfer a copy of the backup file to a remote server using the RSync protocol, and it'll be stored in to the "$HOME/backups/" path on this server. Finally, it'll notify me by email if the backup raises an error/exception during the process indicating that something went wrong. (When setting `mail.on_success = true` it'll also notify you of every successful backup)
177
+
178
+ ### Things to note
179
+
180
+ The __keep__ option I passed in to the S3 storage location enables "Backup Cycling". In this case, after the 21st backup file gets pushed, it'll exceed the 20 backup limit, and remove the oldest backup from the S3 bucket.
181
+
182
+ The __RSync__ protocol doesn't utilize the __keep__ option. RSync is used to do incremental backups, and only stores a single file on your remote server, which gets incrementally updated with each run. For example, if everything you dump ends up to be about 2000MB, the first time, you'll be transferring the full 2000MB. If by the time the next backup run starts this dump has increased to 2100MB, it'll calculate the difference between the source and destination file and only transfer the remaining 100MB, rather than the full 2100MB. (Note: To reduce bandwidth as much as possible with RSync, ensure you don't use compression or encryption, otherwise RSync isn't able to calculate the difference very well and bandwidth usage greatly increases.)
183
+
184
+ The __Mail__ notifier. I have not provided the SMTP options to use my Gmail account to notify myself when exceptions are raised during the process. So this won't work, check out the wiki on how to configure this. I left it out in this example.
185
+
186
+ ### And that's it!
187
+
188
+ So as you can see the DSL is straightforward and should be simple to understand and extend to your needs. You can have as many databases, archives, storage locations, compressors, encryptors and notifiers inside the above example as you need and it'll bundle all of it up in a nice packaged archive and transfer it to every specified location (as redundant as you like).
189
+
190
+ ### Running the example
191
+
192
+ Remember the `Backup::Model.new(:sample_backup, 'A sample backup configuration') do`?
193
+ The `:sample_backup` is called the "id", or "trigger". This is used to identify the backup procedure/file and initialize it.
194
+
195
+ backup perform -t sample_backup
196
+
197
+ That's it.
198
+
199
+ ### Automatic backups
200
+
201
+ Since it's a simple command line utility, just write a cron to invoke it whenever you want. I recommend you use the [Whenever Gem](https://github.com/javan/whenever) to manage your cron tasks. It'll enable you to write such elegant automatic backup syntax in Ruby:
202
+
203
+ every 6.hours do
204
+ command "backup perform -t sample_backup"
205
+ end
206
+
207
+
208
+ Documentation
209
+ -------------
210
+
211
+ See the [Wiki Pages](https://github.com/meskyanichi/backup/wiki). The subjects labeled **without** the "Backup 2)"-prefix are meant for Backup 3 users.
212
+
213
+
214
+ Suggestions, Bugs, Requests, Questions
215
+ --------------------------------------
216
+
217
+ View the [issue log](https://github.com/meskyanichi/backup/issues) and post them there.
218
+
219
+
220
+ Want to contribute?
221
+ -------------------
222
+
223
+ - Fork/Clone the **develop** branch
224
+ - Write RSpec tests, and test against:
225
+ - Ruby 1.9.2
226
+ - Ruby 1.8.7
227
+ - Ruby Enterprise Edition 1.8.7
228
+ - Try to keep the overall *structure / design* of the gem the same
229
+
230
+ I can't guarantee I'll pull every pull request. Also, I may accept your pull request and drastically change parts to improve readability/maintainability. Feel free to discuss about improvements, new functionality/features in the [issue log](https://github.com/meskyanichi/backup/issues) before contributing if you need/want more information.
231
+
232
+
233
+ Backup 2 - Issues, Wiki, Source, Gems
234
+ =====================================
235
+
236
+ I won't actively support Backup 2 anymore. The source will remain on [a separate branch](https://github.com/meskyanichi/backup/tree/backup-2). [The Issues](https://github.com/meskyanichi/backup/issues) that belong to Backup 2 have been tagged with a black label "Backup 2". The Backup 2 specific [Wiki pages](https://github.com/meskyanichi/backup/wiki) have been prefixed with "Backup 2) <Article>". [The Backup 2 Gems](http://rubygems.org/gems/backup) will always remain so you can still use Backup 2. I might still accept pull requests, but would highly encourage anyone to [move to __Backup 3__ once it's here](https://github.com/meskyanichi/backup).
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/lib/backup')
4
+
5
+ Gem::Specification.new do |gem|
6
+
7
+ ##
8
+ # General configuration / information
9
+ gem.name = 'backup'
10
+ gem.version = Backup::Version.gemspec
11
+ gem.platform = Gem::Platform::RUBY
12
+ gem.authors = 'Michael van Rooijen'
13
+ gem.email = 'meskyanichi@gmail.com'
14
+ gem.homepage = 'http://rubygems.org/gems/backup'
15
+ gem.summary = 'Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL.'
16
+ gem.description = 'Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL.
17
+ It supports various databases (MySQL, PostgreSQL, MongoDB and Redis), it supports various storage locations
18
+ (Amazon S3, Rackspace Cloud Files, Dropbox, any remote server through FTP, SFTP, SCP and RSync), it can archive files and folders,
19
+ it can cycle backups, it can do incremental backups, it can compress backups, it can encrypt backups (OpenSSL or GPG),
20
+ it can notify you about successful and/or failed backups. It is very extensible and easy to add new functionality to. It\'s easy to use.'
21
+
22
+ ##
23
+ # Files and folder that need to be compiled in to the Ruby Gem
24
+ gem.files = %x[git ls-files].split("\n")
25
+ gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
26
+ gem.require_path = 'lib'
27
+
28
+ ##
29
+ # The Backup CLI executable
30
+ gem.executables = ['backup']
31
+
32
+ ##
33
+ # Production gem dependencies
34
+ gem.add_dependency 'thor', ['~> 0.14.6'] # CLI
35
+ gem.add_dependency 'fog', ['~> 0.5.3' ] # Amazon S3, Rackspace Cloud Files
36
+ gem.add_dependency 'dropbox', ['~> 1.2.3' ] # Dropbox
37
+ gem.add_dependency 'mail', ['~> 2.2.15'] # Mail
38
+ gem.add_dependency 'net-sftp', ['~> 2.0.5' ] # SFTP Protocol
39
+ gem.add_dependency 'net-scp', ['~> 1.0.4' ] # SCP Protocol
40
+
41
+ end
data/bin/backup CHANGED
@@ -1,14 +1,193 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- puts
4
- puts
5
- puts "Backup"
6
- puts "-------------------------------------------------"
7
- puts "I've stopped releasing builds for the Backup gem."
8
- puts "To get the latest Backup versions, please issue the following command from now on:"
9
- puts
10
- puts "\s\sgem install backup"
11
- puts
12
- puts "Thanks!"
13
- puts "https://github.com/meskyanichi/backup"
14
- exit
3
+ ##
4
+ # Load RubyGems for Ruby <= 1.8.7
5
+ require 'rubygems'
6
+ require 'tempfile'
7
+ require 'fileutils'
8
+
9
+ ##
10
+ # Load Thor for the Command Line Interface
11
+ begin
12
+ require 'thor'
13
+ rescue LoadError
14
+ puts 'Backup uses Thor as CLI (Command Line Interface).'
15
+ puts 'Please install Thor first: `gem install thor`'
16
+ end
17
+
18
+ ##
19
+ # Load the Backup source
20
+ require File.expand_path("../../lib/backup", __FILE__)
21
+
22
+ ##
23
+ # Build the Backup Command Line Interface using Thor
24
+ class BackupCLI < Thor
25
+ include Thor::Actions
26
+
27
+ TEMPLATE_DIR = File.expand_path("../../lib/templates", __FILE__)
28
+
29
+ ##
30
+ # [Perform]
31
+ # Performs the backup process. The only required option is the --trigger [-t].
32
+ # If the other options (--config_file, --data_path, --tmp_path) aren't specified
33
+ # it'll fallback to the (good) defaults
34
+ method_option :trigger, :type => :string, :aliases => '-t', :required => true
35
+ method_option :config_file, :type => :string, :aliases => '-c'
36
+ method_option :data_path, :type => :string, :aliases => '-d'
37
+ method_option :log_path, :type => :string, :aliases => '-l'
38
+ method_option :tmp_path, :type => :string
39
+ desc 'perform', 'Performs the backup for the specified trigger'
40
+ def perform
41
+
42
+ ##
43
+ # Defines the TRIGGER and TIME constants
44
+ Backup.send(:const_set, :TRIGGER, options[:trigger])
45
+ Backup.send(:const_set, :TIME, Time.now.strftime("%Y.%m.%d.%H.%M.%S"))
46
+
47
+ ##
48
+ # Overwrites the CONFIG_FILE location, if --config-file was specified
49
+ if options[:config_file]
50
+ Backup.send(:remove_const, :CONFIG_FILE)
51
+ Backup.send(:const_set, :CONFIG_FILE, options[:config_file])
52
+ end
53
+
54
+ ##
55
+ # Overwrites the DATA_PATH location, if --data-path was specified
56
+ if options[:data_path]
57
+ Backup.send(:remove_const, :DATA_PATH)
58
+ Backup.send(:const_set, :DATA_PATH, options[:data_path])
59
+ end
60
+
61
+ ##
62
+ # Overwrites the LOG_PATH location, if --log-path was specified
63
+ if options[:log_path]
64
+ Backup.send(:remove_const, :LOG_PATH)
65
+ Backup.send(:const_set, :LOG_PATH, options[:log_path])
66
+ end
67
+
68
+ ##
69
+ # Overwrites the TMP_PATH location, if --tmp-path was specified
70
+ if options[:tmp_path]
71
+ Backup.send(:remove_const, :TMP_PATH)
72
+ Backup.send(:const_set, :TMP_PATH, options[:tmp_path])
73
+ end
74
+
75
+ ##
76
+ # Ensure the TMP_PATH, LOG_PATH, DATA_PATH and DATA_PATH/TRIGGER
77
+ # are created if they do not yet exist
78
+ Array.new([
79
+ Backup::TMP_PATH,
80
+ Backup::LOG_PATH,
81
+ File.join(Backup::DATA_PATH, Backup::TRIGGER)
82
+ ]).each do |path|
83
+ FileUtils.mkdir_p(path)
84
+ end
85
+
86
+ ##
87
+ # Parses the backup configuration file and returns the model instance by trigger
88
+ model = Backup::Finder.new(Backup::TRIGGER, Backup::CONFIG_FILE).find
89
+
90
+ ##
91
+ # Runs the returned model
92
+ Backup::Logger.message "Performing backup for #{model.label}!"
93
+ model.perform!
94
+ end
95
+
96
+ ##
97
+ # [Generate]
98
+ # Generates a configuration file based on the arguments passed in.
99
+ # For example, running $ backup generate --databases='mongodb' will generate a pre-populated
100
+ # configuration file with a base MongoDB setup
101
+ desc 'generate', 'Generates configuration blocks based on the arguments you pass in'
102
+ method_option :path, :type => :string
103
+ method_option :databases, :type => :string
104
+ method_option :storages, :type => :string
105
+ method_option :syncers, :type => :string
106
+ method_option :encryptors, :type => :string
107
+ method_option :compressors, :type => :string
108
+ method_option :notifiers, :type => :string
109
+ method_option :archives, :type => :boolean
110
+ def generate
111
+ temp_file = Tempfile.new('backup.rb')
112
+ temp_file << File.read( File.join(TEMPLATE_DIR, 'readme') )
113
+ temp_file << "Backup::Model.new(:my_backup, 'My Backup') do\n\n"
114
+
115
+ if options[:archives]
116
+ temp_file << File.read( File.join(TEMPLATE_DIR, 'archive') ) + "\n\n"
117
+ end
118
+
119
+ [:databases, :storages, :syncers, :encryptors, :compressors, :notifiers].each do |item|
120
+ if options[item]
121
+ options[item].split(',').map(&:strip).uniq.each do |entry|
122
+ if File.exist?( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) )
123
+ temp_file << File.read( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) ) + "\n\n"
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ temp_file << "end\n\n"
130
+ temp_file.close
131
+ if options[:path]
132
+ FileUtils.mkdir_p(options[:path])
133
+ overwrite?(File.join(Backup::PATH, 'config.rb'))
134
+ File.open(File.join(options[:path], 'config.rb'), 'w') do |file|
135
+ file.write( File.read(temp_file.path) )
136
+ puts "Generated configuration file in '#{File.join(options[:path], 'config.rb')}'"
137
+ end
138
+ else
139
+ FileUtils.mkdir_p(Backup::PATH)
140
+ overwrite?(File.join(Backup::PATH, 'config.rb'))
141
+ File.open(File.join(Backup::PATH, 'config.rb'), 'w') do |file|
142
+ file.write( File.read(temp_file.path) )
143
+ puts "Generated configuration file in '#{File.join(Backup::PATH, 'config.rb')}'"
144
+ end
145
+ end
146
+ temp_file.unlink
147
+ end
148
+
149
+ ##
150
+ # [Decrypt]
151
+ # Shorthand for decrypting encrypted files
152
+ desc 'decrypt', 'Decrypts encrypted files'
153
+ method_option :encryptor, :type => :string, :required => true
154
+ method_option :in, :type => :string, :required => true
155
+ method_option :out, :type => :string, :required => true
156
+ method_option :base64, :type => :boolean, :default => false
157
+ def decrypt
158
+ case options[:encryptor].downcase
159
+ when 'openssl'
160
+ base64 = options[:base64] ? '-base64' : ''
161
+ %x[openssl aes-256-cbc -d #{base64} -in '#{options[:in]}' -out '#{options[:out]}']
162
+ when 'gpg'
163
+ %x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
164
+ else
165
+ puts "Unknown encryptor: #{options[:encryptor]}"
166
+ puts "Use either 'openssl' or 'gpg'"
167
+ end
168
+ end
169
+
170
+ ##
171
+ # [Version]
172
+ # Returns the current version of the Backup gem
173
+ map '-v' => :version
174
+ desc 'version', 'Display installed Backup version'
175
+ def version
176
+ puts "Backup #{Backup::Version.current}"
177
+ end
178
+
179
+ private
180
+
181
+ ##
182
+ # Helper method for asking the user if he/she wants to overwrite the file
183
+ def overwrite?(path)
184
+ if File.exist?(path)
185
+ exit if no? "A configuration file already exists in #{ path }. Do you want to overwrite? [y/n]"
186
+ end
187
+ end
188
+
189
+ end
190
+
191
+ ##
192
+ # Enable the CLI for the Backup binary
193
+ BackupCLI.start