Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The last build release.

  • Loading branch information...
commit a223a6968cafa14629c43347ce5cfab56ac44103 1 parent 5ad9188
@meskyanichi meskyanichi authored
Showing with 16 additions and 6,590 deletions.
  1. +0 −17 Gemfile
  2. +0 −88 Gemfile.lock
  3. +0 −24 LICENSE.md
  4. +3 −229 README.md
  5. +1 −19 backup.gemspec
  6. +12 −190 bin/backup
  7. +0 −148 lib/backup.rb
  8. +0 −54 lib/backup/archive.rb
  9. +0 −50 lib/backup/cli.rb
  10. +0 −17 lib/backup/compressor/base.rb
  11. +0 −61 lib/backup/compressor/gzip.rb
  12. +0 −15 lib/backup/configuration/base.rb
  13. +0 −10 lib/backup/configuration/compressor/base.rb
  14. +0 −23 lib/backup/configuration/compressor/gzip.rb
  15. +0 −18 lib/backup/configuration/database/base.rb
  16. +0 −37 lib/backup/configuration/database/mongodb.rb
  17. +0 −37 lib/backup/configuration/database/mysql.rb
  18. +0 −37 lib/backup/configuration/database/postgresql.rb
  19. +0 −35 lib/backup/configuration/database/redis.rb
  20. +0 −10 lib/backup/configuration/encryptor/base.rb
  21. +0 −17 lib/backup/configuration/encryptor/gpg.rb
  22. +0 −26 lib/backup/configuration/encryptor/open_ssl.rb
  23. +0 −54 lib/backup/configuration/helpers.rb
  24. +0 −39 lib/backup/configuration/notifier/base.rb
  25. +0 −52 lib/backup/configuration/notifier/mail.rb
  26. +0 −18 lib/backup/configuration/storage/base.rb
  27. +0 −21 lib/backup/configuration/storage/cloudfiles.rb
  28. +0 −25 lib/backup/configuration/storage/dropbox.rb
  29. +0 −25 lib/backup/configuration/storage/ftp.rb
  30. +0 −25 lib/backup/configuration/storage/rsync.rb
  31. +0 −25 lib/backup/configuration/storage/s3.rb
  32. +0 −25 lib/backup/configuration/storage/scp.rb
  33. +0 −25 lib/backup/configuration/storage/sftp.rb
  34. +0 −33 lib/backup/database/base.rb
  35. +0 −137 lib/backup/database/mongodb.rb
  36. +0 −104 lib/backup/database/mysql.rb
  37. +0 −111 lib/backup/database/postgresql.rb
  38. +0 −105 lib/backup/database/redis.rb
  39. +0 −17 lib/backup/encryptor/base.rb
  40. +0 −78 lib/backup/encryptor/gpg.rb
  41. +0 −67 lib/backup/encryptor/open_ssl.rb
  42. +0 −39 lib/backup/finder.rb
  43. +0 −80 lib/backup/logger.rb
  44. +0 −249 lib/backup/model.rb
  45. +0 −29 lib/backup/notifier/base.rb
  46. +0 −32 lib/backup/notifier/binder.rb
  47. +0 −141 lib/backup/notifier/mail.rb
  48. +0 −31 lib/backup/notifier/templates/notify_failure.erb
  49. +0 −16 lib/backup/notifier/templates/notify_success.erb
  50. +0 −67 lib/backup/storage/base.rb
  51. +0 −95 lib/backup/storage/cloudfiles.rb
  52. +0 −82 lib/backup/storage/dropbox.rb
  53. +0 −114 lib/backup/storage/ftp.rb
  54. +0 −45 lib/backup/storage/object.rb
  55. +0 −100 lib/backup/storage/rsync.rb
  56. +0 −108 lib/backup/storage/s3.rb
  57. +0 −105 lib/backup/storage/scp.rb
  58. +0 −106 lib/backup/storage/sftp.rb
  59. +0 −72 lib/backup/version.rb
  60. +0 −4 lib/templates/archive
  61. +0 −4 lib/templates/compressor/gzip
  62. +0 −10 lib/templates/database/mongodb
  63. +0 −11 lib/templates/database/mysql
  64. +0 −11 lib/templates/database/postgresql
  65. +0 −10 lib/templates/database/redis
  66. +0 −9 lib/templates/encryptor/gpg
  67. +0 −5 lib/templates/encryptor/openssl
  68. +0 −14 lib/templates/notifier/mail
  69. +0 −15 lib/templates/readme
  70. +0 −7 lib/templates/storage/cloudfiles
  71. +0 −8 lib/templates/storage/dropbox
  72. +0 −8 lib/templates/storage/ftp
  73. +0 −7 lib/templates/storage/rsync
  74. +0 −8 lib/templates/storage/s3
  75. +0 −8 lib/templates/storage/scp
  76. +0 −8 lib/templates/storage/sftp
  77. +0 −53 spec/archive_spec.rb
  78. +0 −11 spec/backup_spec.rb
  79. +0 −59 spec/compressor/gzip_spec.rb
  80. +0 −35 spec/configuration/base_spec.rb
  81. +0 −28 spec/configuration/compressor/gzip_spec.rb
  82. +0 −16 spec/configuration/database/base_spec.rb
  83. +0 −30 spec/configuration/database/mongodb_spec.rb
  84. +0 −32 spec/configuration/database/mysql_spec.rb
  85. +0 −32 spec/configuration/database/postgresql_spec.rb
  86. +0 −30 spec/configuration/database/redis_spec.rb
  87. +0 −25 spec/configuration/encryptor/gpg_spec.rb
  88. +0 −31 spec/configuration/encryptor/open_ssl_spec.rb
  89. +0 −32 spec/configuration/notifier/mail_spec.rb
  90. +0 −34 spec/configuration/storage/cloudfiles_spec.rb
  91. +0 −40 spec/configuration/storage/dropbox_spec.rb
  92. +0 −40 spec/configuration/storage/ftp_spec.rb
  93. +0 −37 spec/configuration/storage/rsync_spec.rb
  94. +0 −37 spec/configuration/storage/s3_spec.rb
  95. +0 −40 spec/configuration/storage/scp_spec.rb
  96. +0 −40 spec/configuration/storage/sftp_spec.rb
  97. +0 −30 spec/database/base_spec.rb
  98. +0 −144 spec/database/mongodb_spec.rb
  99. +0 −150 spec/database/mysql_spec.rb
  100. +0 −164 spec/database/postgresql_spec.rb
  101. +0 −122 spec/database/redis_spec.rb
  102. +0 −57 spec/encryptor/gpg_spec.rb
  103. +0 −102 spec/encryptor/open_ssl_spec.rb
  104. +0 −37 spec/logger_spec.rb
  105. +0 −236 spec/model_spec.rb
  106. +0 −97 spec/notifier/mail_spec.rb
  107. +0 −21 spec/spec_helper.rb
  108. +0 −33 spec/storage/base_spec.rb
  109. +0 −102 spec/storage/cloudfiles_spec.rb
  110. +0 −89 spec/storage/dropbox_spec.rb
  111. +0 −133 spec/storage/ftp_spec.rb
  112. +0 −74 spec/storage/object_spec.rb
  113. +0 −115 spec/storage/rsync_spec.rb
  114. +0 −110 spec/storage/s3_spec.rb
  115. +0 −129 spec/storage/scp_spec.rb
  116. +0 −125 spec/storage/sftp_spec.rb
  117. +0 −32 spec/version_spec.rb
View
17 Gemfile
@@ -1,17 +0,0 @@
-##
-# RubyGems Source
-source 'http://rubygems.org'
-
-##
-# Bundle gems definde inside the gemspec file
-gemspec
-
-##
-# Define gems to be used in the 'test' environment
-group :test do
- gem 'rspec'
- gem 'mocha'
- gem 'infinity_test'
- gem 'fuubar'
- gem 'timecop'
-end
View
88 Gemfile.lock
@@ -1,88 +0,0 @@
-PATH
- remote: .
- specs:
- backup (3.0.2.build.0)
- dropbox (~> 1.2.3)
- fog (~> 0.5.3)
- mail (~> 2.2.15)
- net-scp (~> 1.0.4)
- net-sftp (~> 2.0.5)
- thor (~> 0.14.6)
-
-GEM
- remote: http://rubygems.org/
- specs:
- activesupport (3.0.5)
- builder (3.0.0)
- diff-lcs (1.1.2)
- dropbox (1.2.3)
- json (>= 1.2.0)
- mechanize (>= 1.0.0)
- multipart-post (>= 1.0)
- oauth (>= 0.3.6)
- excon (0.5.6)
- fog (0.5.3)
- builder
- excon (>= 0.5.2)
- formatador (>= 0.0.16)
- json
- mime-types
- net-ssh (>= 2.0.23)
- nokogiri (>= 1.4.4)
- ruby-hmac
- formatador (0.0.16)
- fuubar (0.0.3)
- rspec (~> 2.0)
- rspec-instafail (~> 0.1.4)
- ruby-progressbar (~> 0.0.9)
- i18n (0.5.0)
- infinity_test (1.0.2)
- notifiers (>= 1.1.0)
- watchr (>= 0.7)
- json (1.5.1)
- mail (2.2.15)
- activesupport (>= 2.3.6)
- i18n (>= 0.4.0)
- mime-types (~> 1.16)
- treetop (~> 1.4.8)
- mechanize (1.0.0)
- nokogiri (>= 1.2.1)
- mime-types (1.16)
- mocha (0.9.12)
- multipart-post (1.1.0)
- net-scp (1.0.4)
- net-ssh (>= 1.99.1)
- net-sftp (2.0.5)
- net-ssh (>= 2.0.9)
- net-ssh (2.1.3)
- nokogiri (1.4.4)
- notifiers (1.1.0)
- oauth (0.4.4)
- polyglot (0.3.1)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
- diff-lcs (~> 1.1.2)
- rspec-instafail (0.1.6)
- rspec-mocks (2.5.0)
- ruby-hmac (0.4.0)
- ruby-progressbar (0.0.9)
- thor (0.14.6)
- timecop (0.3.5)
- treetop (1.4.9)
- polyglot (>= 0.3.1)
- watchr (0.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- backup!
- fuubar
- infinity_test
- mocha
- rspec
- timecop
View
24 LICENSE.md
@@ -1,24 +0,0 @@
-
-Copyright (c) 2009-2011 Michael van Rooijen ( [@meskyanichi](http://twitter.com/#!/meskyanichi) )
-=================================================================================================
-
-The "Backup" RubyGem is released under the **MIT LICENSE**
-----------------------------------------------------------
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
View
232 README.md
@@ -1,236 +1,10 @@
Backup 3
========
-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.
-
-Author
-------
-
-Michael van Rooijen ( [@meskyanichi](http://twitter.com/#!/meskyanichi) )
-
-Drop me a message for any questions, suggestions, requests, bugs or submit them to the [issue log](https://github.com/meskyanichi/backup/issues).
-
-Installation
-------------
-
-To get the latest stable version
+I've stopped releasing builds of the Backup gem since it seemed unnecessary after all, and frequently pushing out 0.0.x versions is fine with me ( and anyone else I assume ). Please issue the following command from now on to get the latest backup versions:
gem install backup
-To get the latest *build* of the latest stable version
-
- gem install backup --pre
-
-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.
-
-You can view the list of released versions over at [RubyGems.org (Backup)](https://rubygems.org/gems/backup/versions)
-
-
-What Backup 3 currently supports
-================================
-
-**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.**
-
-Database Support
-----------------
-
-- MySQL
-- PostgreSQL
-- MongoDB
-- Redis
-
-[Database Wiki Page](https://github.com/meskyanichi/backup/wiki/Databases)
-
-Filesystem Support
-------------------
-
-- Files
-- Folders
-
-[Archive Wiki Page](https://github.com/meskyanichi/backup/wiki/Archives)
-
-Storage Locations
------------------
-
-- Amazon Simple Storage Service (S3)
-- Rackspace Cloud Files (Mosso)
-- Dropbox
-- Remote Servers *(Available Protocols: FTP, SFTP, SCP and RSync)*
-
-[Storage Wiki Page](https://github.com/meskyanichi/backup/wiki/Storages)
-
-Storage Features
-----------------
-
-- Backup Cycling, applies to:
- - Amazon Simple Storage Service (S3)
- - Rackspace Cloud Files (Mosso)
- - Dropbox
- - Remote Servers *(Only Protocols: FTP, SFTP, SCP)*
-- Incremental Backups, applies to:
- - Remote Servers *(Only Protocols: RSync)*
-
-[Storage Wiki Page](https://github.com/meskyanichi/backup/wiki/Storages)
-
-Compressors
------------
-
-- Gzip
-
-[Compressors Wiki Page](https://github.com/meskyanichi/backup/wiki/Compressors)
-
-Encryptors
-----------
-
-- OpenSSL
-- GPG
-
-[Encryptors Wiki Page](https://github.com/meskyanichi/backup/wiki/Encryptors)
-
-Notifiers
----------
-
-- Mail
-
-[Notifiers Wiki Page](https://github.com/meskyanichi/backup/wiki/Notifiers)
-
-Supported Ruby versions (Tested with RSpec)
--------------------------------------------
-
-- Ruby 1.9.2
-- Ruby 1.8.7
-- Ruby Enterprise Edition 1.8.7
-
-Environments
-------------
-
-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.
-
-Compatibility
--------------
-
-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.
-
-
-A sample "Backup" configuration file
-====================================
-
-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)**
-
- Backup::Model.new(:sample_backup, 'A sample backup configuration') do
-
- database MySQL do |database|
- database.name = 'my_sample_mysql_db'
- database.username = 'my_username'
- database.password = 'my_password'
- database.skip_tables = ['logs']
- database.additional_options = ['--single-transaction', '--quick']
- end
-
- database MongoDB do |database|
- database.name = 'my_sample_mongo_db'
- database.only_collections = ['users', 'events', 'posts']
- end
-
- archive :user_avatars do |archive|
- archive.add '/var/apps/my_sample_app/public/avatars'
- end
-
- archive :logs do |archive|
- archive.add '/var/apps/my_sample_app/logs/production.log'
- archive.add '/var/apps/my_sample_app/logs/newrelic_agent.log'
- archive.add '/var/apps/my_sample_app/logs/other.log'
- end
-
- encrypt_with OpenSSL do |encryption|
- encryption.password = 'my_secret_password'
- end
-
- compress_with Gzip do |compression|
- compression.best = true
- end
-
- store_with S3 do |s3|
- s3.access_key_id = 'my_access_key_id'
- s3.secret_access_key = 'my_secret_access_key'
- s3.region = 'us-east-1'
- s3.bucket = 'my_bucket/backups'
- s3.keep = 20
- end
-
- store_with RSync do |server|
- server.username = 'my_username'
- server.password = 'my_password'
- server.ip = '123.45.678.90'
- server.path = '~/backups/'
- end
-
- notify_by Mail do |mail|
- mail.on_success = false
- mail.on_failure = true
- end
- end
-
-### Explanation for the above example
-
-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)
-
-### Things to note
-
-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.
-
-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.)
-
-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.
-
-### And that's it!
-
-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).
-
-### Running the example
-
-Remember the `Backup::Model.new(:sample_backup, 'A sample backup configuration') do`?
-The `:sample_backup` is called the "id", or "trigger". This is used to identify the backup procedure/file and initialize it.
-
- backup perform -t sample_backup
-
-That's it.
-
-### Automatic backups
-
-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:
-
- every 6.hours do
- command "backup perform -t sample_backup"
- end
-
-
-Documentation
--------------
-
-See the [Wiki Pages](https://github.com/meskyanichi/backup/wiki). The subjects labeled **without** the "Backup 2)"-prefix are meant for Backup 3 users.
-
-
-Suggestions, Bugs, Requests, Questions
---------------------------------------
-
-View the [issue log](https://github.com/meskyanichi/backup/issues) and post them there.
-
-
-Want to contribute?
--------------------
-
-- Fork/Clone the **develop** branch
-- Write RSpec tests, and test against:
- - Ruby 1.9.2
- - Ruby 1.8.7
- - Ruby Enterprise Edition 1.8.7
-- Try to keep the overall *structure / design* of the gem the same
-
-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.
-
-
-Backup 2 - Issues, Wiki, Source, Gems
-=====================================
+Thanks!
-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).
+[Return to the develop branch](https://github.com/meskyanichi/backup)
View
20 backup.gemspec
@@ -1,13 +1,11 @@
# encoding: utf-8
-require File.expand_path(File.dirname(__FILE__) + '/lib/backup')
-
Gem::Specification.new do |gem|
##
# General configuration / information
gem.name = 'backup'
- gem.version = Backup::Version.gemspec
+ gem.version = '3.0.3.build.0'
gem.platform = Gem::Platform::RUBY
gem.authors = 'Michael van Rooijen'
gem.email = 'meskyanichi@gmail.com'
@@ -19,23 +17,7 @@ Gem::Specification.new do |gem|
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.'
- ##
- # Files and folder that need to be compiled in to the Ruby Gem
- gem.files = %x[git ls-files].split("\n")
- gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
- gem.require_path = 'lib'
-
- ##
# The Backup CLI executable
gem.executables = ['backup']
- ##
- # Production gem dependencies
- gem.add_dependency 'thor', ['~> 0.14.6'] # CLI
- gem.add_dependency 'fog', ['~> 0.5.3' ] # Amazon S3, Rackspace Cloud Files
- gem.add_dependency 'dropbox', ['~> 1.2.3' ] # Dropbox
- gem.add_dependency 'mail', ['~> 2.2.15'] # Mail
- gem.add_dependency 'net-sftp', ['~> 2.0.5' ] # SFTP Protocol
- gem.add_dependency 'net-scp', ['~> 1.0.4' ] # SCP Protocol
-
end
View
202 bin/backup
@@ -1,192 +1,14 @@
#! /usr/bin/env ruby
-##
-# Load RubyGems for Ruby <= 1.8.7
-require 'rubygems'
-require 'tempfile'
-require 'fileutils'
-
-##
-# Load Thor for the Command Line Interface
-begin
- require 'thor'
-rescue LoadError
- puts 'Backup uses Thor as CLI (Command Line Interface).'
- puts 'Please install Thor first: `gem install thor`'
-end
-
-##
-# Load the Backup source
-require File.expand_path("../../lib/backup", __FILE__)
-
-##
-# Build the Backup Command Line Interface using Thor
-class BackupCLI < Thor
- include Thor::Actions
-
- TEMPLATE_DIR = File.expand_path("../../lib/templates", __FILE__)
-
- ##
- # [Perform]
- # Performs the backup process. The only required option is the --trigger [-t].
- # If the other options (--config_file, --data_path, --tmp_path) aren't specified
- # it'll fallback to the (good) defaults
- method_option :trigger, :type => :string, :aliases => '-t', :required => true
- method_option :config_file, :type => :string, :aliases => '-c'
- method_option :data_path, :type => :string, :aliases => '-d'
- method_option :log_path, :type => :string, :aliases => '-l'
- method_option :tmp_path, :type => :string
- desc 'perform', 'Performs the backup for the specified trigger'
- def perform
-
- ##
- # Defines the TRIGGER and TIME constants
- Backup.send(:const_set, :TRIGGER, options[:trigger])
- Backup.send(:const_set, :TIME, Time.now.strftime("%Y.%m.%d.%H.%M.%S"))
-
- ##
- # Overwrites the CONFIG_FILE location, if --config-file was specified
- if options[:config_file]
- Backup.send(:remove_const, :CONFIG_FILE)
- Backup.send(:const_set, :CONFIG_FILE, options[:config_file])
- end
-
- ##
- # Overwrites the DATA_PATH location, if --data-path was specified
- if options[:data_path]
- Backup.send(:remove_const, :DATA_PATH)
- Backup.send(:const_set, :DATA_PATH, options[:data_path])
- end
-
- ##
- # Overwrites the LOG_PATH location, if --log-path was specified
- if options[:log_path]
- Backup.send(:remove_const, :LOG_PATH)
- Backup.send(:const_set, :LOG_PATH, options[:log_path])
- end
-
- ##
- # Overwrites the TMP_PATH location, if --tmp-path was specified
- if options[:tmp_path]
- Backup.send(:remove_const, :TMP_PATH)
- Backup.send(:const_set, :TMP_PATH, options[:tmp_path])
- end
-
- ##
- # Ensure the TMP_PATH, LOG_PATH, DATA_PATH and DATA_PATH/TRIGGER
- # are created if they do not yet exist
- Array.new([
- Backup::TMP_PATH,
- Backup::LOG_PATH,
- File.join(Backup::DATA_PATH, Backup::TRIGGER)
- ]).each do |path|
- FileUtils.mkdir_p(path)
- end
-
- ##
- # Parses the backup configuration file and returns the model instance by trigger
- model = Backup::Finder.new(Backup::TRIGGER, Backup::CONFIG_FILE).find
-
- ##
- # Runs the returned model
- Backup::Logger.message "Performing backup for #{model.label}!"
- model.perform!
- end
-
- ##
- # [Generate]
- # Generates a configuration file based on the arguments passed in.
- # For example, running $ backup generate --databases='mongodb' will generate a pre-populated
- # configuration file with a base MongoDB setup
- desc 'generate', 'Generates configuration blocks based on the arguments you pass in'
- method_option :path, :type => :string
- method_option :databases, :type => :string
- method_option :storages, :type => :string
- method_option :encryptors, :type => :string
- method_option :compressors, :type => :string
- method_option :notifiers, :type => :string
- method_option :archives, :type => :boolean
- def generate
- temp_file = Tempfile.new('backup.rb')
- temp_file << File.read( File.join(TEMPLATE_DIR, 'readme') )
- temp_file << "Backup::Model.new(:my_backup, 'My Backup') do\n\n"
-
- if options[:archives]
- temp_file << File.read( File.join(TEMPLATE_DIR, 'archive') ) + "\n\n"
- end
-
- [:databases, :storages, :encryptors, :compressors, :notifiers].each do |item|
- if options[item]
- options[item].split(',').map(&:strip).uniq.each do |entry|
- if File.exist?( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) )
- temp_file << File.read( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) ) + "\n\n"
- end
- end
- end
- end
-
- temp_file << "end\n\n"
- temp_file.close
- if options[:path]
- FileUtils.mkdir_p(options[:path])
- overwrite?(File.join(Backup::PATH, 'config.rb'))
- File.open(File.join(options[:path], 'config.rb'), 'w') do |file|
- file.write( File.read(temp_file.path) )
- puts "Generated configuration file in '#{File.join(options[:path], 'config.rb')}'"
- end
- else
- FileUtils.mkdir_p(Backup::PATH)
- overwrite?(File.join(Backup::PATH, 'config.rb'))
- File.open(File.join(Backup::PATH, 'config.rb'), 'w') do |file|
- file.write( File.read(temp_file.path) )
- puts "Generated configuration file in '#{File.join(Backup::PATH, 'config.rb')}'"
- end
- end
- temp_file.unlink
- end
-
- ##
- # [Decrypt]
- # Shorthand for decrypting encrypted files
- desc 'decrypt', 'Decrypts encrypted files'
- method_option :encryptor, :type => :string, :required => true
- method_option :in, :type => :string, :required => true
- method_option :out, :type => :string, :required => true
- method_option :base64, :type => :boolean, :default => false
- def decrypt
- case options[:encryptor].downcase
- when 'openssl'
- base64 = options[:base64] ? '-base64' : ''
- %x[openssl aes-256-cbc -d #{base64} -in '#{options[:in]}' -out '#{options[:out]}']
- when 'gpg'
- %x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
- else
- puts "Unknown encryptor: #{options[:encryptor]}"
- puts "Use either 'openssl' or 'gpg'"
- end
- end
-
- ##
- # [Version]
- # Returns the current version of the Backup gem
- map '-v' => :version
- desc 'version', 'Display installed Backup version'
- def version
- puts "Backup #{Backup::Version.current}"
- end
-
-private
-
- ##
- # Helper method for asking the user if he/she wants to overwrite the file
- def overwrite?(path)
- if File.exist?(path)
- exit if no? "A configuration file already exists in #{ path }. Do you want to overwrite? [y/n]"
- end
- end
-
-end
-
-##
-# Enable the CLI for the Backup binary
-BackupCLI.start
+puts
+puts
+puts "Backup"
+puts "-------------------------------------------------"
+puts "I've stopped releasing builds for the Backup gem."
+puts "To get the latest Backup versions, please issue the following command from now on:"
+puts
+puts "\s\sgem install backup"
+puts
+puts "Thanks!"
+puts "https://github.com/meskyanichi/backup"
+exit
View
148 lib/backup.rb
@@ -1,148 +0,0 @@
-# encoding: utf-8
-
-require 'fileutils'
-require 'yaml'
-
-##
-# The Backup Ruby Gem
-module Backup
-
- ##
- # List the available database, storage, compressor, encryptor and notifier constants.
- # These are used to dynamically define these constants as classes inside Backup::Finder
- # to provide a nicer configuration file DSL syntax to the users. Adding existing constants
- # to the arrays below will enable the user to use a constant instead of a string.
- # Example, instead of:
- # database "MySQL" do |mysql|
- # You can do:
- # database MySQL do |mysql|
- DATABASES = ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis']
- STORAGES = ['S3', 'CloudFiles', 'Dropbox', 'FTP', 'SFTP', 'SCP', 'RSync']
- COMPRESSORS = ['Gzip']
- ENCRYPTORS = ['OpenSSL', 'GPG']
- NOTIFIERS = ['Mail']
-
- ##
- # Backup's internal paths
- LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup')
- CONFIGURATION_PATH = File.join(LIBRARY_PATH, 'configuration')
- STORAGE_PATH = File.join(LIBRARY_PATH, 'storage')
- DATABASE_PATH = File.join(LIBRARY_PATH, 'database')
- COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor')
- ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
- NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
-
- ##
- # Backup's Environment paths
- PATH = File.join(ENV['HOME'], 'Backup')
- DATA_PATH = File.join(ENV['HOME'], 'Backup', 'data')
- CONFIG_FILE = File.join(ENV['HOME'], 'Backup', 'config.rb')
- LOG_PATH = File.join(ENV['HOME'], 'Backup', 'log')
- TMP_PATH = File.join(ENV['HOME'], 'Backup', '.tmp')
-
- ##
- # Autoload Backup base files
- autoload :Model, File.join(LIBRARY_PATH, 'model')
- autoload :Archive, File.join(LIBRARY_PATH, 'archive')
- autoload :CLI, File.join(LIBRARY_PATH, 'cli')
- autoload :Finder, File.join(LIBRARY_PATH, 'finder')
- autoload :Logger, File.join(LIBRARY_PATH, 'logger')
- autoload :Version, File.join(LIBRARY_PATH, 'version')
-
- ##
- # Autoload Backup configuration files
- module Configuration
- autoload :Base, File.join(CONFIGURATION_PATH, 'base')
- autoload :Helpers, File.join(CONFIGURATION_PATH, 'helpers')
-
- module Notifier
- autoload :Base, File.join(CONFIGURATION_PATH, 'notifier', 'base')
- autoload :Mail, File.join(CONFIGURATION_PATH, 'notifier', 'mail')
- end
-
- module Encryptor
- autoload :Base, File.join(CONFIGURATION_PATH, 'encryptor', 'base')
- autoload :OpenSSL, File.join(CONFIGURATION_PATH, 'encryptor', 'open_ssl')
- autoload :GPG, File.join(CONFIGURATION_PATH, 'encryptor', 'gpg')
- end
-
- module Compressor
- autoload :Base, File.join(CONFIGURATION_PATH, 'compressor', 'base')
- autoload :Gzip, File.join(CONFIGURATION_PATH, 'compressor', 'gzip')
- end
-
- module Storage
- autoload :Base, File.join(CONFIGURATION_PATH, 'storage', 'base')
- autoload :S3, File.join(CONFIGURATION_PATH, 'storage', 's3')
- autoload :CloudFiles, File.join(CONFIGURATION_PATH, 'storage', 'cloudfiles')
- autoload :Dropbox, File.join(CONFIGURATION_PATH, 'storage', 'dropbox')
- autoload :FTP, File.join(CONFIGURATION_PATH, 'storage', 'ftp')
- autoload :SFTP, File.join(CONFIGURATION_PATH, 'storage', 'sftp')
- autoload :SCP, File.join(CONFIGURATION_PATH, 'storage', 'scp')
- autoload :RSync, File.join(CONFIGURATION_PATH, 'storage', 'rsync')
- end
-
- module Database
- autoload :Base, File.join(CONFIGURATION_PATH, 'database', 'base')
- autoload :MySQL, File.join(CONFIGURATION_PATH, 'database', 'mysql')
- autoload :PostgreSQL, File.join(CONFIGURATION_PATH, 'database', 'postgresql')
- autoload :MongoDB, File.join(CONFIGURATION_PATH, 'database', 'mongodb')
- autoload :Redis, File.join(CONFIGURATION_PATH, 'database', 'redis')
- end
- end
-
- ##
- # Autoload Backup storage files
- module Storage
- autoload :Base, File.join(STORAGE_PATH, 'base')
- autoload :Object, File.join(STORAGE_PATH, 'object')
- autoload :S3, File.join(STORAGE_PATH, 's3')
- autoload :CloudFiles, File.join(STORAGE_PATH, 'cloudfiles')
- autoload :Dropbox, File.join(STORAGE_PATH, 'dropbox')
- autoload :FTP, File.join(STORAGE_PATH, 'ftp')
- autoload :SFTP, File.join(STORAGE_PATH, 'sftp')
- autoload :SCP, File.join(STORAGE_PATH, 'scp')
- autoload :RSync, File.join(STORAGE_PATH, 'rsync')
- end
-
- ##
- # Autoload Backup database files
- module Database
- autoload :Base, File.join(DATABASE_PATH, 'base')
- autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
- autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
- autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
- autoload :Redis, File.join(DATABASE_PATH, 'redis')
- end
-
- ##
- # Autoload compressor files
- module Compressor
- autoload :Base, File.join(COMPRESSOR_PATH, 'base')
- autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
- end
-
- ##
- # Autoload encryptor files
- module Encryptor
- autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
- autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
- autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
- end
-
- ##
- # Autoload notification files
- module Notifier
- autoload :Base, File.join(NOTIFIER_PATH, 'base')
- autoload :Binder, File.join(NOTIFIER_PATH, 'binder')
- autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
- end
-
- ##
- # Dynamically defines all the available database, storage, compressor, encryptor and notifier
- # classes inside Backup::Finder to improve the DSL for the configuration file
- (DATABASES + STORAGES + COMPRESSORS + ENCRYPTORS + NOTIFIERS).each do |constant|
- Backup::Finder.const_set(constant, Class.new)
- end
-
-end
View
54 lib/backup/archive.rb
@@ -1,54 +0,0 @@
-# encoding: utf-8
-
-module Backup
- class Archive
- include Backup::CLI
-
- ##
- # Stores the name of the archive
- attr_accessor :name
-
- ##
- # Stores an array of different paths/files to store
- attr_accessor :paths
-
- ##
- # Stores the path to the archive directory
- attr_accessor :archive_path
-
- ##
- # Takes the name of the archive and the configuration block
- def initialize(name, &block)
- @name = name.to_sym
- @paths = Array.new
- @archive_path = File.join(TMP_PATH, TRIGGER, 'archive')
-
- instance_eval(&block)
- end
-
- ##
- # Adds new paths to the @paths instance variable array
- def add(path)
- @paths << path
- end
-
- ##
- # Archives all the provided paths in to a single .tar file
- # and places that .tar file in the folder which later will be packaged
- def perform!
- mkdir(archive_path)
- Logger.message("#{ self.class } started packaging and archiving #{ paths.map { |path| "\"#{path}\""}.join(", ") }.")
- run("#{ utility(:tar) } -c #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
- end
-
- private
-
- ##
- # Returns a "tar-ready" string of all the specified paths combined
- def paths_to_package
- paths.map do |path|
- "'#{path}'"
- end.join("\s")
- end
- end
-end
View
50 lib/backup/cli.rb
@@ -1,50 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module CLI
-
- ##
- # Wrapper method for %x[] to run CL commands
- # through a ruby method. This helps with test coverage and
- # improves readability
- def run(command)
- %x[#{command}]
- end
-
- ##
- # Wrapper method for FileUtils.mkdir_p to create directories
- # through a ruby method. This helps with test coverage and
- # improves readability
- def mkdir(path)
- FileUtils.mkdir_p(path)
- end
-
- ##
- # Wrapper for the FileUtils.rm_rf to remove files and folders
- # through a ruby method. This helps with test coverage and
- # improves readability
- def rm(path)
- FileUtils.rm_rf(path)
- end
-
- ##
- # Tries to find the full path of the specified utility. If the full
- # path is found, it'll return that. Otherwise it'll just return the
- # name of the utility. If the 'utility_path' is defined, it'll check
- # to see if it isn't an empty string, and if it isn't, it'll go ahead and
- # always use that path rather than auto-detecting it
- def utility(name)
- if respond_to?(:utility_path)
- if utility_path.is_a?(String) and not utility_path.empty?
- return utility_path
- end
- end
-
- if path = %x[which #{name}].chomp and not path.empty?
- return path
- end
- name
- end
-
- end
-end
View
17 lib/backup/compressor/base.rb
@@ -1,17 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Compressor
- class Base
- include Backup::CLI
- include Backup::Configuration::Helpers
-
- ##
- # Logs a message to the console and log file to inform
- # the client that Backup is compressing the archive
- def log!
- Backup::Logger.message "#{ self.class } started compressing the archive."
- end
- end
- end
-end
View
61 lib/backup/compressor/gzip.rb
@@ -1,61 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Compressor
- class Gzip < Base
-
- ##
- # Tells Backup::Compressor::Gzip to compress
- # better rather than faster when set to true
- attr_writer :best
-
- ##
- # Tells Backup::Compressor::Gzip to compress
- # faster rather than better when set to true
- attr_writer :fast
-
- ##
- # Creates a new instance of Backup::Compressor::Gzip and
- # configures it to either compress faster or better
- def initialize(&block)
- load_defaults!
-
- @best ||= false
- @fast ||= false
-
- instance_eval(&block) if block_given?
- end
-
- ##
- # Performs the compression of the packages backup file
- def perform!
- log!
- run("#{ utility(:gzip) } #{ options } '#{ Backup::Model.file }'")
- Backup::Model.extension += '.gz'
- end
-
- private
-
- ##
- # Combines the provided options and returns a gzip options string
- def options
- (best + fast).join("\s")
- end
-
- ##
- # Returns the gzip option syntax for compressing
- # better when @best is set to true
- def best
- return ['--best'] if @best; []
- end
-
- ##
- # Returns the gzip option syntax for compressing
- # faster when @fast is set to true
- def fast
- return ['--fast'] if @fast; []
- end
-
- end
- end
-end
View
15 lib/backup/configuration/base.rb
@@ -1,15 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- class Base
- extend Backup::Configuration::Helpers
-
- ##
- # Allows for global configuration through block-notation
- def self.defaults
- yield self
- end
- end
- end
-end
View
10 lib/backup/configuration/compressor/base.rb
@@ -1,10 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Compressor
- class Base < Backup::Configuration::Base
- end
- end
- end
-end
View
23 lib/backup/configuration/compressor/gzip.rb
@@ -1,23 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Compressor
- class Gzip < Base
- class << self
-
- ##
- # Tells Backup::Compressor::Gzip to compress
- # better rather than faster when set to true
- attr_accessor :best
-
- ##
- # Tells Backup::Compressor::Gzip to compress
- # faster rather than better when set to true
- attr_accessor :fast
-
- end
- end
- end
- end
-end
View
18 lib/backup/configuration/database/base.rb
@@ -1,18 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Database
- class Base < Backup::Configuration::Base
- class << self
-
- ##
- # Allows the user to specify the path to a "dump" utility
- # in case it cannot be auto-detected by Backup
- attr_accessor :utility_path
-
- end
- end
- end
- end
-end
View
37 lib/backup/configuration/database/mongodb.rb
@@ -1,37 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Database
- class MongoDB < Base
- class << self
-
- ##
- # Name of the database that needs to get dumped
- attr_accessor :name
-
- ##
- # Credentials for the specified database
- attr_accessor :username, :password
-
- ##
- # Connectivity options
- attr_accessor :host, :port
-
- ##
- # IPv6 support (disabled by default)
- attr_accessor :ipv6
-
- ##
- # Collections to dump, collections that aren't specified won't get dumped
- attr_accessor :only_collections
-
- ##
- # Additional "mongodump" options
- attr_accessor :additional_options
-
- end
- end
- end
- end
-end
View
37 lib/backup/configuration/database/mysql.rb
@@ -1,37 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Database
- class MySQL < Base
- class << self
-
- ##
- # Name of the database that needs to get dumped
- attr_accessor :name
-
- ##
- # Credentials for the specified database
- attr_accessor :username, :password
-
- ##
- # Connectivity options
- attr_accessor :host, :port, :socket
-
- ##
- # Tables to skip while dumping the database
- attr_accessor :skip_tables
-
- ##
- # Tables to dump, tables that aren't specified won't get dumped
- attr_accessor :only_tables
-
- ##
- # Additional "mysqldump" options
- attr_accessor :additional_options
-
- end
- end
- end
- end
-end
View
37 lib/backup/configuration/database/postgresql.rb
@@ -1,37 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Database
- class PostgreSQL < Base
- class << self
-
- ##
- # Name of the database that needs to get dumped
- attr_accessor :name
-
- ##
- # Credentials for the specified database
- attr_accessor :username, :password
-
- ##
- # Connectivity options
- attr_accessor :host, :port, :socket
-
- ##
- # Tables to skip while dumping the database
- attr_accessor :skip_tables
-
- ##
- # Tables to dump, tables that aren't specified won't get dumped
- attr_accessor :only_tables
-
- ##
- # Additional "pg_dump" options
- attr_accessor :additional_options
-
- end
- end
- end
- end
-end
View
35 lib/backup/configuration/database/redis.rb
@@ -1,35 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Database
- class Redis < Base
- class << self
-
- ##
- # Name of and path to the database that needs to get dumped
- attr_accessor :name, :path
-
- ##
- # Credentials for the specified database
- attr_accessor :password
-
- ##
- # Determines whether Backup should invoke the SAVE command through
- # the 'redis-cli' utility to persist the most recent data before
- # copying over the dump file
- attr_accessor :invoke_save
-
- ##
- # Connectivity options
- attr_accessor :host, :port, :socket
-
- ##
- # Additional "redis-cli" options
- attr_accessor :additional_options
-
- end
- end
- end
- end
-end
View
10 lib/backup/configuration/encryptor/base.rb
@@ -1,10 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Encryptor
- class Base < Backup::Configuration::Base
- end
- end
- end
-end
View
17 lib/backup/configuration/encryptor/gpg.rb
@@ -1,17 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Encryptor
- class GPG < Base
- class << self
-
- ##
- # The GPG Public key that'll be used to encrypt the backup
- attr_accessor :key
-
- end
- end
- end
- end
-end
View
26 lib/backup/configuration/encryptor/open_ssl.rb
@@ -1,26 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Encryptor
- class OpenSSL < Base
- class << self
-
- ##
- # The password that'll be used to encrypt the backup. This
- # password will be required to decrypt the backup later on.
- attr_accessor :password
-
- ##
- # Determines whether the 'base64' should be used or not
- attr_accessor :base64
-
- ##
- # Determines whether the 'salt' flag should be used
- attr_accessor :salt
-
- end
- end
- end
- end
-end
View
54 lib/backup/configuration/helpers.rb
@@ -1,54 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Helpers
-
- ##
- # Finds all the object's getter methods and checks the global
- # configuration for these methods, if they respond then they will
- # assign the object's attribute(s) to that particular global configuration's attribute
- def load_defaults!
- c = self.class.name.split('::')
- configuration = Backup::Configuration.const_get(c[1]).const_get(c[2])
-
- getter_methods.each do |attribute|
- if configuration.respond_to?(attribute)
- unless configuration.send(attribute).nil?
- self.send("#{attribute}=", configuration.send(attribute))
- end
- end
- end
- end
-
- ##
- # Clears all the defaults that may have been set by the user
- def clear_defaults!
- setter_methods.each do |method|
- self.send(method, nil)
- end
- end
-
- ##
- # Returns an array of the setter methods (as String)
- def setter_methods
- methods.map do |method|
- method = method.to_s
- method if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri='
- end.compact
- end
-
- ##
- # Returns an array of getter methods (as Array)
- def getter_methods
- methods.map do |method|
- method = method.to_s
- if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri='
- method.sub('=','')
- end
- end.compact
- end
-
- end
- end
-end
View
39 lib/backup/configuration/notifier/base.rb
@@ -1,39 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Notifier
- class Base < Backup::Configuration::Base
- class << self
-
- ##
- # When set to true, the user will be notified by email
- # when a backup process ends without raising any exceptions
- attr_writer :on_success
-
- ##
- # When set to true, the user will be notified by email
- # when a backup process raises an exception before finishing
- attr_writer :on_failure
-
- end
-
- ##
- # When @on_success is nil it means it hasn't been defined
- # and will then default to true
- def self.on_success
- return true if @on_success.nil?
- @on_success
- end
-
- ##
- # When @on_failure is nil it means it hasn't been defined
- # and will then default to true
- def self.on_failure
- return true if @on_failure.nil?
- @on_failure
- end
- end
- end
- end
-end
View
52 lib/backup/configuration/notifier/mail.rb
@@ -1,52 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Notifier
- class Mail < Base
- class << self
-
- ##
- # Sender and Receiver email addresses
- # Examples:
- # sender - my.email.address@gmail.com
- # receiver - your.email.address@gmail.com
- attr_accessor :from, :to
-
- ##
- # The address to use
- # Example: smtp.gmail.com
- attr_accessor :address
-
- ##
- # The port to connect to
- # Example: 587
- attr_accessor :port
-
- ##
- # Your domain (if applicable)
- # Example: mydomain.com
- attr_accessor :domain
-
- ##
- # Username and Password (sender email's credentials)
- # Examples:
- # user_name - meskyanichi
- # password - my_secret_password
- attr_accessor :user_name, :password
-
- ##
- # Authentication type
- # Example: plain
- attr_accessor :authentication
-
- ##
- # Automatically set TLS
- # Example: true
- attr_accessor :enable_starttls_auto
-
- end
- end
- end
- end
-end
View
18 lib/backup/configuration/storage/base.rb
@@ -1,18 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class Base < Backup::Configuration::Base
- class << self
-
- ##
- # Sets the limit to how many backups to keep in the remote location.
- # If the limit exceeds it will remove the oldest backup to make room for the newest
- attr_accessor :keep
-
- end
- end
- end
- end
-end
View
21 lib/backup/configuration/storage/cloudfiles.rb
@@ -1,21 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class CloudFiles < Base
- class << self
-
- ##
- # Rackspace Cloud Files Credentials
- attr_accessor :api_key, :username
-
- ##
- # Rackspace Cloud Files container name and path
- attr_accessor :container, :path
-
- end
- end
- end
- end
-end
View
25 lib/backup/configuration/storage/dropbox.rb
@@ -1,25 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class Dropbox < Base
- class << self
-
- ##
- # Dropbox user credentials
- attr_accessor :email, :password
-
- ##
- # Dropbox API credentials
- attr_accessor :api_key, :api_secret
-
- ##
- # Path to where the backups will be stored
- attr_accessor :path
-
- end
- end
- end
- end
-end
View
25 lib/backup/configuration/storage/ftp.rb
@@ -1,25 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class FTP < Base
- class << self
-
- ##
- # Server credentials
- attr_accessor :username, :password
-
- ##
- # Server IP Address and FTP port
- attr_accessor :ip, :port
-
- ##
- # Path to store backups to
- attr_accessor :path
-
- end
- end
- end
- end
-end
View
25 lib/backup/configuration/storage/rsync.rb
@@ -1,25 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class RSync < Base
- class << self
-
- ##
- # Server credentials
- attr_accessor :username, :password
-
- ##
- # Server IP Address and SSH port
- attr_accessor :ip, :port
-
- ##
- # Path to store backups to
- attr_accessor :path
-
- end
- end
- end
- end
-end
View
25 lib/backup/configuration/storage/s3.rb
@@ -1,25 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class S3 < Base
- class << self
-
- ##
- # Amazon Simple Storage Service (S3) Credentials
- attr_accessor :access_key_id, :secret_access_key
-
- ##
- # Amazon S3 bucket name and path
- attr_accessor :bucket, :path
-
- ##
- # Region of the specified S3 bucket
- attr_accessor :region
-
- end
- end
- end
- end
-end
View
25 lib/backup/configuration/storage/scp.rb
@@ -1,25 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class SCP < Base
- class << self
-
- ##
- # Server credentials
- attr_accessor :username, :password
-
- ##
- # Server IP Address and SCP port
- attr_accessor :ip, :port
-
- ##
- # Path to store backups to
- attr_accessor :path
-
- end
- end
- end
- end
-end
View
25 lib/backup/configuration/storage/sftp.rb
@@ -1,25 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Configuration
- module Storage
- class SFTP < Base
- class << self
-
- ##
- # Server credentials
- attr_accessor :username, :password
-
- ##
- # Server IP Address and SFTP port
- attr_accessor :ip, :port
-
- ##
- # Path to store backups to
- attr_accessor :path
-
- end
- end
- end
- end
-end
View
33 lib/backup/database/base.rb
@@ -1,33 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Database
- class Base
- include Backup::CLI
- include Backup::Configuration::Helpers
-
- ##
- # Contains the path to where the database should be dumped
- attr_accessor :dump_path
-
- ##
- # Allows the user to specify the path to a "dump" utility
- # in case it cannot be auto-detected by Backup
- attr_accessor :utility_path
-
- ##
- # Defines the @dump_path and ensures it exists by creating it
- def prepare!
- @dump_path = File.join(TMP_PATH, TRIGGER, self.class.name.split('::').last)
- mkdir(dump_path)
- end
-
- ##
- # Logs a message to the console and log file to inform
- # the client that Backup is dumping the database
- def log!
- Logger.message("#{ self.class } started dumping and archiving \"#{ name }\".")
- end
- end
- end
-end
View
137 lib/backup/database/mongodb.rb
@@ -1,137 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Database
- class MongoDB < Base
-
- ##
- # Name of the database that needs to get dumped
- attr_accessor :name
-
- ##
- # Credentials for the specified database
- attr_accessor :username, :password
-
- ##
- # Connectivity options
- attr_accessor :host, :port
-
- ##
- # IPv6 support (disabled by default)
- attr_accessor :ipv6
-
- ##
- # Collections to dump, collections that aren't specified won't get dumped
- attr_accessor :only_collections
-
- ##
- # Additional "mongodump" options
- attr_accessor :additional_options
-
- ##
- # Creates a new instance of the MongoDB database object
- def initialize(&block)
- load_defaults!
-
- @only_collections ||= Array.new
- @additional_options ||= Array.new
- @ipv6 ||= false
-
- instance_eval(&block)
- prepare!
- end
-
- ##
- # Builds the MongoDB credentials syntax to authenticate the user
- # to perform the database dumping process
- def credential_options
- %w[username password].map do |option|
- next if send(option).nil? or send(option).empty?
- "--#{option}='#{send(option)}'"
- end.compact.join("\s")
- end
-
- ##
- # Builds the MongoDB connectivity options syntax to connect the user
- # to perform the database dumping process
- def connectivity_options
- %w[host port].map do |option|
- next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?)
- "--#{option}='#{send(option)}'"
- end.compact.join("\s")
- end
-
- ##
- # Builds a MongoDB compatible string for the
- # additional options specified by the user
- def additional_options
- @additional_options.join("\s")
- end
-
- ##
- # Returns an array of collections to dump
- def collections_to_dump
- @only_collections
- end
-
- ##
- # Returns the MongoDB database selector syntax
- def database
- "--db='#{ name }'"
- end
-
- ##
- # Returns the mongodump syntax for enabling ipv6
- def ipv6
- @ipv6.eql?(true) ? '--ipv6' : ''
- end
-
- ##
- # Returns the MongoDB syntax for determining where to output all the database dumps,
- # e.g. ~/Backup/.tmp/MongoDB/<databases here>/<database collections>
- def dump_directory
- "--out='#{ dump_path }'"
- end
-
- ##
- # Builds the full mongodump string based on all attributes
- def mongodump
- "#{ utility(:mongodump) } #{ database } #{ credential_options } " +
- "#{ connectivity_options } #{ ipv6 } #{ additional_options } #{ dump_directory }"
- end
-
- ##
- # Performs the mongodump command and outputs the data to the
- # specified path based on the 'trigger'. If the user hasn't specified any
- # specific collections to dump, it'll dump everything. If the user has specified
- # collections to dump, it'll loop through the array of collections and invoke the
- # 'mongodump' command once per collection
- def perform!
- log!
-
- if collections_to_dump.is_a?(Array) and not collections_to_dump.empty?
- specific_collection_dump!
- else
- dump!
- end
- end
-
- ##
- # Builds and runs the mongodump command
- def dump!
- run(mongodump)
- end
-
- ##
- # For each collection in the @only_collections array, it'll
- # build the whole 'mongodump' command, append the '--collection' option,
- # and run the command built command
- def specific_collection_dump!
- collections_to_dump.each do |collection|
- run("#{mongodump} --collection='#{collection}'")
- end
- end
-
- end
- end
-end
View
104 lib/backup/database/mysql.rb
@@ -1,104 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Database
- class MySQL < Base
-
- ##
- # Name of the database that needs to get dumped
- attr_accessor :name
-
- ##
- # Credentials for the specified database
- attr_accessor :username, :password
-
- ##
- # Connectivity options
- attr_accessor :host, :port, :socket
-
- ##
- # Tables to skip while dumping the database
- attr_accessor :skip_tables
-
- ##
- # Tables to dump, tables that aren't specified won't get dumped
- attr_accessor :only_tables
-
- ##
- # Additional "mysqldump" options
- attr_accessor :additional_options
-
- ##
- # Creates a new instance of the MySQL adapter object
- def initialize(&block)
- load_defaults!
-
- @skip_tables ||= Array.new
- @only_tables ||= Array.new
- @additional_options ||= Array.new
-
- instance_eval(&block)
- prepare!
- end
-
- ##
- # Builds the MySQL syntax for specifying which tables to skip
- # during the dumping of the database
- def tables_to_skip
- skip_tables.map do |table|
- "--ignore-table='#{name}.#{table}'"
- end.join("\s")
- end
-
- ##
- # Builds the MySQL syntax for specifying which tables to dump
- # during the dumping of the database
- def tables_to_dump
- only_tables.join("\s")
- end
-
- ##
- # Builds the credentials MySQL syntax to authenticate the user
- # to perform the database dumping process
- def credential_options
- %w[username password].map do |option|
- next if send(option).nil? or send(option).empty?
- "--#{option}='#{send(option)}'".gsub('--username', '--user')
- end.compact.join("\s")
- end
-
- ##
- # Builds the MySQL connectivity options syntax to connect the user
- # to perform the database dumping process
- def connectivity_options
- %w[host port socket].map do |option|
- next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?)
- "--#{option}='#{send(option)}'"
- end.compact.join("\s")
- end
-
- ##
- # Builds a MySQL compatible string for the additional options
- # specified by the user
- def options
- additional_options.join("\s")
- end
-
- ##
- # Builds the full mysqldump string based on all attributes
- def mysqldump
- "#{ utility(:mysqldump) } #{ credential_options } #{ connectivity_options } " +
- "#{ options } #{ name } #{ tables_to_dump } #{ tables_to_skip }"
- end
-
- ##
- # Performs the mysqldump command and outputs the
- # data to the specified path based on the 'trigger'
- def perform!
- log!
- run("#{mysqldump} > '#{File.join(dump_path, name)}.sql'")
- end
-
- end
- end
-end
View
111 lib/backup/database/postgresql.rb
@@ -1,111 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Database
- class PostgreSQL < Base
-
- ##
- # Name of the database that needs to get dumped
- attr_accessor :name
-
- ##
- # Credentials for the specified database
- attr_accessor :username, :password
-
- ##
- # Connectivity options
- attr_accessor :host, :port, :socket
-
- ##
- # Tables to skip while dumping the database
- attr_accessor :skip_tables
-
- ##
- # Tables to dump, tables that aren't specified won't get dumped
- attr_accessor :only_tables
-
- ##
- # Additional "pg_dump" options
- attr_accessor :additional_options
-
- ##
- # Creates a new instance of the PostgreSQL adapter object
- # Sets the PGPASSWORD environment variable to the password
- # so it doesn't prompt and hang in the process
- def initialize(&block)
- load_defaults!
-
- @skip_tables ||= Array.new
- @only_tables ||= Array.new
- @additional_options ||= Array.new
-
- instance_eval(&block)
- prepare!
- ENV['PGPASSWORD'] = password
- end
-
- ##
- # Builds the PostgreSQL syntax for specifying which tables to skip
- # during the dumping of the database
- def tables_to_skip
- skip_tables.map do |table|
- "--exclude-table='#{table}'"
- end.join("\s")
- end
-
- ##
- # Builds the PostgreSQL syntax for specifying which tables to dump
- # during the dumping of the database
- def tables_to_dump
- only_tables.map do |table|
- "--table='#{table}'"
- end.join("\s")
- end
-
- ##
- # Builds the credentials PostgreSQL syntax to authenticate the user
- # to perform the database dumping process
- def credential_options
- return '' unless username.is_a?(String) and not username.empty?
- "--username='#{username}'"
- end
-
- ##
- # Builds the PostgreSQL connectivity options syntax to connect the user
- # to perform the database dumping process, socket gets gsub'd to host since
- # that's the option PostgreSQL takes for socket connections as well. In case
- # both the host and the socket are specified, the socket will take priority over the host
- def connectivity_options
- %w[host port socket].map do |option|
- next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?)
- "--#{option}='#{send(option)}'".gsub('--socket=', '--host=')
- end.compact.join("\s")
- end
-
- ##
- # Builds a PostgreSQL compatible string for the additional options
- # specified by the user
- def options
- additional_options.join("\s")
- end
-
- ##
- # Builds the full pgdump string based on all attributes
- def pgdump
- "#{ utility(:pg_dump) } #{ credential_options } #{ connectivity_options } " +
- "#{ options } #{ tables_to_dump } #{ tables_to_skip } #{ name }"
- end
-
- ##
- # Performs the pgdump command and outputs the
- # data to the specified path based on the 'trigger'
- # and resets the 'PGPASSWORD' environment variable to nil
- def perform!
- log!
- run("#{pgdump} > '#{File.join(dump_path, name)}.sql'")
- ENV['PGPASSWORD'] = nil
- end
-
- end
- end
-end
View
105 lib/backup/database/redis.rb
@@ -1,105 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Database
- class Redis < Base
-
- ##
- # Name of and path to the database that needs to get dumped
- attr_accessor :name, :path
-
- ##
- # Credentials for the specified database
- attr_accessor :password
-
- ##
- # Determines whether Backup should invoke the SAVE command through
- # the 'redis-cli' utility to persist the most recent data before
- # copying over the dump file
- attr_accessor :invoke_save
-
- ##
- # Connectivity options
- attr_accessor :host, :port, :socket
-
- ##
- # Additional "redis-cli" options
- attr_accessor :additional_options
-
- ##
- # Creates a new instance of the Redis database object
- def initialize(&block)
- load_defaults!
-
- @additional_options ||= Array.new
-
- instance_eval(&block)
- prepare!
- end
-
- ##
- # Builds the Redis credentials syntax to authenticate the user
- # to perform the database dumping process
- def credential_options
- return "-a '#{password}'" if password; String.new
- end
-
- ##
- # Builds the Redis connectivity options syntax to connect the user
- # to perform the database dumping process
- def connectivity_options
- %w[host port socket].map do |option|
- next if send(option).nil?; "-#{option[0,1]} '#{send(option)}'"
- end.compact.join("\s")
- end
-
- ##
- # Builds a Redis compatible string for the
- # additional options specified by the user
- def additional_options
- @additional_options.join("\s")
- end
-
- ##
- # Returns the Redis database file name
- def database
- "#{ name }.rdb"
- end
-
- ##
- # Performs the Redis backup by using the 'cp' unix utility
- # to copy the persisted Redis dump file to the Backup archive.
- # Additionally, when 'invoke_save' is set to true, it'll tell
- # the Redis server to persist the current state to the dump file
- # before copying the dump to get the most recent updates in to the backup
- def perform!
- log!
-
- invoke_save! if invoke_save
- copy!
- end
-
- ##
- # Tells Redis to persist the current state of the
- # in-memory database to the persisted dump file
- def invoke_save!
- response = run("#{ utility('redis-cli') } #{ credential_options } #{ connectivity_options } #{ additional_options } SAVE")
- unless response =~ /OK/
- Logger.error "Could not invoke the Redis SAVE command. The #{ database } file might not be contain the most recent data."
- Logger.error "Please check if the server is running, the credentials (if any) are correct, and the host/port/socket are correct."
- end
- end
-
- ##
- # Performs the copy command to copy over the Redis dump file to the Backup archive
- def copy!
- unless File.exist?(File.join(path, database))
- Logger.error "Redis database dump not found in '#{ File.join(path, database) }'"
- exit
- end
-
- run("#{ utility(:cp) } '#{ File.join(path, database) }' '#{ File.join(dump_path, database) }'")
- end
- end
- end
-end
View
17 lib/backup/encryptor/base.rb
@@ -1,17 +0,0 @@
-# encoding: utf-8
-
-module Backup
- module Encryptor
- class Base
- include Backup::CLI
- include Backup::Configuration::Helpers
-
- ##
- # Logs a message to the console and log file to inform
- # the client that Backup is encrypting the archive
- def log!
- Logger.message "#{ self.class } started encrypting the archive."
- end
- end
- end
-end
View
78 lib/backup/encryptor/gpg.rb
@@ -1,78 +0,0 @@
-# encoding: utf-8
-
-##
-# Require the tempfile Ruby library when Backup::Encryptor::GPG is loaded
-require 'tempfile'
-
-module Backup
- module Encryptor
- class GPG < Base
-
- ##
- # The GPG Public key that'll be used to encrypt the backup
- attr_accessor :key
-
- ##
- # Contains the GPG encryption key id which'll be extracted from the public key file
- attr_accessor :encryption_key_id
-
- ##
- # Contains the temporary file with the public key
- attr_accessor :tmp_file
-
- ##
- # Creates a new instance of Backup::Encryptor::GPG and
- # sets the key to the provided GPG key. To enhance the DSL
- # the user may use tabs and spaces to indent the multi-line key string
- # since we gsub() every preceding 'space' and 'tab' on each line
- def initialize(&block)