mirror of
https://github.com/krislamo/puppet-rsnapshot
synced 2024-12-16 09:40:35 +00:00
working prototype (config generation)
This commit is contained in:
commit
234c5935a6
5
.fixtures.yml
Normal file
5
.fixtures.yml
Normal file
@ -0,0 +1,5 @@
|
||||
fixtures:
|
||||
repositories:
|
||||
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
|
||||
symlinks:
|
||||
"rsnapshot": "#{source_dir}"
|
19
.travis.yml
Normal file
19
.travis.yml
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
sudo: false
|
||||
language: ruby
|
||||
cache: bundler
|
||||
bundler_args: --without system_tests
|
||||
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- rvm: 1.8.7
|
||||
env: PUPPET_GEM_VERSION="~> 3.0"
|
||||
- rvm: 1.9.3
|
||||
env: PUPPET_GEM_VERSION="~> 3.0"
|
||||
- rvm: 2.0.0
|
||||
env: PUPPET_GEM_VERSION="~> 3.0"
|
||||
- rvm: 2.1.6
|
||||
env: PUPPET_GEM_VERSION="~> 4.0"
|
||||
notifications:
|
||||
email: false
|
135
CONTRIBUTING.md
Normal file
135
CONTRIBUTING.md
Normal file
@ -0,0 +1,135 @@
|
||||
Checklist (and a short version for the impatient)
|
||||
=================================================
|
||||
|
||||
* Commits:
|
||||
|
||||
- Make commits of logical units.
|
||||
|
||||
- Check for unnecessary whitespace with "git diff --check" before
|
||||
committing.
|
||||
|
||||
- Commit using Unix line endings (check the settings around "crlf" in
|
||||
git-config(1)).
|
||||
|
||||
- Do not check in commented out code or unneeded files.
|
||||
|
||||
- The first line of the commit message should be a short
|
||||
description (50 characters is the soft limit, excluding ticket
|
||||
number(s)), and should skip the full stop.
|
||||
|
||||
- Associate the issue in the message. The first line should include
|
||||
the issue number in the form "(#XXXX) Rest of message".
|
||||
|
||||
- The body should provide a meaningful commit message, which:
|
||||
|
||||
- uses the imperative, present tense: "change", not "changed" or
|
||||
"changes".
|
||||
|
||||
- includes motivation for the change, and contrasts its
|
||||
implementation with the previous behavior.
|
||||
|
||||
- Make sure that you have tests for the bug you are fixing, or
|
||||
feature you are adding.
|
||||
|
||||
- Make sure the test suites passes after your commit:
|
||||
`bundle exec rspec spec/acceptance` More information on [testing](#Testing) below
|
||||
|
||||
- When introducing a new feature, make sure it is properly
|
||||
documented in the README.md
|
||||
|
||||
* Submission:
|
||||
|
||||
* Pre-requisites:
|
||||
|
||||
- Make sure you have a [GitHub account](https://github.com/join)
|
||||
|
||||
* Preferred method:
|
||||
|
||||
- Fork the repository on GitHub.
|
||||
|
||||
- Push your changes to a topic branch in your fork of the
|
||||
repository. (the format ticket/1234-short_description_of_change is
|
||||
usually preferred for this project).
|
||||
|
||||
- Submit a pull request to the repository in the OpenConceptConsulting
|
||||
organization.
|
||||
|
||||
Testing
|
||||
=======
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
|
||||
Our puppet modules provide [`Gemfile`](./Gemfile)s which can tell a ruby
|
||||
package manager such as [bundler](http://bundler.io/) what Ruby packages,
|
||||
or Gems, are required to build, develop, and test this software.
|
||||
|
||||
Please make sure you have [bundler installed](http://bundler.io/#getting-started)
|
||||
on your system, then use it to install all dependencies needed for this project,
|
||||
by running
|
||||
|
||||
```shell
|
||||
% bundle install
|
||||
Fetching gem metadata from https://rubygems.org/........
|
||||
Fetching gem metadata from https://rubygems.org/..
|
||||
Using rake (10.1.0)
|
||||
Using builder (3.2.2)
|
||||
-- 8><-- many more --><8 --
|
||||
Using rspec-system-puppet (2.2.0)
|
||||
Using serverspec (0.6.3)
|
||||
Using rspec-system-serverspec (1.0.0)
|
||||
Using bundler (1.3.5)
|
||||
Your bundle is complete!
|
||||
Use `bundle show [gemname]` to see where a bundled gem is installed.
|
||||
```
|
||||
|
||||
NOTE some systems may require you to run this command with sudo.
|
||||
|
||||
If you already have those gems installed, make sure they are up-to-date:
|
||||
|
||||
```shell
|
||||
% bundle update
|
||||
```
|
||||
|
||||
With all dependencies in place and up-to-date we can now run the tests:
|
||||
|
||||
```shell
|
||||
% rake spec
|
||||
```
|
||||
|
||||
This will execute all the [rspec tests](http://rspec-puppet.com/) tests
|
||||
under [spec/defines](./spec/defines), [spec/classes](./spec/classes),
|
||||
and so on. rspec tests may have the same kind of dependencies as the
|
||||
module they are testing. While the module defines in its [Modulefile](./Modulefile),
|
||||
rspec tests define them in [.fixtures.yml](./fixtures.yml).
|
||||
|
||||
Some puppet modules also come with [beaker](https://github.com/puppetlabs/beaker)
|
||||
tests. These tests spin up a virtual machine under
|
||||
[VirtualBox](https://www.virtualbox.org/)) with, controlling it with
|
||||
[Vagrant](http://www.vagrantup.com/) to actually simulate scripted test
|
||||
scenarios. In order to run these, you will need both of those tools
|
||||
installed on your system.
|
||||
|
||||
You can run them by issuing the following command
|
||||
|
||||
```shell
|
||||
% rake spec_clean
|
||||
% rspec spec/acceptance
|
||||
```
|
||||
|
||||
This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml),
|
||||
install puppet, copy this module and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb)
|
||||
and then run all the tests under [spec/acceptance](./spec/acceptance).
|
||||
|
||||
Writing Tests
|
||||
-------------
|
||||
|
||||
XXX getting started writing tests.
|
||||
|
||||
Additional Resources
|
||||
====================
|
||||
|
||||
* [General GitHub documentation](http://help.github.com/)
|
||||
|
||||
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
||||
|
32
Gemfile
Normal file
32
Gemfile
Normal file
@ -0,0 +1,32 @@
|
||||
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
|
||||
|
||||
group :development, :unit_tests do
|
||||
gem 'rspec-core', '~> 3.1.7', :require => false
|
||||
gem 'rspec-puppet', '~> 2.1', :require => false
|
||||
gem 'puppetlabs_spec_helper', :require => false
|
||||
gem 'simplecov', :require => false
|
||||
gem 'puppet_facts', :require => false
|
||||
gem 'json', :require => false
|
||||
gem 'metadata-json-lint', :require => false
|
||||
gem 'puppet-lint', '< 1.1.0', :require => false
|
||||
end
|
||||
|
||||
group :system_tests do
|
||||
gem 'beaker-rspec', :require => false
|
||||
gem 'serverspec', :require => false
|
||||
gem 'beaker-puppet_install_helper', :require => false
|
||||
end
|
||||
|
||||
if facterversion = ENV['FACTER_GEM_VERSION']
|
||||
gem 'facter', facterversion, :require => false
|
||||
else
|
||||
gem 'facter', :require => false
|
||||
end
|
||||
|
||||
if puppetversion = ENV['PUPPET_GEM_VERSION']
|
||||
gem 'puppet', puppetversion, :require => false
|
||||
else
|
||||
gem 'puppet', :require => false
|
||||
end
|
||||
|
||||
# vim:ft=ruby
|
76
README.md
Normal file
76
README.md
Normal file
@ -0,0 +1,76 @@
|
||||
# rsnapshot
|
||||
|
||||
[![Build Status](https://travis-ci.org/OpenConceptConsulting/puppet-rsnapshot.svg?branch=master)](https://travis-ci.org/OpenConceptConsulting/puppet-rsnapshot)
|
||||
|
||||
#### Table of Contents
|
||||
|
||||
1. [Overview](#overview)
|
||||
2. [Module Description - What the module does and why it is useful](#module-description)
|
||||
3. [Setup - The basics of getting started with rsnapshot](#setup)
|
||||
* [What rsnapshot affects](#what-rsnapshot-affects)
|
||||
4. [Usage - Configuration options and additional functionality](#usage)
|
||||
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
|
||||
5. [Limitations - OS compatibility, etc.](#limitations)
|
||||
6. [Development - Guide for contributing to the module](#development)
|
||||
|
||||
## Overview
|
||||
|
||||
This puppet module manages rsnapshot configuration. It's a barebones module, as it doesn't deal with managing ssh keys or cron rules to trigger rsnapshot.
|
||||
|
||||
At the moment, this module has been tested with Puppet 3.x and Ubuntu 12.04, 14.04 and Debian 6. If you have another OS/Puppet version you want to include, please submit a pull request!
|
||||
|
||||
## Module Description
|
||||
|
||||
This module is a barebones rsnapshot installation and configuration system. It came into existing because we needed an rsnapshot module but didn't want to have it generate cron rules or setup ssh keys (rsnapshot only needs to generate local backups for us).
|
||||
|
||||
It is relatively trivial to then add a `cron` rule to trigger rsnapshot, and managing ssh keys can be done through `ssh_authorized_key`.
|
||||
|
||||
## Setup
|
||||
|
||||
### What rsnapshot affects
|
||||
|
||||
* `rsnapshot` package and its dependencies
|
||||
* `/etc/rsnapshot.conf` (by default)
|
||||
|
||||
## Usage
|
||||
|
||||
You only need to declare the rsnapshot class, and configure the parameters you need.
|
||||
The class will default to sane values for your OS if you don't override some parameters.
|
||||
|
||||
While you can include the class as is, it wont be useful unless you specify `backups` or `backup_scripts`.
|
||||
|
||||
## Reference
|
||||
|
||||
### backups
|
||||
A hash backup locations. The key is the source, the value is the destination.
|
||||
|
||||
```
|
||||
class { 'rsnapshot':
|
||||
backups => {
|
||||
'/home/' => 'localhost/',
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If you want the backup stanza to have overriden configuration options, add them to the destination, separated by a tab character:
|
||||
|
||||
```
|
||||
class { 'rsnapshot':
|
||||
backups => {
|
||||
'/home/' => 'localhost/ one_fs=1',
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### backup_scripts
|
||||
Exactly like [backups](#backups), except that they generate `backup_script` stanzas.
|
||||
|
||||
## Limitations
|
||||
|
||||
The module has been tested/used in production with Puppet 3.x.
|
||||
|
||||
On the OS side, the module currently only works on Debian-family OSes, but we'd love to get a patch to add support for more families/operating systems.
|
||||
|
||||
## Development
|
||||
|
||||
Development is happening on [github](https://github.com/OpenConceptConsulting/puppet-rsnapshot), and we welcome pull requests!
|
23
Rakefile
Normal file
23
Rakefile
Normal file
@ -0,0 +1,23 @@
|
||||
require 'puppetlabs_spec_helper/rake_tasks'
|
||||
require 'puppet-lint/tasks/puppet-lint'
|
||||
|
||||
PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
|
||||
PuppetLint.configuration.fail_on_warnings = true
|
||||
PuppetLint.configuration.send('relative')
|
||||
PuppetLint.configuration.send('disable_80chars')
|
||||
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
|
||||
PuppetLint.configuration.ignore_paths = ["vendor/**/*.pp", "spec/**/*.pp", "pkg/**/*.pp"]
|
||||
|
||||
desc "Validate manifests, templates, and ruby files"
|
||||
task :validate do
|
||||
Dir['manifests/**/*.pp'].each do |manifest|
|
||||
sh "puppet parser validate --noop #{manifest}"
|
||||
end
|
||||
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
|
||||
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
|
||||
end
|
||||
Dir['templates/**/*.erb'].each do |template|
|
||||
sh "erb -P -x -T '-' #{template} | ruby -c"
|
||||
end
|
||||
end
|
||||
|
15
lib/puppet/parser/functions/pick_undef.rb
Normal file
15
lib/puppet/parser/functions/pick_undef.rb
Normal file
@ -0,0 +1,15 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:pick_undef, :type => :rvalue, :doc => <<-EOS
|
||||
This function is similar to pick_default, but will return or undefined values.
|
||||
EOS
|
||||
) do |args|
|
||||
fail "Must receive at least one argument." if args.empty?
|
||||
default = args.last
|
||||
args = args[0..-2].compact
|
||||
# args.delete(:undef)
|
||||
# args.delete(:undefined)
|
||||
# args.delete("")
|
||||
args << default
|
||||
return args[0]
|
||||
end
|
||||
end
|
87
manifests/config.pp
Normal file
87
manifests/config.pp
Normal file
@ -0,0 +1,87 @@
|
||||
# == Class: rsnapshot::config
|
||||
#
|
||||
# manage host configs
|
||||
class rsnapshot::config (
|
||||
$hosts = $rsnapshot::hosts,
|
||||
) {
|
||||
# these are global settings, no point in setting them per host
|
||||
$config_version = $rsnapshot::params::config_version
|
||||
$lockpath = pick($rsnapshot::lockpath, $rsnapshot::params::config_lockpath)
|
||||
$conf_d = pick($rsnapshot::conf_d, $rsnapshot::params::conf_d)
|
||||
# make sure lock path and conf path exist
|
||||
file { $conf_d:
|
||||
ensure => 'directory',
|
||||
}
|
||||
file { $lockpath:
|
||||
ensure => 'directory',
|
||||
}
|
||||
|
||||
$hosts.each |String $host, Hash $hash | {
|
||||
$snapshot_root = pick($hash['snapshot_root'], $rsnapshot::params::config_snapshot_root)
|
||||
$backups = pick($hash['backups'], $rsnapshot::params::config_backups)
|
||||
$backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user)
|
||||
$cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp)
|
||||
$cmd_rm = pick($hash['cmd_rm'], $rsnapshot::params::config_cmd_rm)
|
||||
$cmd_rsync = pick($hash['cmd_rsync'], $rsnapshot::params::config_cmd_rsync)
|
||||
$cmd_ssh = pick($hash['cmd_ssh'], $rsnapshot::params::config_cmd_ssh)
|
||||
$cmd_logger = pick($hash['cmd_logger'], $rsnapshot::params::config_cmd_logger)
|
||||
$cmd_du = pick($hash['cmd_du'], $rsnapshot::params::config_cmd_du)
|
||||
$cmd_rsnapshot_diff = pick_undef($hash['cmd_rsnapshot_diff'], $rsnapshot::params::config_cmd_rsnapshot_diff)
|
||||
$cmd_preexec = pick_undef($hash['cmd_preexec'], $rsnapshot::params::config_cmd_preexec)
|
||||
$cmd_postexec = pick_undef($hash['cmd_postexec'], $rsnapshot::params::config_cmd_postexec)
|
||||
$use_lvm = pick_undef($hash['use_lvm'], $rsnapshot::params::config_use_lvm)
|
||||
$linux_lvm_cmd_lvcreate = pick_undef($hash['linux_lvm_cmd_lvcreate'], $rsnapshot::params::config_linux_lvm_cmd_lvcreate)
|
||||
$linux_lvm_cmd_lvremove = pick_undef($hash['linux_lvm_cmd_lvremove'], $rsnapshot::params::config_linux_lvm_cmd_lvremove)
|
||||
$linux_lvm_cmd_mount = pick_undef($hash['linux_lvm_cmd_mount'], $rsnapshot::params::config_linux_lvm_cmd_mount)
|
||||
$linux_lvm_cmd_umount = pick_undef($hash['linux_lvm_cmd_umount'], $rsnapshot::params::config_linux_lvm_cmd_umount)
|
||||
$linux_lvm_snapshotsize = pick_undef($hash['linux_lvm_snapshotsize'], $rsnapshot::params::config_linux_lvm_snapshotsize)
|
||||
$linux_lvm_snapshotname = pick_undef($hash['linux_lvm_snapshotname'], $rsnapshot::params::config_linux_lvm_snapshotname)
|
||||
$linux_lvm_vgpath = pick_undef($hash['linux_lvm_vgpath'], $rsnapshot::params::config_linux_lvm_vgpath)
|
||||
$linux_lvm_mountpath = pick_undef($hash['linux_lvm_mountpath'], $rsnapshot::params::config_linux_lvm_mountpath)
|
||||
$no_create_root = pick_undef($hash['no_create_root'], $rsnapshot::params::config_no_create_root)
|
||||
notice("no_create_root for $host is $no_create_root ")
|
||||
$lockfile = "${lockpath}/${host}.pid"
|
||||
$logpath = pick($hash['logpath'], $rsnapshot::logpath, $rsnapshot::params::config_logpath)
|
||||
$logfile = "${logpath}/${host}.log"
|
||||
$verbose = pick($hash['verbose'], $rsnapshot::params::config_verbose)
|
||||
$loglevel = pick($hash['loglevel'], $rsnapshot::params::config_loglevel)
|
||||
$stop_on_stale_lockfile = pick_undef($hash['stop_on_stale_lockfile'], $rsnapshot::params::config_stop_on_stale_lockfile)
|
||||
$rsync_short_args = pick($hash['rsync_short_args'], $rsnapshot::params::config_rsync_short_args)
|
||||
$rsync_long_args = pick_undef($hash['rsync_long_args'], $rsnapshot::params::config_rsync_long_args)
|
||||
$ssh_args = pick_undef($hash['ssh_args'], $rsnapshot::params::config_ssh_args)
|
||||
$du_args = pick_undef($hash['du_args'], $rsnapshot::params::config_du_args)
|
||||
$one_fs = pick_undef($hash['one_fs'], $rsnapshot::params::config_one_fs)
|
||||
# one of both interval or retain must be present
|
||||
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
||||
$retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain)
|
||||
notice("interval for $host is $interval ")
|
||||
if ! ($interval and $retain ) {
|
||||
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
||||
}
|
||||
$include = pick_undef($hash['include'], $rsnapshot::params::config_include)
|
||||
$exclude = pick_undef($hash['exclude'], $rsnapshot::params::config_exclude)
|
||||
$include_file = pick_undef($hash['include_file'], $rsnapshot::params::config_include_file)
|
||||
$exclude_file = pick($hash['exclude_file'], $rsnapshot::params::config_exclude_file, "${conf_d}/${host}.exclude")
|
||||
$link_dest = pick_undef($hash['link_dest'], $rsnapshot::params::config_link_dest)
|
||||
if $link_dest { $link_dest_num = bool2num($link_dest) }
|
||||
$sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first)
|
||||
if $sync_first { $sync_first_num = bool2num($sync_first) }
|
||||
$rsync_numtries = pick_undef($hash['rsync_numtries'], $rsnapshot::params::config_rsync_numtries)
|
||||
$use_lazy_deletes = pick_undef($hash['use_lazy_deletes'], $rsnapshot::params::config_use_lazy_deletes)
|
||||
if $use_lazy_deletes { $use_lazy_deletes_num = bool2num($use_lazy_deletes) }
|
||||
$backup_scripts = pick_undef($hash['backup_scripts'], $rsnapshot::params::config_backup_scripts)
|
||||
|
||||
$snapshot_dir = "${config_snapshot_root}/${host}"
|
||||
$config = "${conf_d}/${host}.rsnapshot.conf"
|
||||
|
||||
|
||||
file { $config:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => template('rsnapshot/rsnapshot.erb')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
manifests/init.pp
Normal file
23
manifests/init.pp
Normal file
@ -0,0 +1,23 @@
|
||||
# == Class: rsnapshot
|
||||
#
|
||||
# Manages rsnapshot.
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
class rsnapshot (
|
||||
$hosts = $rsnapshot::params::hosts,
|
||||
$conf_d = $rsnapshot::params::conf_d,
|
||||
$logpath = $rsnapshot::params::config_logpath,
|
||||
$lockpath = $rsnapshot::params::config_lockpath,
|
||||
) inherits rsnapshot::params {
|
||||
|
||||
# anchor { 'rsnapshot::begin': } ->
|
||||
#class { 'rsnapshot::install': } ->
|
||||
#class { 'rsnapshot::config': } ->
|
||||
#anchor { 'rsnapshot::end': }
|
||||
if $hosts {
|
||||
class { 'rsnapshot::config': }
|
||||
contain 'rsnapshot::config'
|
||||
}
|
||||
}
|
||||
|
11
manifests/install.pp
Normal file
11
manifests/install.pp
Normal file
@ -0,0 +1,11 @@
|
||||
# == Class: rsnapshot::install
|
||||
#
|
||||
# Installs the rsnapshot package.
|
||||
class rsnapshot::install inherits rsnapshot {
|
||||
|
||||
package { $rsnapshot::package_name:
|
||||
ensure => $rsnapshot::package_ensure,
|
||||
}
|
||||
|
||||
}
|
||||
|
63
manifests/params.pp
Normal file
63
manifests/params.pp
Normal file
@ -0,0 +1,63 @@
|
||||
# == Class: rsnapshot
|
||||
#
|
||||
# default params
|
||||
class rsnapshot::params {
|
||||
$hosts = undef
|
||||
$conf_d = '/tmp/rsnapshot.d' # the place where the host specific configs are stored
|
||||
$config_backup_user = 'root'
|
||||
$package_name = 'rsnapshot'
|
||||
$package_ensure = 'present'
|
||||
$config_version = '1.2'
|
||||
$config_cmd_cp = '/bin/cp'
|
||||
$config_cmd_rm = '/bin/rm'
|
||||
$config_cmd_rsync = '/usr/bin/rsync'
|
||||
$config_cmd_ssh = '/usr/bin/ssh'
|
||||
$config_cmd_logger = '/usr/bin/logger'
|
||||
$config_cmd_du = '/usr/bin/du'
|
||||
$config_cmd_rsnapshot_diff = '/usr/bin/rsnapshot-diff'
|
||||
$config_cmd_preexec = undef
|
||||
$config_cmd_postexec = undef
|
||||
$config_use_lvm = undef
|
||||
$config_linux_lvm_cmd_lvcreate = undef # '/sbin/lvcreate'
|
||||
$config_linux_lvm_cmd_lvremove = undef # '/sbin/lvremove'
|
||||
$config_linux_lvm_cmd_mount = undef # '/sbin/mount'
|
||||
$config_linux_lvm_cmd_umount = undef # '/sbin/umount'
|
||||
$config_linux_lvm_snapshotsize = undef # '100M'
|
||||
$config_linux_lvm_snapshotname = undef # 'rsnapshot'
|
||||
$config_linux_lvm_vgpath = undef # '/dev'
|
||||
$config_linux_lvm_mountpath = undef # '/mount/rsnapshot'
|
||||
$config_logpath = '/var/log/rsnapshot'
|
||||
$config_logfile = '/var/log/rsnapshot.log' # unused, we are logging to $logpath/$host.log
|
||||
$config_lockpath = '/var/run/rsnapshot'
|
||||
$config_snapshot_root = '/backup/'
|
||||
$config_no_create_root = undef # bool, true or false
|
||||
$config_verbose = '2'
|
||||
$config_loglevel = '4'
|
||||
$config_stop_on_stale_lockfile = undef # bool
|
||||
$config_rsync_short_args = '-az'
|
||||
$config_rsync_long_args = undef # defaults are --delete --numeric-ids --relative --delete-excluded
|
||||
$config_ssh_args = undef
|
||||
$config_du_args = undef
|
||||
$config_one_fs = undef
|
||||
$config_retain = { }
|
||||
$config_interval = {
|
||||
'daily' => '7',
|
||||
'weekly' => '4',
|
||||
'monthly' => '6',
|
||||
}
|
||||
$config_include = []
|
||||
$config_exclude = []
|
||||
$config_include_file = undef
|
||||
$config_exclude_file = undef
|
||||
$config_link_dest = false
|
||||
$config_sync_first = false
|
||||
$config_rsync_numtries = 1
|
||||
$config_use_lazy_deletes = false
|
||||
$config_backups = {
|
||||
'/etc' => './',
|
||||
'/home' => './',
|
||||
}
|
||||
$config_backup_scripts = {}
|
||||
|
||||
}
|
||||
|
22
metadata.json
Normal file
22
metadata.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "loomsen-rsnapshot",
|
||||
"version": "0.1.0",
|
||||
"author": "loomsen",
|
||||
"summary": "Configures rsnapshot.",
|
||||
"license": "Apache-2.0",
|
||||
"source": "https://github.com/loomsen/puppet-rsnapshot",
|
||||
"project_page": "https://github.com/loomsen/puppet-rsnapshot",
|
||||
"issues_url": "https://github.com/loomsen/puppet-rsnapshot/issues",
|
||||
"tags": [
|
||||
"rsnapshot",
|
||||
"backup",
|
||||
],
|
||||
"requirements": [
|
||||
{ "name": "pe", "version_requirement": ">= 3.0.0" },
|
||||
{ "name": "puppet", "version_requirement": ">= 3.0.0" }
|
||||
],
|
||||
"dependencies": [
|
||||
{ "name": "puppetlabs-stdlib","version_range": ">= 1.0.0"
|
||||
}
|
||||
]
|
||||
}
|
12
spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml
Normal file
12
spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml
Normal file
@ -0,0 +1,12 @@
|
||||
HOSTS:
|
||||
ubuntu-1204-x64:
|
||||
default_apply_opts:
|
||||
strict_variables:
|
||||
platform: ubuntu-12.04-amd64
|
||||
hypervisor : docker
|
||||
image: ubuntu:12.04
|
||||
# This stops the image from being deleted on completion, speeding up the process.
|
||||
docker_preserve_image: true
|
||||
CONFIG:
|
||||
type: foss
|
||||
log_level: debug
|
10
spec/acceptance/nodesets/ubuntu-12.04-x86_64-vagrant.yml
Normal file
10
spec/acceptance/nodesets/ubuntu-12.04-x86_64-vagrant.yml
Normal file
@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
ubuntu-1204-x64:
|
||||
default_apply_opts:
|
||||
strict_variables:
|
||||
platform: ubuntu-12.04-amd64
|
||||
hypervisor : vagrant
|
||||
box : puppetlabs/ubuntu-12.04-64-nocm
|
||||
CONFIG:
|
||||
type: foss
|
||||
log_level: debug
|
12
spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml
Normal file
12
spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml
Normal file
@ -0,0 +1,12 @@
|
||||
HOSTS:
|
||||
ubuntu-1404-x64:
|
||||
default_apply_opts:
|
||||
strict_variables:
|
||||
platform: ubuntu-14.04-amd64
|
||||
hypervisor : docker
|
||||
image: ubuntu:14.04
|
||||
# This stops the image from being deleted on completion, speeding up the process.
|
||||
docker_preserve_image: true
|
||||
CONFIG:
|
||||
type: foss
|
||||
log_level: debug
|
10
spec/acceptance/nodesets/ubuntu-14.04-x86_64-vagrant.yml
Normal file
10
spec/acceptance/nodesets/ubuntu-14.04-x86_64-vagrant.yml
Normal file
@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
ubuntu-1404-x64:
|
||||
default_apply_opts:
|
||||
strict_variables:
|
||||
platform: ubuntu-14.04-amd64
|
||||
hypervisor : vagrant
|
||||
box : puppetlabs/ubuntu-14.04-64-nocm
|
||||
CONFIG:
|
||||
type: foss
|
||||
log_level: debug
|
37
spec/classes/init_spec.rb
Normal file
37
spec/classes/init_spec.rb
Normal file
@ -0,0 +1,37 @@
|
||||
require 'spec_helper'
|
||||
describe 'rsnapshot' do
|
||||
|
||||
{'Ubuntu' => 'Debian', 'Debian' => 'Debian'}.each do |system, family|
|
||||
context "when on system #{system} no lvm" do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => family,
|
||||
:operatingsystem => system,
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_class('rsnapshot') }
|
||||
it { should contain_class('rsnapshot::install') }
|
||||
it { should contain_class('rsnapshot::config') }
|
||||
end
|
||||
|
||||
context "when on system #{system} with lvm" do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => family,
|
||||
:operatingsystem => system,
|
||||
}
|
||||
end
|
||||
|
||||
let(:params) { {:use_lvm => true} }
|
||||
|
||||
it { should contain_class('rsnapshot') }
|
||||
it { should contain_class('rsnapshot::install') }
|
||||
it { should contain_class('rsnapshot::config') }
|
||||
|
||||
it {
|
||||
should contain_file('/etc/rsnapshot.conf').with_content(/^linux_lvm_((\w|_)+)\t(.*)$/)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
6
spec/spec.opts
Normal file
6
spec/spec.opts
Normal file
@ -0,0 +1,6 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
29
spec/spec_helper.rb
Normal file
29
spec/spec_helper.rb
Normal file
@ -0,0 +1,29 @@
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.include PuppetlabsSpec::Files
|
||||
|
||||
c.before :each do
|
||||
# Ensure that we don't accidentally cache facts and environment
|
||||
# between test cases.
|
||||
Facter::Util::Loader.any_instance.stubs(:load_all)
|
||||
Facter.clear
|
||||
Facter.clear_messages
|
||||
|
||||
# Store any environment variables away to be restored later
|
||||
@old_env = {}
|
||||
ENV.each_key {|k| @old_env[k] = ENV[k]}
|
||||
|
||||
if Gem::Version.new(`puppet --version`) >= Gem::Version.new('3.5')
|
||||
Puppet.settings[:strict_variables]=true
|
||||
end
|
||||
if ENV['PARSER']
|
||||
Puppet.settings[:parser]=ENV['PARSER']
|
||||
end
|
||||
end
|
||||
|
||||
c.after :each do
|
||||
PuppetlabsSpec::Files.cleanup
|
||||
end
|
||||
end
|
||||
|
142
templates/rsnapshot.erb
Normal file
142
templates/rsnapshot.erb
Normal file
@ -0,0 +1,142 @@
|
||||
# This file is being managed by puppet
|
||||
# Module 'rsnaphost'
|
||||
|
||||
config_version <%= @config_version %>
|
||||
snapshot_root <%= @snapshot_root %>
|
||||
<% if @no_create_root != '' -%>
|
||||
no_create_root <%= @no_create_root %>
|
||||
<% end -%>
|
||||
cmd_rsync <%= @cmd_rsync %>
|
||||
<% if @cmd_cp != '' -%>
|
||||
cmd_cp <%= @cmd_cp %>
|
||||
<% end -%>
|
||||
<% if @cmd_rm != '' -%>
|
||||
cmd_rm <%= @cmd_rm %>
|
||||
<% end -%>
|
||||
<% if @cmd_ssh != '' -%>
|
||||
cmd_ssh <%= @cmd_ssh %>
|
||||
<% end -%>
|
||||
<% if @cmd_logger != '' -%>
|
||||
cmd_logger <%= @cmd_logger %>
|
||||
<% end -%>
|
||||
<% if @cmd_du != '' -%>
|
||||
cmd_du <%= @cmd_du %>
|
||||
<% end -%>
|
||||
<% if @cmd_rsnapshot_diff != '' -%>
|
||||
cmd_rsnapshot_diff <%= @cmd_rsnapshot_diff %>
|
||||
<% end -%>
|
||||
<% if @cmd_preexec != '' -%>
|
||||
cmd_preexec <%= @cmd_preexec %>
|
||||
<% end -%>
|
||||
<% if @cmd_postexec != '' -%>
|
||||
cmd_postexec <%= @cmd_postexec %>
|
||||
<% end -%>
|
||||
<% if @use_lvm != '' -%>
|
||||
<% if @linux_lvm_cmd_lvcreate -%>
|
||||
linux_lvm_cmd_lvcreate <%= @linux_lvm_cmd_lvcreate %>
|
||||
<% end -%>
|
||||
<% if @linux_lvm_cmd_lvremove != '' -%>
|
||||
linux_lvm_cmd_lvremove <%= @linux_lvm_cmd_lvremove %>
|
||||
<% end -%>
|
||||
<% if @linux_lvm_cmd_mount != '' -%>
|
||||
linux_lvm_cmd_mount <%= @linux_lvm_cmd_mount %>
|
||||
<% end -%>
|
||||
<% if @linux_lvm_cmd_umount != '' -%>
|
||||
linux_lvm_cmd_umount <%= @linux_lvm_cmd_umount %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
#########################################
|
||||
# BACKUP INTERVALS #
|
||||
# Must be unique and in ascending order #
|
||||
# i.e. hourly, daily, weekly, etc. #
|
||||
#########################################
|
||||
<%if @interval != '' -%>
|
||||
<% @interval.each_pair do |name, time| -%>
|
||||
interval <%= name %> <%= time %>
|
||||
<% end -%>
|
||||
<% else %>
|
||||
<% @retain.each_pair do |name, time| -%>
|
||||
retain <%= name %> <%= time %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
verbose <%= @verbose %>
|
||||
loglevel <%= @loglevel %>
|
||||
<% if @logfile != '' -%>
|
||||
logfile <%= @logfile %>
|
||||
<% end -%>
|
||||
<% if @lockfile != '' -%>
|
||||
lockfile <%= @lockfile %>
|
||||
<% end -%>
|
||||
<% if @stop_on_stale_lockfile != '' -%>
|
||||
stop_on_stale_lockfile <%= @stop_on_stale_lockfile %>
|
||||
<%end-%>
|
||||
<% if @rsync_short_args != '' -%>
|
||||
rsync_short_args <%= @rsync_short_args %>
|
||||
<% end -%>
|
||||
<% if @rsync_long_args != '' -%>
|
||||
rsync_long_args <%= @rsync_long_args %>
|
||||
<% end -%>
|
||||
<% if @ssh_args != '' -%>
|
||||
ssh_args <%= @ssh_args %>
|
||||
<% end -%>
|
||||
<% if @du_args != '' -%>
|
||||
du_args <%= @du_args %>
|
||||
<% end -%>
|
||||
<% if @one_fs != '' %>
|
||||
one_fs <%= @one_fs_num %>
|
||||
<% end -%>
|
||||
<% if @include != '' %>
|
||||
<% @include.each do |pattern| -%>
|
||||
include <%= pattern %>
|
||||
<% end -%>
|
||||
<%end-%>
|
||||
<% if @exclude != '' %>
|
||||
<% @exclude.each do |pattern| -%>
|
||||
exclude <%= pattern %>
|
||||
<% end -%>
|
||||
<%end-%>
|
||||
<% if @include_file != '' -%>
|
||||
include_file <%= @include_file %>
|
||||
<% end -%>
|
||||
<% if @exclude_file != '' -%>
|
||||
exclude_file <%= @exclude_file %>
|
||||
<% end -%>
|
||||
<% if @link_dest != '' -%>
|
||||
link_dest <%= @link_dest_num %>
|
||||
<% end -%>
|
||||
<% if @sync_first != '' -%>
|
||||
sync_first <%= @sync_first_num %>
|
||||
<% end -%>
|
||||
<% if @use_lazy_deletes != '' -%>
|
||||
use_lazy_deletes <%= @use_lazy_deletes_num %>
|
||||
<% end -%>
|
||||
<% if @rsync_numtries != '' -%>
|
||||
rsync_numtries <%= @rsync_numtries %>
|
||||
<% end -%>
|
||||
<% if @use_lvm != '' -%>
|
||||
<% if @linux_lvm_snapshotsize -%>
|
||||
linux_lvm_snapshotsize <%= @linux_lvm_snapshotsize %>
|
||||
<% end -%>
|
||||
<% if @linux_lvm_snapshotname != '' -%>
|
||||
linux_lvm_snapshotname <%= @linux_lvm_snapshotname %>
|
||||
<% end -%>
|
||||
<% if @linux_lvm_vgpath != '' -%>
|
||||
linux_lvm_vgpath <%= @linux_lvm_vgpath %>
|
||||
<% end -%>
|
||||
<% if @linux_lvm_mountpath != '' -%>
|
||||
linux_lvm_mountpath <%= @linux_lvm_mountpath %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% @backups.each_pair do |source, dest| -%>
|
||||
<% if @backup_user != '' -%>
|
||||
backup <%= @backup_user %>@<%=@host%>:<%= source %> <%=dest%>
|
||||
<% else -%>
|
||||
backup <%=@host%>:<%= source %> <%=dest%>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% if @backup_scripts != '' -%>
|
||||
<% @backup_scripts.each_pair do |source, dest| -%>
|
||||
backup_script <%= source %> <%= dest %>
|
||||
<% end -%>
|
||||
<%end-%>
|
||||
|
12
tests/init.pp
Normal file
12
tests/init.pp
Normal file
@ -0,0 +1,12 @@
|
||||
# The baseline for module testing used by Puppet Labs is that each manifest
|
||||
# should have a corresponding test manifest that declares that class or defined
|
||||
# type.
|
||||
#
|
||||
# Tests are then run by using puppet apply --noop (to check for compilation
|
||||
# errors and view a log of events) or by fully applying the test in a virtual
|
||||
# environment (to compare the resulting system state to the desired state).
|
||||
#
|
||||
# Learn more about module testing here:
|
||||
# http://docs.puppetlabs.com/guides/tests_smoke.html
|
||||
#
|
||||
include rsnapshot
|
Loading…
Reference in New Issue
Block a user