backup 2.4.5.1 → 3.0.0.build.0
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 +17 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.md +24 -0
- data/README.md +189 -75
- data/backup.gemspec +41 -0
- data/bin/backup +161 -90
- data/lib/backup.rb +133 -117
- data/lib/backup/archive.rb +54 -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 +7 -67
- 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 +47 -17
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -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 +25 -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/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/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 +80 -0
- data/lib/backup/model.rb +249 -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/storage/base.rb +60 -3
- data/lib/backup/storage/cloudfiles.rb +85 -6
- data/lib/backup/storage/dropbox.rb +74 -4
- data/lib/backup/storage/ftp.rb +103 -27
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +100 -0
- data/lib/backup/storage/s3.rb +100 -7
- data/lib/backup/storage/scp.rb +94 -19
- data/lib/backup/storage/sftp.rb +94 -19
- data/lib/backup/version.rb +70 -1
- 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/readme +15 -0
- data/lib/templates/storage/cloudfiles +7 -0
- data/lib/templates/storage/dropbox +8 -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/spec/archive_spec.rb +53 -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 +40 -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/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 +37 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/mail_spec.rb +97 -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 +89 -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/version_spec.rb +32 -0
- metadata +139 -123
- data/CHANGELOG +0 -131
- data/LICENSE +0 -20
- data/generators/backup/backup_generator.rb +0 -69
- data/generators/backup/templates/backup.rake +0 -56
- data/generators/backup/templates/backup.rb +0 -253
- data/generators/backup/templates/create_backup_tables.rb +0 -18
- data/generators/backup_update/backup_update_generator.rb +0 -50
- data/generators/backup_update/templates/migrations/update_backup_tables.rb +0 -27
- data/lib/backup/adapters/archive.rb +0 -34
- data/lib/backup/adapters/base.rb +0 -167
- data/lib/backup/adapters/custom.rb +0 -41
- data/lib/backup/adapters/mongo_db.rb +0 -139
- data/lib/backup/adapters/mysql.rb +0 -60
- data/lib/backup/adapters/postgresql.rb +0 -60
- data/lib/backup/adapters/sqlite.rb +0 -25
- data/lib/backup/command_helper.rb +0 -14
- data/lib/backup/configuration/adapter.rb +0 -21
- data/lib/backup/configuration/adapter_options.rb +0 -8
- data/lib/backup/configuration/attributes.rb +0 -19
- data/lib/backup/configuration/mail.rb +0 -20
- data/lib/backup/configuration/smtp.rb +0 -8
- data/lib/backup/configuration/storage.rb +0 -8
- data/lib/backup/connection/cloudfiles.rb +0 -75
- data/lib/backup/connection/dropbox.rb +0 -63
- data/lib/backup/connection/s3.rb +0 -88
- data/lib/backup/core_ext/object.rb +0 -5
- data/lib/backup/environment/base.rb +0 -12
- data/lib/backup/environment/rails_configuration.rb +0 -15
- data/lib/backup/environment/unix_configuration.rb +0 -109
- data/lib/backup/mail/base.rb +0 -97
- data/lib/backup/mail/mail.txt +0 -7
- data/lib/backup/record/base.rb +0 -65
- data/lib/backup/record/cloudfiles.rb +0 -28
- data/lib/backup/record/dropbox.rb +0 -27
- data/lib/backup/record/ftp.rb +0 -39
- data/lib/backup/record/local.rb +0 -26
- data/lib/backup/record/s3.rb +0 -25
- data/lib/backup/record/scp.rb +0 -33
- data/lib/backup/record/sftp.rb +0 -38
- data/lib/backup/storage/local.rb +0 -22
- data/lib/generators/backup/USAGE +0 -10
- data/lib/generators/backup/backup_generator.rb +0 -47
- data/lib/generators/backup/templates/backup.rake +0 -56
- data/lib/generators/backup/templates/backup.rb +0 -236
- data/lib/generators/backup/templates/create_backup_tables.rb +0 -18
- data/setup/backup.rb +0 -257
- data/setup/backup.sqlite3 +0 -0
data/lib/backup/storage/sftp.rb
CHANGED
@@ -1,31 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# Only load the Net::SFTP library/gem when the Backup::Storage::SFTP class is loaded
|
1
5
|
require 'net/sftp'
|
2
6
|
|
3
7
|
module Backup
|
4
8
|
module Storage
|
5
9
|
class SFTP < Base
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
|
11
|
+
##
|
12
|
+
# Server credentials
|
13
|
+
attr_accessor :username, :password
|
14
|
+
|
15
|
+
##
|
16
|
+
# Server IP Address and SFTP port
|
17
|
+
attr_accessor :ip, :port
|
18
|
+
|
19
|
+
##
|
20
|
+
# Path to store backups to
|
21
|
+
attr_accessor :path
|
22
|
+
|
23
|
+
##
|
24
|
+
# Creates a new instance of the SFTP storage object
|
25
|
+
# First it sets the defaults (if any exist) and then evaluates
|
26
|
+
# the configuration block which may overwrite these defaults
|
27
|
+
def initialize(&block)
|
28
|
+
load_defaults!
|
29
|
+
|
30
|
+
@port ||= 22
|
31
|
+
@path ||= 'backups'
|
32
|
+
|
33
|
+
instance_eval(&block) if block_given?
|
34
|
+
|
35
|
+
@time = TIME
|
36
|
+
@path = path.sub(/^\~\//, '')
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# This is the remote path to where the backup files will be stored
|
41
|
+
def remote_path
|
42
|
+
File.join(path, TRIGGER)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Performs the backup transfer
|
47
|
+
def perform!
|
48
|
+
transfer!
|
49
|
+
cycle!
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
##
|
55
|
+
# Establishes a connection to the remote server and returns the Net::SFTP object.
|
56
|
+
# Not doing any instance variable caching because this object gets persisted in YAML
|
57
|
+
# format to a file and will issues. This, however has no impact on performance since it only
|
58
|
+
# gets invoked once per object for a #transfer! and once for a remove! Backups run in the
|
59
|
+
# background anyway so even if it were a bit slower it shouldn't matter.
|
60
|
+
def connection
|
61
|
+
Net::SFTP.start(ip, username, :password => password, :port => port)
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Transfers the archived file to the specified remote server
|
66
|
+
def transfer!
|
67
|
+
Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
|
68
|
+
create_remote_directories!
|
69
|
+
connection.upload!(
|
70
|
+
File.join(local_path, local_file),
|
71
|
+
File.join(remote_path, remote_file)
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Removes the transferred archive file from the server
|
77
|
+
def remove!
|
78
|
+
begin
|
79
|
+
connection.remove!(
|
80
|
+
File.join(remote_path, remote_file)
|
81
|
+
)
|
82
|
+
rescue Net::SFTP::StatusException
|
83
|
+
Logger.warn "Could not remove file \"#{ File.join(remote_path, remote_file) }\"."
|
13
84
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Creates (if they don't exist yet) all the directories on the remote
|
89
|
+
# server in order to upload the backup file. Net::SFTP does not support
|
90
|
+
# paths to directories that don't yet exist when creating new directories.
|
91
|
+
# Instead, we split the parts up in to an array (for each '/') and loop through
|
92
|
+
# that to create the directories one by one. Net::SFTP raises an exception when
|
93
|
+
# the directory it's trying ot create already exists, so we have rescue it
|
94
|
+
def create_remote_directories!
|
95
|
+
path_parts = Array.new
|
96
|
+
remote_path.split('/').each do |path_part|
|
97
|
+
path_parts << path_part
|
19
98
|
begin
|
20
|
-
|
21
|
-
|
22
|
-
rescue
|
23
|
-
puts "Could not find \"#{path}\" on \"#{ip}\", please ensure this directory exists."
|
24
|
-
exit
|
25
|
-
end
|
99
|
+
connection.mkdir!(path_parts.join('/'))
|
100
|
+
rescue Net::SFTP::StatusException; end
|
26
101
|
end
|
27
102
|
end
|
28
|
-
|
103
|
+
|
29
104
|
end
|
30
105
|
end
|
31
106
|
end
|
data/lib/backup/version.rb
CHANGED
@@ -1,3 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Backup
|
2
|
-
|
4
|
+
|
5
|
+
##
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# # Returns the current backup version based on the defined constants
|
9
|
+
# Backup::Version.current
|
10
|
+
#
|
11
|
+
# # Returns a gemspec compatible version number based on the defined constants
|
12
|
+
# Backup::Version.gemspec
|
13
|
+
#
|
14
|
+
class Version
|
15
|
+
|
16
|
+
##
|
17
|
+
# MAJOR:
|
18
|
+
# Defines the major version
|
19
|
+
# MINOR:
|
20
|
+
# Defines the minor version
|
21
|
+
# PATCH:
|
22
|
+
# Defines the patch version
|
23
|
+
# BUILD:
|
24
|
+
# Defines the build version ( use 'false' if no build )
|
25
|
+
MAJOR, MINOR, PATCH, BUILD = 3, 0, 0, 0
|
26
|
+
|
27
|
+
# ========================================================= #
|
28
|
+
# ADJUST THE CONSTANTS ABOVE TO CHANGE THE BACKUP VERSION #
|
29
|
+
# ========================================================= #
|
30
|
+
|
31
|
+
##
|
32
|
+
# Returns the major version ( big release based off of multiple minor releases )
|
33
|
+
def self.major
|
34
|
+
MAJOR
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Returns the minor version ( small release based off of multiple patches )
|
39
|
+
def self.minor
|
40
|
+
MINOR
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Returns the patch version ( updates, features and (crucial) bug fixes based off of multiple builds )
|
45
|
+
def self.patch
|
46
|
+
PATCH
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Returns the build version ( improvements, small additions, frequent releases )
|
51
|
+
def self.build
|
52
|
+
BUILD
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Returns the current version ( not for gemspec / rubygems )
|
57
|
+
def self.current
|
58
|
+
"#{major}.#{minor}.#{patch} / build #{build or 0}"
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Returns the (gemspec qualified) current version
|
63
|
+
def self.gemspec
|
64
|
+
if build.eql?(false)
|
65
|
+
"#{major}.#{minor}.#{patch}"
|
66
|
+
else
|
67
|
+
"#{major}.#{minor}.#{patch}.build.#{build}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
3
72
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
database MongoDB do |db|
|
2
|
+
db.name = "my_database_name"
|
3
|
+
db.username = "my_username"
|
4
|
+
db.password = "my_password"
|
5
|
+
db.host = "localhost"
|
6
|
+
db.port = 5432
|
7
|
+
db.ipv6 = false
|
8
|
+
db.only_collections = ['only', 'these' 'collections']
|
9
|
+
db.additional_options = []
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
database MySQL do |db|
|
2
|
+
db.name = "my_database_name"
|
3
|
+
db.username = "my_username"
|
4
|
+
db.password = "my_password"
|
5
|
+
db.host = "localhost"
|
6
|
+
db.port = 3306
|
7
|
+
db.socket = "/tmp/mysql.sock"
|
8
|
+
db.skip_tables = ['skip', 'these', 'tables']
|
9
|
+
db.only_tables = ['only', 'these' 'tables']
|
10
|
+
db.additional_options = ['--quick', '--single-transaction']
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
database PostgreSQL do |db|
|
2
|
+
db.name = "my_database_name"
|
3
|
+
db.username = "my_username"
|
4
|
+
db.password = "my_password"
|
5
|
+
db.host = "localhost"
|
6
|
+
db.port = 5432
|
7
|
+
db.socket = "/tmp/pg.sock"
|
8
|
+
db.skip_tables = ['skip', 'these', 'tables']
|
9
|
+
db.only_tables = ['only', 'these' 'tables']
|
10
|
+
db.additional_options = ['--quick', '--single-transaction']
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
notify_by Mail do |mail|
|
2
|
+
mail.on_success = true
|
3
|
+
mail.on_failure = true
|
4
|
+
|
5
|
+
mail.from = 'sender@email.com'
|
6
|
+
mail.to = 'receiver@email.com'
|
7
|
+
mail.address = 'smtp.gmail.com'
|
8
|
+
mail.port = 587
|
9
|
+
mail.domain = 'your.host.name'
|
10
|
+
mail.user_name = 'sender@email.com'
|
11
|
+
mail.password = 'my_password'
|
12
|
+
mail.authentication = 'plain'
|
13
|
+
mail.enable_starttls_auto = true
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
##
|
2
|
+
# Backup
|
3
|
+
# Generated Template
|
4
|
+
#
|
5
|
+
# For more information:
|
6
|
+
#
|
7
|
+
# View the Git repository at https://github.com/meskyanichi/backup
|
8
|
+
# View the Wiki/Documentation at https://github.com/meskyanichi/backup/wiki
|
9
|
+
# View the issue log at https://github.com/meskyanichi/backup/issues
|
10
|
+
#
|
11
|
+
# When you're finished configuring this configuration file,
|
12
|
+
# you can run it from the command line by issuing the following command:
|
13
|
+
#
|
14
|
+
# $ backup -t my_backup [-c <path_to_configuration_file>]
|
15
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Archive do
|
6
|
+
|
7
|
+
let(:archive) do
|
8
|
+
Backup::Archive.new(:dummy_archive) do |a|
|
9
|
+
a.add '/home/rspecuser/somefile'
|
10
|
+
a.add '/home/rspecuser/logs/'
|
11
|
+
a.add '/home/rspecuser/dotfiles/'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have no paths' do
|
16
|
+
archive = Backup::Archive.new(:dummy_archive) { |a| }
|
17
|
+
archive.paths.count.should == 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have 3 paths' do
|
21
|
+
archive.paths.count.should == 3
|
22
|
+
end
|
23
|
+
|
24
|
+
it do
|
25
|
+
archive.name.should == :dummy_archive
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#paths_to_package' do
|
29
|
+
it 'should return a tar -c friendly string' do
|
30
|
+
archive.send(:paths_to_package).should ==
|
31
|
+
"'/home/rspecuser/somefile' '/home/rspecuser/logs/' '/home/rspecuser/dotfiles/'"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#perform!' do
|
36
|
+
before do
|
37
|
+
[:mkdir, :run, :utility].each { |method| archive.stubs(method) }
|
38
|
+
Backup::Logger.stubs(:message)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should tar all the specified paths' do
|
42
|
+
archive.expects(:mkdir).with(File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive'))
|
43
|
+
archive.expects(:run).with("tar -c '/home/rspecuser/somefile' '/home/rspecuser/logs/' '/home/rspecuser/dotfiles/' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
|
44
|
+
archive.expects(:utility).with(:tar).returns(:tar)
|
45
|
+
archive.perform!
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should log the status' do
|
49
|
+
Backup::Logger.expects(:message).with("Backup::Archive started packaging and archiving \"/home/rspecuser/somefile\", \"/home/rspecuser/logs/\", \"/home/rspecuser/dotfiles/\".")
|
50
|
+
archive.perform!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/backup_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
describe Backup do
|
6
|
+
it do
|
7
|
+
Backup::TMP_PATH.should == File.join(ENV['HOME'], 'Backup', '.tmp')
|
8
|
+
Backup::DATA_PATH.should == File.join(ENV['HOME'], 'Backup', 'data')
|
9
|
+
Backup::CONFIG_FILE.should == File.join(ENV['HOME'], 'Backup', 'config.rb')
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Compressor::Gzip do
|
6
|
+
let(:compressor) { Backup::Compressor::Gzip.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Backup::Model.extension = 'tar'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'the options' do
|
13
|
+
it do
|
14
|
+
compressor.send(:best).should == []
|
15
|
+
end
|
16
|
+
|
17
|
+
it do
|
18
|
+
compressor.send(:fast).should == []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#perform!' do
|
23
|
+
before do
|
24
|
+
[:run, :utility].each { |method| compressor.stubs(method) }
|
25
|
+
Backup::Logger.stubs(:message)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should perform the compression' do
|
29
|
+
compressor.expects(:utility).with(:gzip).returns(:gzip)
|
30
|
+
compressor.expects(:run).with("gzip '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
31
|
+
compressor.perform!
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should perform the compression with the --best and --fast options' do
|
35
|
+
compressor = Backup::Compressor::Gzip.new do |c|
|
36
|
+
c.best = true
|
37
|
+
c.fast = true
|
38
|
+
end
|
39
|
+
|
40
|
+
compressor.stubs(:utility).returns(:gzip)
|
41
|
+
compressor.expects(:run).with("gzip --best --fast '#{ File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar") }'")
|
42
|
+
compressor.perform!
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set the class variable @extension (Backup::Model.extension) to .gz' do
|
46
|
+
compressor.stubs(:utility).returns(:gzip)
|
47
|
+
compressor.expects(:run)
|
48
|
+
|
49
|
+
Backup::Model.extension.should == 'tar'
|
50
|
+
compressor.perform!
|
51
|
+
Backup::Model.extension.should == 'tar.gz'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should log' do
|
55
|
+
Backup::Logger.expects(:message).with("Backup::Compressor::Gzip started compressing the archive.")
|
56
|
+
compressor.perform!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|