Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for rsync Storage #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for rsync storage
Brian Cheldelin committed Sep 19, 2016
commit bf1123d93d4f13d462ebfe9363275416cd16090b
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -276,6 +276,22 @@ String. Bucket to store archive when using S3 storage type

String. Region to store archive when using S3 storage type

##### `rsync_mode`

String. rsync mode to use with rsync storage

##### `rsync_port`

Integer. Port for rsync storage model to use

Default: 22

##### `rsync_compress`

Boolean. Weather or not to enable rsync compression on transfer

Default: undef (false)

##### `encryptor`

String. Encryptor to use on backup archive
44 changes: 41 additions & 3 deletions manifests/job.pp
Original file line number Diff line number Diff line change
@@ -58,6 +58,10 @@
# FTP
$ftp_port = $::backup::ftp_port,
$ftp_passive_mode = $::backup::ftp_passive_mode,
# rsync
$rsync_mode = $::backup::rsync_mode,
$rsync_port = $::backup::rsync_port,
$rsync_compress = $::backup::rsync_compress,

## Encryptors
$encryptor = $::backup::encryptor,
@@ -173,8 +177,8 @@
}

# Storage
if !member(['s3', 'local', 'ftp'], $storage_type) {
fail("[Backup::Job::${name}]: Currently supported storage types are: ftp, local, and s3")
if !member(['s3', 'local', 'ftp', 'rsync'], $storage_type) {
fail("[Backup::Job::${name}]: Currently supported storage types are: ftp, local, s3, and rsync")
}

if $keep and !is_integer($keep) {
@@ -186,7 +190,7 @@
}

# local and ftp require path parameter
if member(['ftp', 'local'], $storage_type) {
if member(['ftp', 'local', 'rsync'], $storage_type) {
if !$path {
fail("[Backup::Job::${name}]: Path parameter is required with storage_type => ${storage_type}")
}
@@ -243,6 +247,27 @@
validate_bool($ftp_passive_mode)
}

if $storage_type == 'rsync' {
if $rsync_mode and !member([
'ssh',
'ssh_daemon',
'rsync_daemon',
], $rsync_mode ) {
fail("[Backup::Job::${name}]: ${rsync_mode} is not a valid mode")
}
if !$storage_host or !is_string($storage_host) {
fail("[Backup::Job::${name}]: Parameter storage_host is required for rsync storage")
}
if !$rsync_port or !is_integer($rsync_port) {
fail("[Backup::Job::${name}]: rsync_port must be an integer. (Got: ${rsync_port})")
}

if $rsync_compress {
validate_bool($rsync_compress)
}

}

# Encryptor
if $encryptor and !member(['openssl'], $encryptor) {
fail("[Backup::Job::${name}]: Supported encryptors are openssl")
@@ -479,6 +504,19 @@
content => template('backup/job/ftp.erb'),
order => '35',
}
} elsif $storage_type == 'rsync' {
# Template uses
# - $server_username
# - $server_ip
# - $server_port
# - $server_compress
# - $server_mode
# - $path
concat::fragment { "${_name}_rsync":
target => "/etc/backup/models/${_name}.rb",
content => template('backup/job/rsync.erb'),
order => '35',
}
}

if $logfile_enabled or $syslog_enabled or $console_quiet {
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -53,6 +53,10 @@
# FTP
$ftp_port = 21
$ftp_passive_mode = false
# rsync
$rsync_mode = undef
$rsync_port = 22
$rsync_compress = undef

## Encryptors
$encryptor = undef
96 changes: 96 additions & 0 deletions spec/defines/backup_job_spec.rb
Original file line number Diff line number Diff line change
@@ -346,6 +346,68 @@
end
end # ftp

context 'rsync' do
context 'bad mode' do
let(:params) { {
:types => 'archive',
:add => 'here',
:storage_type => 'rsync',
:storage_host => 'mysite.example.com',
:path => '/there',
:rsync_mode => 'abcde'
} }
it { expect { is_expected.to compile }.to raise_error(/abcde is not a valid mode/)}
end

context 'missing host' do
let(:params) { {
:types => 'archive',
:add => 'here',
:storage_type => 'rsync',
:storage_username => 'myuser',
:path => '/there',
} }
it { expect { is_expected.to compile }.to raise_error(/storage_host is required/)}
end

context 'missing path' do
let(:params) { {
:types => 'archive',
:add => 'here',
:storage_type => 'rsync',
:storage_username => 'myuser',
:storage_host => 'mysite.example.com',
} }
it { expect { is_expected.to compile }.to raise_error(/Path parameter is required/)}
end

context 'bad port' do
let(:params) { {
:types => 'archive',
:add => 'here',
:storage_type => 'rsync',
:storage_username => 'myuser',
:storage_host => 'mysite.example.com',
:rsync_port => 'abcde',
:path => '/there',
} }
it { expect { is_expected.to compile }.to raise_error(/rsync_port must be an integer/)}
end

context 'bad rsync_compress' do
let(:params) { {
:types => 'archive',
:add => 'here',
:storage_type => 'rsync',
:storage_username => 'myuser',
:storage_host => 'mysite.example.com',
:path => '/there',
:rsync_compress => 'bob',
} }
it { expect { is_expected.to compile }.to raise_error(/"bob" is not a boolean/)}
end
end # rsync

context 'encryptor generic' do
context 'bad encryptor' do
let(:params) { {
@@ -1014,6 +1076,40 @@
end
end # ftp

context 'rsync' do
context 'minimum settings' do
let(:params) { {
:types => 'archive',
:add => '/here',
:storage_type => 'rsync',
:storage_host => 'mysite.example.com',
:path => '/there',
} }
it { should_not contain_concat__fragment('job1_rsync').with(:content => /server\..+user/) }
it { should contain_concat__fragment('job1_rsync').with(:content => /server\.ip\s+=\s"mysite.example.com"/) }
it { should contain_concat__fragment('job1_rsync').with(:content => /server\.port\s+=\s22$/) }
it { should contain_concat__fragment('job1_rsync').with(:content => /server\.path\s+=\s"\/there"/) }
it { should_not contain_concat__fragment('job1_rsync').with(:content => /server\.rsync_compress/) }
end

context 'all params' do
let(:params) { {
:types => 'archive',
:add => '/here',
:storage_type => 'rsync',
:storage_username => 'myuser',
:storage_host => 'mysite.example.com',
:path => '/there',
:rsync_port => 22,
:rsync_mode => 'ssh',
:keep => 10,
} }
it { should contain_concat__fragment('job1_rsync').with(:content => /server\..+user\s+=\s"myuser"/) }
it { should contain_concat__fragment('job1_rsync').with(:content => /server\.port\s+=\s22/) }
it { should contain_concat__fragment('job1_rsync').with(:content => /server\.mode\s+=\s:ssh/) }
end
end # rsync

context 'logging' do
context 'no logging' do
let(:params) { {
21 changes: 21 additions & 0 deletions templates/job/rsync.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##
# rsync [Storage]
#
store_with RSync do |server|
<%if @storage_username and (@rsync_mode == 'ssh') -%>
server.ssh_user = "<%= @storage_username -%>"
<% elsif @storage_username -%>
server.rsync_user = "<%= @storage_username -%>"
<% end -%>
server.host = "<%= @storage_host -%>"
<%if @rsync_port -%>
server.port = <%= @rsync_port %>
<% end -%>
server.path = "<%= @_path -%>"
<% if @rsync_compress -%>
server.compress = "<%= @rsync_compress %>"
<% end -%>
<% if @rsync_mode -%>
server.mode = :<%= @rsync_mode %>
<% end -%>
end