alg-backup 3.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.infinity_test +7 -0
- data/.rspec +3 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +101 -0
- data/LICENSE.md +24 -0
- data/README.md +276 -0
- data/backup.gemspec +39 -0
- data/bin/backup +260 -0
- data/lib/backup.rb +168 -0
- data/lib/backup/archive.rb +73 -0
- data/lib/backup/cli.rb +50 -0
- data/lib/backup/compressor/base.rb +17 -0
- data/lib/backup/compressor/gzip.rb +61 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/compressor/base.rb +10 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/database/base.rb +18 -0
- data/lib/backup/configuration/database/mongodb.rb +37 -0
- data/lib/backup/configuration/database/mysql.rb +37 -0
- data/lib/backup/configuration/database/postgresql.rb +37 -0
- data/lib/backup/configuration/database/redis.rb +35 -0
- data/lib/backup/configuration/encryptor/base.rb +10 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
- data/lib/backup/configuration/helpers.rb +54 -0
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
- data/lib/backup/configuration/storage/dropbox.rb +29 -0
- data/lib/backup/configuration/storage/ftp.rb +25 -0
- data/lib/backup/configuration/storage/rsync.rb +25 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/rsync.rb +45 -0
- data/lib/backup/configuration/syncer/s3.rb +33 -0
- data/lib/backup/database/base.rb +33 -0
- data/lib/backup/database/mongodb.rb +137 -0
- data/lib/backup/database/mysql.rb +104 -0
- data/lib/backup/database/postgresql.rb +111 -0
- data/lib/backup/database/redis.rb +105 -0
- data/lib/backup/dependency.rb +84 -0
- data/lib/backup/encryptor/base.rb +17 -0
- data/lib/backup/encryptor/gpg.rb +78 -0
- data/lib/backup/encryptor/open_ssl.rb +67 -0
- data/lib/backup/finder.rb +39 -0
- data/lib/backup/logger.rb +86 -0
- data/lib/backup/model.rb +272 -0
- data/lib/backup/notifier/base.rb +29 -0
- data/lib/backup/notifier/binder.rb +32 -0
- data/lib/backup/notifier/mail.rb +141 -0
- data/lib/backup/notifier/templates/notify_failure.erb +31 -0
- data/lib/backup/notifier/templates/notify_success.erb +16 -0
- data/lib/backup/notifier/twitter.rb +87 -0
- data/lib/backup/storage/base.rb +67 -0
- data/lib/backup/storage/cloudfiles.rb +95 -0
- data/lib/backup/storage/dropbox.rb +87 -0
- data/lib/backup/storage/ftp.rb +114 -0
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +99 -0
- data/lib/backup/storage/s3.rb +108 -0
- data/lib/backup/storage/scp.rb +106 -0
- data/lib/backup/storage/sftp.rb +106 -0
- data/lib/backup/syncer/base.rb +10 -0
- data/lib/backup/syncer/rsync.rb +117 -0
- data/lib/backup/syncer/s3.rb +116 -0
- data/lib/backup/version.rb +43 -0
- data/lib/templates/archive +4 -0
- data/lib/templates/compressor/gzip +4 -0
- data/lib/templates/database/mongodb +10 -0
- data/lib/templates/database/mysql +11 -0
- data/lib/templates/database/postgresql +11 -0
- data/lib/templates/database/redis +10 -0
- data/lib/templates/encryptor/gpg +9 -0
- data/lib/templates/encryptor/openssl +5 -0
- data/lib/templates/notifier/mail +14 -0
- data/lib/templates/notifier/twitter +9 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +7 -0
- data/lib/templates/storage/dropbox +9 -0
- data/lib/templates/storage/ftp +8 -0
- data/lib/templates/storage/rsync +7 -0
- data/lib/templates/storage/s3 +8 -0
- data/lib/templates/storage/scp +8 -0
- data/lib/templates/storage/sftp +8 -0
- data/lib/templates/syncer/rsync +14 -0
- data/lib/templates/syncer/s3 +12 -0
- data/spec/archive_spec.rb +90 -0
- data/spec/backup_spec.rb +11 -0
- data/spec/compressor/gzip_spec.rb +59 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/gzip_spec.rb +28 -0
- data/spec/configuration/database/base_spec.rb +16 -0
- data/spec/configuration/database/mongodb_spec.rb +30 -0
- data/spec/configuration/database/mysql_spec.rb +32 -0
- data/spec/configuration/database/postgresql_spec.rb +32 -0
- data/spec/configuration/database/redis_spec.rb +30 -0
- data/spec/configuration/encryptor/gpg_spec.rb +25 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
- data/spec/configuration/notifier/mail_spec.rb +32 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
- data/spec/configuration/storage/dropbox_spec.rb +43 -0
- data/spec/configuration/storage/ftp_spec.rb +40 -0
- data/spec/configuration/storage/rsync_spec.rb +37 -0
- data/spec/configuration/storage/s3_spec.rb +37 -0
- data/spec/configuration/storage/scp_spec.rb +40 -0
- data/spec/configuration/storage/sftp_spec.rb +40 -0
- data/spec/configuration/syncer/rsync_spec.rb +46 -0
- data/spec/configuration/syncer/s3_spec.rb +43 -0
- data/spec/database/base_spec.rb +30 -0
- data/spec/database/mongodb_spec.rb +144 -0
- data/spec/database/mysql_spec.rb +150 -0
- data/spec/database/postgresql_spec.rb +164 -0
- data/spec/database/redis_spec.rb +122 -0
- data/spec/encryptor/gpg_spec.rb +57 -0
- data/spec/encryptor/open_ssl_spec.rb +102 -0
- data/spec/logger_spec.rb +46 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/notifier/twitter_spec.rb +86 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/storage/base_spec.rb +33 -0
- data/spec/storage/cloudfiles_spec.rb +102 -0
- data/spec/storage/dropbox_spec.rb +105 -0
- data/spec/storage/ftp_spec.rb +133 -0
- data/spec/storage/object_spec.rb +74 -0
- data/spec/storage/rsync_spec.rb +115 -0
- data/spec/storage/s3_spec.rb +110 -0
- data/spec/storage/scp_spec.rb +129 -0
- data/spec/storage/sftp_spec.rb +125 -0
- data/spec/syncer/rsync_spec.rb +156 -0
- data/spec/syncer/s3_spec.rb +139 -0
- data/spec/version_spec.rb +21 -0
- metadata +217 -0
data/.gitignore
ADDED
data/.infinity_test
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
##
|
2
|
+
# RubyGems Source
|
3
|
+
source 'http://rubygems.org'
|
4
|
+
|
5
|
+
##
|
6
|
+
# Load Backup::Dependency
|
7
|
+
%w[cli dependency].each do |path|
|
8
|
+
require File.expand_path("../lib/backup/#{path}", __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Dynamically define the dependencies specified in Backup::Dependency.all
|
13
|
+
Backup::Dependency.all.each do |name, gemspec|
|
14
|
+
gem(name, gemspec[:version])
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Define gems to be used in the 'test' environment
|
19
|
+
group :test do
|
20
|
+
gem 'rspec'
|
21
|
+
gem 'mocha'
|
22
|
+
gem 'infinity_test'
|
23
|
+
gem 'fuubar'
|
24
|
+
gem 'timecop'
|
25
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.5)
|
5
|
+
addressable (2.2.4)
|
6
|
+
builder (3.0.0)
|
7
|
+
diff-lcs (1.1.2)
|
8
|
+
dropbox (1.2.3)
|
9
|
+
json (>= 1.2.0)
|
10
|
+
mechanize (>= 1.0.0)
|
11
|
+
multipart-post (>= 1.0)
|
12
|
+
oauth (>= 0.3.6)
|
13
|
+
excon (0.5.6)
|
14
|
+
faraday (0.5.7)
|
15
|
+
addressable (~> 2.2.4)
|
16
|
+
multipart-post (~> 1.1.0)
|
17
|
+
rack (< 2, >= 1.1.0)
|
18
|
+
faraday_middleware (0.3.2)
|
19
|
+
faraday (~> 0.5.4)
|
20
|
+
fog (0.7.0)
|
21
|
+
builder
|
22
|
+
excon (>= 0.5.5)
|
23
|
+
formatador (>= 0.1.1)
|
24
|
+
json
|
25
|
+
mime-types
|
26
|
+
net-ssh (>= 2.0.23)
|
27
|
+
nokogiri (>= 1.4.4)
|
28
|
+
ruby-hmac
|
29
|
+
formatador (0.1.1)
|
30
|
+
fuubar (0.0.3)
|
31
|
+
rspec (~> 2.0)
|
32
|
+
rspec-instafail (~> 0.1.4)
|
33
|
+
ruby-progressbar (~> 0.0.9)
|
34
|
+
hashie (1.0.0)
|
35
|
+
i18n (0.5.0)
|
36
|
+
infinity_test (1.0.2)
|
37
|
+
notifiers (>= 1.1.0)
|
38
|
+
watchr (>= 0.7)
|
39
|
+
json (1.5.1)
|
40
|
+
mail (2.2.15)
|
41
|
+
activesupport (>= 2.3.6)
|
42
|
+
i18n (>= 0.4.0)
|
43
|
+
mime-types (~> 1.16)
|
44
|
+
treetop (~> 1.4.8)
|
45
|
+
mechanize (1.0.0)
|
46
|
+
nokogiri (>= 1.2.1)
|
47
|
+
mime-types (1.16)
|
48
|
+
mocha (0.9.12)
|
49
|
+
multi_json (0.0.5)
|
50
|
+
multi_xml (0.2.1)
|
51
|
+
multipart-post (1.1.0)
|
52
|
+
net-scp (1.0.4)
|
53
|
+
net-ssh (>= 1.99.1)
|
54
|
+
net-sftp (2.0.5)
|
55
|
+
net-ssh (>= 2.0.9)
|
56
|
+
net-ssh (2.1.3)
|
57
|
+
nokogiri (1.4.4)
|
58
|
+
notifiers (1.1.0)
|
59
|
+
oauth (0.4.4)
|
60
|
+
polyglot (0.3.1)
|
61
|
+
rack (1.2.2)
|
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
|
+
simple_oauth (0.1.4)
|
74
|
+
timecop (0.3.5)
|
75
|
+
treetop (1.4.9)
|
76
|
+
polyglot (>= 0.3.1)
|
77
|
+
twitter (1.1.2)
|
78
|
+
faraday (~> 0.5.4)
|
79
|
+
faraday_middleware (~> 0.3.1)
|
80
|
+
hashie (~> 1.0.0)
|
81
|
+
multi_json (~> 0.0.5)
|
82
|
+
multi_xml (~> 0.2.0)
|
83
|
+
simple_oauth (~> 0.1.3)
|
84
|
+
watchr (0.7)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
ruby
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
dropbox (~> 1.2.3)
|
91
|
+
fog (~> 0.7.0)
|
92
|
+
fuubar
|
93
|
+
infinity_test
|
94
|
+
mail (~> 2.2.15)
|
95
|
+
mocha
|
96
|
+
net-scp (~> 1.0.4)
|
97
|
+
net-sftp (~> 2.0.5)
|
98
|
+
net-ssh (~> 2.1.3)
|
99
|
+
rspec
|
100
|
+
timecop
|
101
|
+
twitter (~> 1.1.2)
|
data/LICENSE.md
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,276 @@
|
|
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 provide Syncers (RSync, S3) for efficient backups, it can archive files and directories, 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 (Email or Twitter). 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
|
+
You can view the list of released versions over at [RubyGems.org (Backup)](https://rubygems.org/gems/backup/versions)
|
21
|
+
|
22
|
+
Getting Started
|
23
|
+
---------------
|
24
|
+
|
25
|
+
I recommend you read this README first, and refer to the [Wiki pages](https://github.com/meskyanichi/backup/wiki) afterwards. There's also a [Getting Started wiki page](https://github.com/meskyanichi/backup/wiki/Getting-Started).
|
26
|
+
|
27
|
+
What Backup 3 currently supports
|
28
|
+
================================
|
29
|
+
|
30
|
+
**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.**
|
31
|
+
|
32
|
+
Database Support
|
33
|
+
----------------
|
34
|
+
|
35
|
+
- MySQL
|
36
|
+
- PostgreSQL
|
37
|
+
- MongoDB
|
38
|
+
- Redis
|
39
|
+
|
40
|
+
[Database Wiki Page](https://github.com/meskyanichi/backup/wiki/Databases)
|
41
|
+
|
42
|
+
Filesystem Support
|
43
|
+
------------------
|
44
|
+
|
45
|
+
- Files
|
46
|
+
- Directories
|
47
|
+
|
48
|
+
[Archive Wiki Page](https://github.com/meskyanichi/backup/wiki/Archives)
|
49
|
+
|
50
|
+
Storage Locations
|
51
|
+
-----------------
|
52
|
+
|
53
|
+
- Amazon Simple Storage Service (S3)
|
54
|
+
- Rackspace Cloud Files (Mosso)
|
55
|
+
- Dropbox
|
56
|
+
- Remote Servers *(Available Protocols: FTP, SFTP, SCP and RSync)*
|
57
|
+
|
58
|
+
[Storage Wiki Page](https://github.com/meskyanichi/backup/wiki/Storages)
|
59
|
+
|
60
|
+
Storage Features
|
61
|
+
----------------
|
62
|
+
|
63
|
+
- Backup Cycling, applies to:
|
64
|
+
- Amazon Simple Storage Service (S3)
|
65
|
+
- Rackspace Cloud Files (Mosso)
|
66
|
+
- Dropbox
|
67
|
+
- Remote Servers *(Only Protocols: FTP, SFTP, SCP)*
|
68
|
+
- Incremental Backups, applies to:
|
69
|
+
- Remote Servers *(Only Protocols: RSync)*
|
70
|
+
|
71
|
+
[Storage Wiki Page](https://github.com/meskyanichi/backup/wiki/Storages)
|
72
|
+
|
73
|
+
Syncers
|
74
|
+
-------
|
75
|
+
|
76
|
+
- RSync
|
77
|
+
- Amazon Simple Storage Service (S3)
|
78
|
+
|
79
|
+
[Syncer Wiki Page](https://github.com/meskyanichi/backup/wiki/Syncers)
|
80
|
+
|
81
|
+
Compressors
|
82
|
+
-----------
|
83
|
+
|
84
|
+
- Gzip
|
85
|
+
|
86
|
+
[Compressors Wiki Page](https://github.com/meskyanichi/backup/wiki/Compressors)
|
87
|
+
|
88
|
+
Encryptors
|
89
|
+
----------
|
90
|
+
|
91
|
+
- OpenSSL
|
92
|
+
- GPG
|
93
|
+
|
94
|
+
[Encryptors Wiki Page](https://github.com/meskyanichi/backup/wiki/Encryptors)
|
95
|
+
|
96
|
+
Notifiers
|
97
|
+
---------
|
98
|
+
|
99
|
+
- Mail
|
100
|
+
- Twitter
|
101
|
+
|
102
|
+
[Notifiers Wiki Page](https://github.com/meskyanichi/backup/wiki/Notifiers)
|
103
|
+
|
104
|
+
Supported Ruby versions (Tested with RSpec)
|
105
|
+
-------------------------------------------
|
106
|
+
|
107
|
+
- Ruby 1.9.2
|
108
|
+
- Ruby 1.8.7
|
109
|
+
- Ruby Enterprise Edition 1.8.7
|
110
|
+
|
111
|
+
Environments
|
112
|
+
------------
|
113
|
+
|
114
|
+
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.
|
115
|
+
|
116
|
+
Compatibility
|
117
|
+
-------------
|
118
|
+
|
119
|
+
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.
|
120
|
+
|
121
|
+
|
122
|
+
A sample "Backup" configuration file
|
123
|
+
====================================
|
124
|
+
|
125
|
+
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)**
|
126
|
+
|
127
|
+
Backup::Model.new(:sample_backup, 'A sample backup configuration') do
|
128
|
+
|
129
|
+
database MySQL do |database|
|
130
|
+
database.name = 'my_sample_mysql_db'
|
131
|
+
database.username = 'my_username'
|
132
|
+
database.password = 'my_password'
|
133
|
+
database.skip_tables = ['logs']
|
134
|
+
database.additional_options = ['--single-transaction', '--quick']
|
135
|
+
end
|
136
|
+
|
137
|
+
database MongoDB do |database|
|
138
|
+
database.name = 'my_sample_mongo_db'
|
139
|
+
database.only_collections = ['users', 'events', 'posts']
|
140
|
+
end
|
141
|
+
|
142
|
+
archive :user_avatars do |archive|
|
143
|
+
archive.add '/var/apps/my_sample_app/public/avatars'
|
144
|
+
end
|
145
|
+
|
146
|
+
archive :logs do |archive|
|
147
|
+
archive.add '/var/apps/my_sample_app/logs/production.log'
|
148
|
+
archive.add '/var/apps/my_sample_app/logs/newrelic_agent.log'
|
149
|
+
archive.add '/var/apps/my_sample_app/logs/other.log'
|
150
|
+
end
|
151
|
+
|
152
|
+
encrypt_with OpenSSL do |encryption|
|
153
|
+
encryption.password = 'my_secret_password'
|
154
|
+
end
|
155
|
+
|
156
|
+
compress_with Gzip do |compression|
|
157
|
+
compression.best = true
|
158
|
+
end
|
159
|
+
|
160
|
+
store_with S3 do |s3|
|
161
|
+
s3.access_key_id = 'my_access_key_id'
|
162
|
+
s3.secret_access_key = 'my_secret_access_key'
|
163
|
+
s3.region = 'us-east-1'
|
164
|
+
s3.bucket = 'my_bucket/backups'
|
165
|
+
s3.keep = 20
|
166
|
+
end
|
167
|
+
|
168
|
+
sync_with S3 do |s3|
|
169
|
+
s3.access_key_id = "my_access_key_id"
|
170
|
+
s3.secret_access_key = "my_secret_access_key"
|
171
|
+
s3.bucket = "my-bucket"
|
172
|
+
s3.path = "/backups"
|
173
|
+
s3.mirror = true
|
174
|
+
|
175
|
+
s3.directories do |directory|
|
176
|
+
directory.add "/var/apps/my_app/public/videos"
|
177
|
+
directory.add "/var/apps/my_app/public/music"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
notify_by Mail do |mail|
|
182
|
+
mail.on_success = false
|
183
|
+
mail.on_failure = true
|
184
|
+
end
|
185
|
+
|
186
|
+
notify_by Twitter do |tweet|
|
187
|
+
tweet.on_success = true
|
188
|
+
tweet.on_failure = true
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
### Explanation for the above example
|
194
|
+
|
195
|
+
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, we're going to use the S3 Syncer to create a mirror of the `/var/apps/my_app/public/videos` and `/var/apps/my_app/public/music` directories on Amazon S3. (This will not package, compress, encrypt - but will directly sync the specified directories "as is" to your S3 bucket). Finally, it'll notify me by email if the backup raises an error/exception during the process, indicating that something went wrong. However, it does not notify me by email when successful backups occur because I set `mail.on_success` to `false`. It'll also notify me by Twitter when failed backups occur, but also when successful ones occur because I set the `tweet.on_success` to `true`.
|
196
|
+
|
197
|
+
### Things to note
|
198
|
+
|
199
|
+
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.
|
200
|
+
|
201
|
+
The __S3__ Syncer ( `sync_with` ) is a different kind of __Storage__ method. As mentioned above, it does not follow the same procedure as the __Storage__ ( `store_with` ) method. A Storage method stores the final result of a copied/organized/packaged/compressed/encrypted file to the desired remote location. A Syncer directly syncs the specified directories and **completely bypasses** the copy/organize/package/compress/encrypt process. This is especially good for backing up directories containing gigabytes of data, such as images, music, videos, and similar large formats. Also, rather than transferring the whole directory every time, it'll only transfer files in all these directories that have been modified or added, thus, saving huge amounts of bandwidth, cpu load and time. You're also not bound to the 5GB per file restriction like the **Storage** method, unless you actually have files in these directories that are >= 5GB, which often is unlikely. Even if the whole directory (and sub-directories) are > 5GB (split over multiple files), it shouldn't be a problem as long as you don't have any *single* file that is 5GB in size. Also, in the above example you see `s3.mirror = true`, this tells the S3 Syncer to keep a "mirror" of the local directories in the S3 bucket. This means that if you delete a file locally, the next time it syncs, it'll also delete the file from the S3 bucket, keeping the local filesystem 1:1 with the S3 bucket.
|
202
|
+
|
203
|
+
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.
|
204
|
+
|
205
|
+
The __Twitter__ notifier. You will require your consumer and oauth credentials, which I have also left out of this example.
|
206
|
+
|
207
|
+
Check out the Wiki for more information on all the above subjects.
|
208
|
+
|
209
|
+
### And that's it!
|
210
|
+
|
211
|
+
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, syncers, 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).
|
212
|
+
|
213
|
+
### Running the example
|
214
|
+
|
215
|
+
Remember the `Backup::Model.new(:sample_backup, 'A sample backup configuration') do`?
|
216
|
+
The `:sample_backup` is called the "id", or "trigger". This is used to identify the backup procedure/file and initialize it.
|
217
|
+
|
218
|
+
backup perform -t sample_backup
|
219
|
+
|
220
|
+
That's it.
|
221
|
+
|
222
|
+
### Automatic backups
|
223
|
+
|
224
|
+
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:
|
225
|
+
|
226
|
+
every 6.hours do
|
227
|
+
command "backup perform -t sample_backup"
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
Documentation
|
232
|
+
-------------
|
233
|
+
|
234
|
+
See the [Wiki Pages](https://github.com/meskyanichi/backup/wiki). The subjects labeled **without** the "Backup 2)"-prefix are meant for Backup 3 users.
|
235
|
+
|
236
|
+
|
237
|
+
Suggestions, Bugs, Requests, Questions
|
238
|
+
--------------------------------------
|
239
|
+
|
240
|
+
View the [issue log](https://github.com/meskyanichi/backup/issues) and post them there.
|
241
|
+
|
242
|
+
Contributors
|
243
|
+
------------
|
244
|
+
|
245
|
+
<table>
|
246
|
+
<tr>
|
247
|
+
<th>Contributor</th>
|
248
|
+
<th>Contribution</th>
|
249
|
+
</tr>
|
250
|
+
<tr>
|
251
|
+
<td><a href="https://github.com/asanghi" target="_blank">Aditya Sanghi ( asanghi )</a></td>
|
252
|
+
<td>Twitter Notifier, Dropbox Timeout Configuration</td>
|
253
|
+
</tr>
|
254
|
+
<tr>
|
255
|
+
<td><a href="https://github.com/phlipper" target="_blank">Phil Cohen ( phlipper )</a></td>
|
256
|
+
<td>Exclude Option for Archives</td>
|
257
|
+
</tr>
|
258
|
+
</table>
|
259
|
+
|
260
|
+
Want to contribute?
|
261
|
+
-------------------
|
262
|
+
|
263
|
+
- Fork/Clone the **develop** branch
|
264
|
+
- Write RSpec tests, and test against:
|
265
|
+
- Ruby 1.9.2
|
266
|
+
- Ruby 1.8.7
|
267
|
+
- Ruby Enterprise Edition 1.8.7
|
268
|
+
- Try to keep the overall *structure / design* of the gem the same
|
269
|
+
|
270
|
+
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.
|
271
|
+
|
272
|
+
|
273
|
+
Backup 2 - Issues, Wiki, Source, Gems
|
274
|
+
=====================================
|
275
|
+
|
276
|
+
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).
|
data/backup.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
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 = 'alg-backup'
|
10
|
+
gem.version = Backup::Version.current
|
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)
|
16
|
+
that allows you to configure and perform backups in a simple manner using
|
17
|
+
an elegant Ruby DSL. It supports various databases (MySQL, PostgreSQL, MongoDB and Redis),
|
18
|
+
it supports various storage locations (Amazon S3, Rackspace Cloud Files, Dropbox, any remote
|
19
|
+
server through FTP, SFTP, SCP and RSync), it provide Syncers (RSync, S3) for efficient backups,
|
20
|
+
it can archive files and directories, it can cycle backups, it can do incremental backups, it
|
21
|
+
can compress backups, it can encrypt backups (OpenSSL or GPG), it can notify you about
|
22
|
+
successful and/or failed backups (Email or Twitter). It is very extensible and easy to add new
|
23
|
+
functionality to. It\'s easy to use.'
|
24
|
+
|
25
|
+
##
|
26
|
+
# Files and folder that need to be compiled in to the Ruby Gem
|
27
|
+
gem.files = %x[git ls-files].split("\n")
|
28
|
+
gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
|
29
|
+
gem.require_path = 'lib'
|
30
|
+
|
31
|
+
##
|
32
|
+
# The Backup CLI executable
|
33
|
+
gem.executables = ['backup']
|
34
|
+
|
35
|
+
##
|
36
|
+
# Production gem dependencies
|
37
|
+
gem.add_dependency 'thor', ['~> 0.14.6']
|
38
|
+
|
39
|
+
end
|