mirror of
https://github.com/krislamo/puppet-rsnapshot
synced 2024-12-16 09:40:35 +00:00
remove unnecessary file
This commit is contained in:
parent
3c5794c13b
commit
b06a4732b5
1
Gemfile
1
Gemfile
@ -29,4 +29,5 @@ else
|
||||
gem 'puppet', :require => false
|
||||
end
|
||||
|
||||
gem 'puppet', "3.8"
|
||||
# vim:ft=ruby
|
||||
|
BIN
pkg/loomsen-rsnapshot-0.1.0.tar.gz
Normal file
BIN
pkg/loomsen-rsnapshot-0.1.0.tar.gz
Normal file
Binary file not shown.
135
pkg/loomsen-rsnapshot-0.1.0/CONTRIBUTING.md
Normal file
135
pkg/loomsen-rsnapshot-0.1.0/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
pkg/loomsen-rsnapshot-0.1.0/Gemfile
Normal file
32
pkg/loomsen-rsnapshot-0.1.0/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
|
276
pkg/loomsen-rsnapshot-0.1.0/README.md
Normal file
276
pkg/loomsen-rsnapshot-0.1.0/README.md
Normal file
@ -0,0 +1,276 @@
|
||||
# rsnapshot
|
||||
|
||||
#### Table of Contents
|
||||
|
||||
1. [Overview](#overview)
|
||||
2. [Module Description - What the module does and why it is useful](#module-description)
|
||||
* [Notes](#notes)
|
||||
3. [Setup - The basics of getting started with rsnapshot](#setup)
|
||||
* [What rsnapshot affects](#what-rsnapshot-affects)
|
||||
* [Setup requirements](#setup-requirements)
|
||||
* [Getting started with rsnapshot](#getting-started)
|
||||
4. [Configuration - options and additional functionality](#configuration)
|
||||
* [Examples](#examples)
|
||||
* [More Options](#more-options)
|
||||
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)
|
||||
7. [Editors](#editors)
|
||||
8. [Contributors](#contributors)
|
||||
|
||||
## Overview
|
||||
|
||||
The rsnapshot module installs, configures and manages rsnapshot on a dedicated backup server.
|
||||
|
||||
## Module Description
|
||||
The rsnapshot module installs, configures and manages rsnapshot on a dedicated backup server. It allows to set up a centralized Backup Server for all your nodes.
|
||||
For the cron setup, the module will pick random time entries for the crons from an Array or a Range of time. For how to configure this, [please see below](#more-options)
|
||||
|
||||
### Notes
|
||||
This module is best used with an ENC like hiera. It will make your config much easier to read and to maintain. Check the examples to see what I mean.
|
||||
|
||||
## Setup
|
||||
|
||||
### What rsnapshot affects
|
||||
|
||||
* This module will install the rsnapshot package on your system
|
||||
* This module will manage the rsnapshot config on your system
|
||||
* This module will manage cron entries for your configured nodes
|
||||
|
||||
### Setup Requirements
|
||||
|
||||
On CentOS Systems this module requires the stahnma-epel module. Also you will need to have rsync installed on all nodes to be backed up.
|
||||
It will create repeatable random cron entries from a configurable timerange for all hosts.
|
||||
|
||||
### Getting Started
|
||||
|
||||
You will need to pass the nodenames to be backed up at least.
|
||||
This will pickup all defaults and add localhost to the backups:
|
||||
|
||||
|
||||
```puppet
|
||||
class { '::rsnapshot':
|
||||
hosts => {
|
||||
'localhost' => {},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
Here are some more elaborate examples of what you can do with this module.
|
||||
|
||||
### Examples
|
||||
This will backup localhost with defaults. It will disable the default backup locations for example.com
|
||||
and just backup '/var' for example.com.
|
||||
```puppet
|
||||
class { '::rsnapshot':
|
||||
hosts => {
|
||||
'localhost' => {},
|
||||
'example.com' => {
|
||||
backup_defaults => false,
|
||||
backup => {
|
||||
'/var/' => './'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
The same in hiera:
|
||||
```yaml
|
||||
---
|
||||
classes: rsnapshot
|
||||
rsnapshot::hosts:
|
||||
localhost:
|
||||
example.com:
|
||||
backup_defaults: false
|
||||
backup:
|
||||
'/var/': './'
|
||||
```
|
||||
|
||||
|
||||
|
||||
A more complete hiera example:
|
||||
```yaml
|
||||
---
|
||||
classes:
|
||||
- rsnapshot
|
||||
|
||||
# override default backup dirs for all hosts:
|
||||
rsnapshot::default_backup:
|
||||
'/etc': './'
|
||||
'/usr/local': './'
|
||||
'/home': './'
|
||||
|
||||
# configure hosts to be backed up
|
||||
rsnapshot::hosts:
|
||||
# pick all defaults for localhost
|
||||
localhost:
|
||||
# add futher backups for node foo.example.com (additional to default_backup) and use a different snapshot root
|
||||
foo.example.com:
|
||||
backup:
|
||||
'/foo': './'
|
||||
'/bar': './'
|
||||
'/baz': './misc'
|
||||
snapshot_root: '/tmp/rsnapshot'
|
||||
# all defaults
|
||||
foo1.example.com:
|
||||
foo2:
|
||||
# disable default backup dirs and just backup /var for node bar1
|
||||
# also set the minute to 0-10 for daily cron (note: this is not particularly useful, it's just meant to document the features)
|
||||
# lastly set the range of hours to pick a random hour from (the cron for bar1 will have hour set to something between 1 and 5)
|
||||
bar1:
|
||||
backup_defaults: false
|
||||
backup:
|
||||
'/var': './var'
|
||||
cron:
|
||||
'daily':
|
||||
'minute': '0-10'
|
||||
'hour': '1..5'
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
### More options
|
||||
The defaults are pretty reasonable, I hope. However, you may override pretty much anything. Available parameters are discussed below.
|
||||
|
||||
#### Specials
|
||||
As mentioned, this module will generate random time entries for your hosts. The random number generator is hashed with hostname and backup_level, so the randomness will be repeatable per host.level. This is important so puppet won't override the crons with each run.
|
||||
You may specify time ranges as follows:
|
||||
* default cron syntax (1-10, '*/5', 5)
|
||||
* an array with allowed values, for example, if you want the backup for a host to run between 1am and 5am, you would override the hours setting for the host in question.
|
||||
in hiera this would look like: (Explanation see below)
|
||||
```yaml
|
||||
rsnapshot::hosts:
|
||||
example.com:
|
||||
cron:
|
||||
'daily':
|
||||
'minute': '1'
|
||||
'hour': '1..5'
|
||||
```
|
||||
This will create the rsnapshot config using defaults from params.pp, but set the minute of the daily backup to '1' and the hour to something random between 1 and 5.
|
||||
So it would look something like:
|
||||
```
|
||||
1 4 * * * foo daily
|
||||
```
|
||||
or maybe
|
||||
```
|
||||
1 2 * * * foo daily
|
||||
```
|
||||
## Reference
|
||||
|
||||
### Classes
|
||||
|
||||
#### Public Classes
|
||||
* rsnapshot: Main class, includes all other classes.
|
||||
|
||||
####Private Classes
|
||||
|
||||
* rsnapshot::install: Handles the packages.
|
||||
* rsnapshot::config: Handles configuration and cron files.
|
||||
* rsnapshot::params: default values.
|
||||
|
||||
### Functions
|
||||
####`assert_empty_hash`
|
||||
Sets an empty value to a hash (we need this so a loop doesn't break if just a hostname is given to pick up all defaults.
|
||||
|
||||
####`pick_undef`
|
||||
Like pick but returns undef values.
|
||||
|
||||
####`rand_from_array`
|
||||
Takes an Integer, a String or an Array as input, and returns a random entry from the array (or just the String/Integer)
|
||||
|
||||
### Parameters
|
||||
|
||||
The following parameters are available in the `::rsnapshot` class:
|
||||
|
||||
####`$hosts`
|
||||
Hash containing the hosts to be backed up and optional overrides per host
|
||||
####`$conf_d`
|
||||
The place where the configs will be dropped (Default: /etc/rsnapshot (will be created if it doesn't exist))
|
||||
####`$config_backup_user`
|
||||
The user to run the backup scripts as (Default: root, also the user used for ssh connections, if you change this make sure you have proper key deployed and the user exists in the nodes to be backed up.)
|
||||
####`$package_name`
|
||||
Default: rsnapshot
|
||||
####`$package_ensure`
|
||||
Default: present
|
||||
####`$cron_dir`
|
||||
Directory to drop the cron files to. Crons will be created per host. (Default: /etc/cron.d)
|
||||
####`$backup_levels`
|
||||
Array containing the backup levels (hourly, daily, weekly, monthly)
|
||||
Configure the backup_levels (valid per host and global, so you may either set: rsnapshot::backup_levels for all hosts or override default backup_levels for specific hosts)
|
||||
####`$backup_defaults`
|
||||
Boolean. Backup default backup dirs or not.
|
||||
####`$cron`
|
||||
Hash. Set time ranges for different backup levels.
|
||||
Hash is of the form:
|
||||
cron =>{
|
||||
daily => {
|
||||
minute => param,
|
||||
hour => param,
|
||||
}
|
||||
weekly => {
|
||||
minute => param,
|
||||
hour => param,
|
||||
}
|
||||
{...}
|
||||
}
|
||||
### rsnapshot configuration variables
|
||||
Please read up on the following in the [rsnapshot manpage](http://linux.die.net/man/1/rsnapshot)
|
||||
####`$cmd_cp`
|
||||
####`$cmd_rm`
|
||||
####`$cmd_rsync`
|
||||
####`$cmd_ssh`
|
||||
####`$cmd_logger`
|
||||
####`$cmd_du`
|
||||
####`$cmd_rsnapshot_diff`
|
||||
####`$cmd_preexec`
|
||||
####`$cmd_postexec`
|
||||
####`$use_lvm`
|
||||
####`$linux_lvm_cmd_lvcreate`
|
||||
####`$linux_lvm_cmd_lvremove`
|
||||
####`$linux_lvm_cmd_mount`
|
||||
####`$linux_lvm_cmd_umount`
|
||||
####`$linux_lvm_snapshotsize`
|
||||
####`$linux_lvm_snapshotname`
|
||||
####`$linux_lvm_vgpath`
|
||||
####`$linux_lvm_mountpath`
|
||||
####`$logpath`
|
||||
####`$logfile`
|
||||
####`$lockpath`
|
||||
####`$snapshot_root`
|
||||
####`$no_create_root`
|
||||
####`$verbose`
|
||||
####`$loglevel`
|
||||
####`$stop_on_stale_lockfile`
|
||||
####`$rsync_short_args`
|
||||
####`$rsync_long_args`
|
||||
####`$ssh_args`
|
||||
####`$du_args`
|
||||
####`$one_fs`
|
||||
####`$retain`
|
||||
####`$interval`
|
||||
####`$include`
|
||||
####`$exclude`
|
||||
####`$include_file`
|
||||
####`$exclude_file`
|
||||
####`$link_dest`
|
||||
####`$sync_first`
|
||||
####`$rsync_numtries`
|
||||
####`$use_lazy_deletes`
|
||||
####`$default_backup`
|
||||
####`$backup_scripts`
|
||||
|
||||
## Limitations
|
||||
Currently, this module support CentOS, Fedora (with the bloonix CentOS Repo), Ubuntu and Debian.
|
||||
|
||||
## Development
|
||||
I have limited access to resources and time, so if you think this module is useful, like it, hate it, want to make it better or
|
||||
want it off the face of the planet, feel free to get in touch with me.
|
||||
|
||||
## Editors
|
||||
Norbert Varzariu (loomsen)
|
||||
|
||||
## Contributors
|
||||
Please see the [list of contributors.](https://github.com/loomsen/puppet-bloonix_agent/graphs/contributors)
|
23
pkg/loomsen-rsnapshot-0.1.0/Rakefile
Normal file
23
pkg/loomsen-rsnapshot-0.1.0/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
|
||||
|
12
pkg/loomsen-rsnapshot-0.1.0/TODO
Normal file
12
pkg/loomsen-rsnapshot-0.1.0/TODO
Normal file
@ -0,0 +1,12 @@
|
||||
* create a struct for cron like
|
||||
cron = {
|
||||
daily = {
|
||||
minute =>
|
||||
hour =>
|
||||
}
|
||||
monthly = {
|
||||
minute =>
|
||||
hour =>
|
||||
}
|
||||
}
|
||||
|
26
pkg/loomsen-rsnapshot-0.1.0/checksums.json
Normal file
26
pkg/loomsen-rsnapshot-0.1.0/checksums.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"CONTRIBUTING.md": "1d1592146aac11936cfda288a04df0e0",
|
||||
"Gemfile": "1291530f9171164c98d314b359bf1d94",
|
||||
"README.md": "79b9753e608f7413f221c040bc980524",
|
||||
"Rakefile": "53164c731c7c0dee279cbe74fce9371e",
|
||||
"TODO": "0833be6e9308a2f59bbdcbb4c175fa05",
|
||||
"lib/puppet/parser/functions/assert_empty_hash.rb": "69fbc5b1d1f85fdd4d4266154d2f074c",
|
||||
"lib/puppet/parser/functions/pick_undef.rb": "227f605e6442d77311cc7faa77c1d293",
|
||||
"lib/puppet/parser/functions/rand_from_array.rb": "bd6e47f00da29df03f529cacb12635ea",
|
||||
"manifests/config.pp": "0f056c7326cacc11697533097e829eed",
|
||||
"manifests/cron.pp": "e2cde5fdb7dd677e0d97308f55fae765",
|
||||
"manifests/init.pp": "714aa55c4e1a495b522075e77c334fdc",
|
||||
"manifests/install.pp": "fb9ade1c118a3ea8c124584418bd45ad",
|
||||
"manifests/params.pp": "bcffee800748e3ce58ecd2c0f596f94a",
|
||||
"metadata.json": "a0219eb24180c95903cfc7bbe05883f6",
|
||||
"spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml": "6e8a9cb235318d510f5931e73ac07c05",
|
||||
"spec/acceptance/nodesets/ubuntu-12.04-x86_64-vagrant.yml": "d170363003b078c180a7263f4b34f53c",
|
||||
"spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml": "2114f58c30427f4c57e1140b1cbdcab9",
|
||||
"spec/acceptance/nodesets/ubuntu-14.04-x86_64-vagrant.yml": "07eedc8f2975ab1c5a5ce28133ef8017",
|
||||
"spec/classes/init_spec.rb": "12aea61c02cc639c7f42a7e988639159",
|
||||
"spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c",
|
||||
"spec/spec_helper.rb": "f3f775caa765cd5ebec8d307f2b07fc5",
|
||||
"templates/cron.erb": "e9455ec3d623a67de0b3fa62255199f7",
|
||||
"templates/rsnapshot.erb": "28250af764432307b330d1ec579afcca",
|
||||
"tests/init.pp": "289ce3c27eea72b5c648097a23bcea61"
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:assert_empty_hash, :type => :rvalue, :doc => <<-EOS
|
||||
This function checks an input struct for undefined hashes in key => hash and assigns {}. This is only a helper function to make a hash.each work if one of the values is undefined
|
||||
EOS
|
||||
)do |args|
|
||||
fail "Must receive one argument." if args.empty?
|
||||
args.each do |arg|
|
||||
h = Hash.new
|
||||
arg.each_pair do |host, hash|
|
||||
unless hash.is_a? Hash
|
||||
hash = {}
|
||||
end
|
||||
h[host] = hash
|
||||
end
|
||||
return h
|
||||
end
|
||||
end
|
||||
end
|
@ -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
|
@ -0,0 +1,37 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:rand_from_array, :type => :rvalue, :doc => <<-EOS
|
||||
This function takes either an int or an array as input and returns the int or a
|
||||
random element from the array
|
||||
EOS
|
||||
)do |args|
|
||||
fail "Must receive two argument." if args.empty?
|
||||
#++ this works if the input is an array
|
||||
# return args.sample
|
||||
# +++++++++++++++++++++++++++++++++++++
|
||||
# args.flatten!
|
||||
params = []
|
||||
params << args[0]
|
||||
params.flatten!
|
||||
arr = []
|
||||
salt = args[1].sum % 60
|
||||
rnd = Random.new(salt)
|
||||
# rnd = Random.new()
|
||||
params.each do |key|
|
||||
if key.is_a?(String) and key =~ /\d\.\.\d/
|
||||
k = key.split('..')
|
||||
r = Range.new(k[0],k[1]).to_a
|
||||
arr << r
|
||||
arr.flatten!
|
||||
elsif key.is_a?(String)
|
||||
arr << key
|
||||
arr.flatten!
|
||||
elsif key.is_a?(Integer)
|
||||
arr << key.to_s
|
||||
arr.flatten!
|
||||
end
|
||||
end
|
||||
last_i = arr.length - 1
|
||||
return arr[rnd.rand(0..last_i)]
|
||||
|
||||
end
|
||||
end
|
146
pkg/loomsen-rsnapshot-0.1.0/manifests/config.pp
Normal file
146
pkg/loomsen-rsnapshot-0.1.0/manifests/config.pp
Normal file
@ -0,0 +1,146 @@
|
||||
# == Class: rsnapshot::config
|
||||
#
|
||||
# manage host configs
|
||||
class rsnapshot::config (
|
||||
$hosts = $rsnapshot::hosts,
|
||||
$cron_dir = $rsnapshot::cron_dir,
|
||||
) {
|
||||
# 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',
|
||||
}
|
||||
file { $cron_dir:
|
||||
ensure => 'directory',
|
||||
}
|
||||
# custom function, if only a hostname is given as a param, this is an empty hash
|
||||
# the next loop would break as puppet does not allow to reassign variables
|
||||
# the function checks $hosts for elements like:
|
||||
# { foo => } and converts those to { foo => {} }
|
||||
$hosts_clean = assert_empty_hash($hosts)
|
||||
|
||||
$hosts_clean.each |String $host, Hash $hash | {
|
||||
$snapshot_root = pick($hash['snapshot_root'], $rsnapshot::params::config_snapshot_root)
|
||||
$backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user)
|
||||
$default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup)
|
||||
$backup_levels = pick($hash['backup_levels'], $rsnapshot::params::config_backup_levels, 'weekly')
|
||||
$backup = $hash['backup']
|
||||
$backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults)
|
||||
$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)
|
||||
$logpath = pick($hash['logpath'], $rsnapshot::logpath, $rsnapshot::params::config_logpath)
|
||||
$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)
|
||||
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
||||
$retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain)
|
||||
$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)
|
||||
$sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first)
|
||||
$use_lazy_deletes = pick_undef($hash['use_lazy_deletes'], $rsnapshot::params::config_use_lazy_deletes)
|
||||
$rsync_numtries = pick_undef($hash['rsync_numtries'], $rsnapshot::params::config_rsync_numtries)
|
||||
$backup_scripts = pick_undef($hash['backup_scripts'], $rsnapshot::params::config_backup_scripts)
|
||||
|
||||
$snapshot_dir = "${config_snapshot_root}/${host}"
|
||||
$config = "${conf_d}/${host}.rsnapshot.conf"
|
||||
$lockfile = "${lockpath}/${host}.pid"
|
||||
$logfile = "${logpath}/${host}.log"
|
||||
|
||||
# fail if $backup_defaults is set to false and no $host[backup] defined
|
||||
if ! $backup_defaults and ! $backup {
|
||||
fail("==> Configuration error: backup_defaults is ${backup_defaults} and backup definitions for this host don't exist <==")
|
||||
}
|
||||
|
||||
# merge the backup hashes to one if backup_default is set (defaults to true)
|
||||
if $backup_defaults {
|
||||
$backups = merge($backup, $default_backup_dirs)
|
||||
} else {
|
||||
$backups = $backup
|
||||
}
|
||||
|
||||
# one of both interval or retain must be present
|
||||
if ! ( $interval and $retain ) {
|
||||
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
||||
}
|
||||
# rsnapshot wants numeric values
|
||||
if $link_dest {
|
||||
$link_dest_num = bool2num($link_dest)
|
||||
}
|
||||
if $sync_first {
|
||||
$sync_first_num = bool2num($sync_first)
|
||||
}
|
||||
if $use_lazy_deletes {
|
||||
$use_lazy_deletes_num = bool2num($use_lazy_deletes)
|
||||
}
|
||||
|
||||
file { $exclude_file:
|
||||
ensure => file,
|
||||
}
|
||||
file { $config:
|
||||
content => template('rsnapshot/rsnapshot.erb')
|
||||
}
|
||||
|
||||
$cronfile = "/tmp/rsnapshot.d/cron/${host}"
|
||||
concat { "${cronfile}":
|
||||
}
|
||||
$backup_levels.each |String $level| {
|
||||
if validate_hash($hash) {
|
||||
# allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly
|
||||
if has_key($host, 'cron'){
|
||||
$c_min = pick($host['cron'][$level]['minute'], $rsnapshot::params::cron[$level]['minute'], '*')
|
||||
$c_hour = pick($host['cron'][$level]['hour'], $rsnapshot::params::cron[$level]['hour'], '*')
|
||||
$c_monthday = pick($host['cron'][$level]['monthday'], $rsnapshot::params::cron[$level]['monthday'], '*')
|
||||
$c_month = pick($host['cron'][$level]['month'], $rsnapshot::params::cron[$level]['month'], '*')
|
||||
$c_weekday = pick($host['cron'][$level]['weekday'], $rsnapshot::params::cron[$level]['weekday'], '*')
|
||||
}
|
||||
} else {
|
||||
$c_min = $rsnapshot::params::cron[$level]['minute']
|
||||
$c_hour = $rsnapshot::params::cron[$level]['hour']
|
||||
$c_monthday = $rsnapshot::params::cron[$level]['monthday']
|
||||
$c_month = $rsnapshot::params::cron[$level]['month']
|
||||
$c_weekday = $rsnapshot::params::cron[$level]['weekday']
|
||||
}
|
||||
$minute = rand_from_array($c_min, "${host}.${level}")
|
||||
$hour = rand_from_array($c_hour, "${host}.${level}")
|
||||
$monthday = rand_from_array($c_monthday, "${host}.${level}")
|
||||
$month = rand_from_array($c_month, "${host}.${level}")
|
||||
$weekday = rand_from_array($c_weekday, "${host}.${level}")
|
||||
concat::fragment { "${host}.${level}":
|
||||
target => "${cronfile}",
|
||||
content => template('rsnapshot/cron.erb'),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
pkg/loomsen-rsnapshot-0.1.0/manifests/init.pp
Normal file
23
pkg/loomsen-rsnapshot-0.1.0/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,
|
||||
$default_backup = $rsnapshot::params::config_default_backup,
|
||||
$package_name = $rsnapshot::params::package_name,
|
||||
$package_ensure = $rsnapshot::params::package_ensure,
|
||||
) inherits rsnapshot::params {
|
||||
if $hosts {
|
||||
class { 'rsnapshot::install': }->
|
||||
class { 'rsnapshot::config': }
|
||||
contain 'rsnapshot::install'
|
||||
contain 'rsnapshot::config'
|
||||
}
|
||||
}
|
||||
|
14
pkg/loomsen-rsnapshot-0.1.0/manifests/install.pp
Normal file
14
pkg/loomsen-rsnapshot-0.1.0/manifests/install.pp
Normal file
@ -0,0 +1,14 @@
|
||||
# == Class: rsnapshot::install
|
||||
#
|
||||
# Installs the rsnapshot package.
|
||||
class rsnapshot::install inherits rsnapshot {
|
||||
case $::operatingsystem {
|
||||
/^CentOS$/: { include epel }
|
||||
default: {}
|
||||
}
|
||||
package { $rsnapshot::package_name:
|
||||
ensure => $rsnapshot::package_ensure,
|
||||
}
|
||||
|
||||
}
|
||||
|
94
pkg/loomsen-rsnapshot-0.1.0/manifests/params.pp
Normal file
94
pkg/loomsen-rsnapshot-0.1.0/manifests/params.pp
Normal file
@ -0,0 +1,94 @@
|
||||
# == 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'
|
||||
$cron_dir = '/tmp/rsnapshot.d/cron'
|
||||
$config_backup_levels = [ 'daily', 'weekly', ]
|
||||
$config_backup_defaults = true
|
||||
$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_default_backup = {
|
||||
'/etc' => './',
|
||||
'/home' => './',
|
||||
}
|
||||
$config_backup_scripts = {}
|
||||
$cron = {
|
||||
'hourly' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '*', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '*',
|
||||
'month' => '*',
|
||||
'weekday' => '*',
|
||||
},
|
||||
'daily' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '*',
|
||||
'month' => '*',
|
||||
'weekday' => '*',
|
||||
},
|
||||
'weekly' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '*',
|
||||
'month' => '*',
|
||||
'weekday' => '0..6',
|
||||
},
|
||||
'monthly' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '0..28',
|
||||
'month' => '*',
|
||||
'weekday' => '*',
|
||||
},
|
||||
}
|
||||
}
|
69
pkg/loomsen-rsnapshot-0.1.0/metadata.json
Normal file
69
pkg/loomsen-rsnapshot-0.1.0/metadata.json
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"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",
|
||||
"dependencies": [
|
||||
{"name":"puppetlabs-stdlib"},
|
||||
{"name":"stahnma-epel"}
|
||||
],
|
||||
"data_provider": null,
|
||||
"tags": [
|
||||
"rsnapshot",
|
||||
"backup",
|
||||
"rsync"
|
||||
],
|
||||
"requirements": [
|
||||
{
|
||||
"name": "pe",
|
||||
"version_requirement": ">= 3.0.0"
|
||||
},
|
||||
{
|
||||
"name": "puppet",
|
||||
"version_requirement": ">= 3.0.0"
|
||||
}
|
||||
],
|
||||
"operatingsystem_support": [
|
||||
{
|
||||
"operatingsystem": "CentOS",
|
||||
"operatingsystemrelease": [
|
||||
"5",
|
||||
"6",
|
||||
"7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"operatingsystem": "Debian",
|
||||
"operatingsystemrelease": [
|
||||
"6",
|
||||
"7",
|
||||
"8"
|
||||
]
|
||||
},
|
||||
{
|
||||
"operatingsystem": "Ubuntu",
|
||||
"operatingsystemrelease": [
|
||||
"12.04",
|
||||
"10.04",
|
||||
"14.04"
|
||||
]
|
||||
},
|
||||
{
|
||||
"operatingsystem": "Fedora",
|
||||
"operatingsystemrelease": [
|
||||
"17",
|
||||
"18",
|
||||
"19",
|
||||
"20",
|
||||
"21",
|
||||
"22",
|
||||
"23",
|
||||
"24"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
@ -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
|
@ -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
|
@ -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
pkg/loomsen-rsnapshot-0.1.0/spec/classes/init_spec.rb
Normal file
37
pkg/loomsen-rsnapshot-0.1.0/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
pkg/loomsen-rsnapshot-0.1.0/spec/spec.opts
Normal file
6
pkg/loomsen-rsnapshot-0.1.0/spec/spec.opts
Normal file
@ -0,0 +1,6 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
29
pkg/loomsen-rsnapshot-0.1.0/spec/spec_helper.rb
Normal file
29
pkg/loomsen-rsnapshot-0.1.0/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
|
||||
|
1
pkg/loomsen-rsnapshot-0.1.0/templates/cron.erb
Normal file
1
pkg/loomsen-rsnapshot-0.1.0/templates/cron.erb
Normal file
@ -0,0 +1 @@
|
||||
<%= @minute %> <%= @hour %> <%= @month %> <%= @monthday %> <%= @weekday %> root /usr/bin/rsnapshot -c <%= @config %> <%= @level %>
|
144
pkg/loomsen-rsnapshot-0.1.0/templates/rsnapshot.erb
Normal file
144
pkg/loomsen-rsnapshot-0.1.0/templates/rsnapshot.erb
Normal file
@ -0,0 +1,144 @@
|
||||
# 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 @host == 'localhost' -%>
|
||||
backup <%= source %> <%=dest%>
|
||||
<% elsif @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
pkg/loomsen-rsnapshot-0.1.0/tests/init.pp
Normal file
12
pkg/loomsen-rsnapshot-0.1.0/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
|
BIN
pkg/loomsen-rsnapshot-0.1.1.tar.gz
Normal file
BIN
pkg/loomsen-rsnapshot-0.1.1.tar.gz
Normal file
Binary file not shown.
135
pkg/loomsen-rsnapshot-0.1.1/CONTRIBUTING.md
Normal file
135
pkg/loomsen-rsnapshot-0.1.1/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
pkg/loomsen-rsnapshot-0.1.1/Gemfile
Normal file
32
pkg/loomsen-rsnapshot-0.1.1/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
|
305
pkg/loomsen-rsnapshot-0.1.1/README.md
Normal file
305
pkg/loomsen-rsnapshot-0.1.1/README.md
Normal file
@ -0,0 +1,305 @@
|
||||
# rsnapshot
|
||||
|
||||
#### Table of Contents
|
||||
|
||||
1. [Overview](#overview)
|
||||
2. [Module Description - What the module does and why it is useful](#module-description)
|
||||
* [Notes](#notes)
|
||||
3. [Setup - The basics of getting started with rsnapshot](#setup)
|
||||
* [What rsnapshot affects](#what-rsnapshot-affects)
|
||||
* [Setup requirements](#setup-requirements)
|
||||
* [Getting started with rsnapshot](#getting-started)
|
||||
4. [Configuration - options and additional functionality](#configuration)
|
||||
* [Examples](#examples)
|
||||
* [More Options](#more-options)
|
||||
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)
|
||||
7. [Editors](#editors)
|
||||
8. [Contributors](#contributors)
|
||||
|
||||
## Overview
|
||||
|
||||
The rsnapshot module installs, configures and manages rsnapshot on a dedicated backup server.
|
||||
|
||||
## Module Description
|
||||
The rsnapshot module installs, configures and manages rsnapshot on a dedicated backup server. It allows to set up a centralized Backup Server for all your nodes.
|
||||
For the cron setup, the module will pick random time entries for the crons from an Array or a Range of time. For how to configure this, [please see below](#more-options)
|
||||
|
||||
### Notes
|
||||
This module is best used with an ENC like hiera. It will make your config much easier to read and to maintain. Check the examples to see what I mean.
|
||||
|
||||
## Setup
|
||||
|
||||
### What rsnapshot affects
|
||||
|
||||
* This module will install the rsnapshot package on your system
|
||||
* This module will manage the rsnapshot config on your system
|
||||
* This module will manage cron entries for your configured nodes
|
||||
|
||||
### Setup Requirements
|
||||
|
||||
On CentOS Systems this module requires the stahnma-epel module. Also you will need to have rsync installed on all nodes to be backed up.
|
||||
It will create repeatable random cron entries from a configurable timerange for all hosts.
|
||||
|
||||
### Getting Started
|
||||
|
||||
You will need to pass the nodenames to be backed up at least.
|
||||
This will pickup all defaults and add localhost to the backups:
|
||||
|
||||
|
||||
```puppet
|
||||
class { '::rsnapshot':
|
||||
hosts => {
|
||||
'localhost' => {},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
Here are some more elaborate examples of what you can do with this module.
|
||||
|
||||
### Examples
|
||||
This will backup localhost with defaults. It will disable the default backup locations for example.com
|
||||
and just backup '/var' for example.com.
|
||||
```puppet
|
||||
class { '::rsnapshot':
|
||||
hosts => {
|
||||
'localhost' => {},
|
||||
'example.com' => {
|
||||
backup_defaults => false,
|
||||
backup => {
|
||||
'/var/' => './'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
The same in hiera:
|
||||
```yaml
|
||||
---
|
||||
classes: rsnapshot
|
||||
rsnapshot::hosts:
|
||||
localhost:
|
||||
example.com:
|
||||
backup_defaults: false
|
||||
backup:
|
||||
'/var/': './'
|
||||
```
|
||||
|
||||
|
||||
|
||||
A more complete hiera example:
|
||||
```yaml
|
||||
---
|
||||
classes:
|
||||
- rsnapshot
|
||||
|
||||
# override default backup dirs for all hosts:
|
||||
rsnapshot::default_backup:
|
||||
'/etc': './'
|
||||
'/usr/local': './'
|
||||
'/home': './'
|
||||
|
||||
# configure hosts to be backed up
|
||||
rsnapshot::hosts:
|
||||
# pick all defaults for localhost
|
||||
localhost:
|
||||
# add futher backups for node foo.example.com (additional to default_backup) and use a different snapshot root
|
||||
foo.example.com:
|
||||
backup:
|
||||
'/foo': './'
|
||||
'/bar': './'
|
||||
'/baz': './misc'
|
||||
snapshot_root: '/tmp/rsnapshot'
|
||||
# all defaults
|
||||
foo1.example.com:
|
||||
foo2:
|
||||
# disable default backup dirs and just backup /var for node bar1
|
||||
# also set the minute to 0-10 for daily cron (note: this is not particularly useful, it's just meant to document the features)
|
||||
# lastly set the range of hours to pick a random hour from (the cron for bar1 will have hour set to something between 1 and 5)
|
||||
bar1:
|
||||
backup_defaults: false
|
||||
backup:
|
||||
'/var': './var'
|
||||
cron:
|
||||
'daily':
|
||||
'minute': '0-10'
|
||||
'hour': '1..5'
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
### More options
|
||||
The defaults are pretty reasonable, I hope. However, you may override pretty much anything. Available parameters are discussed below.
|
||||
|
||||
#### Specials
|
||||
As mentioned, this module will generate random time entries for your hosts. The random number generator is hashed with hostname and backup_level, so the randomness will be repeatable per host.level. This is important so puppet won't override the crons with each run.
|
||||
You may specify time ranges as follows:
|
||||
* default cron syntax (1-10, '*/5', 5)
|
||||
* an array with allowed values, for example, if you want the backup for a host to run between 1am and 5am, you would override the hours setting for the host in question.
|
||||
in hiera this would look like: (Explanation see below)
|
||||
```yaml
|
||||
rsnapshot::hosts:
|
||||
example.com:
|
||||
cron:
|
||||
'daily':
|
||||
'minute': '1'
|
||||
'hour': '1..5'
|
||||
```
|
||||
This will create the rsnapshot config using defaults from params.pp, but set the minute of the daily backup to '1' and the hour to something random between 1 and 5.
|
||||
So it would look something like:
|
||||
```
|
||||
1 4 * * * foo daily
|
||||
```
|
||||
or maybe
|
||||
```
|
||||
1 2 * * * foo daily
|
||||
```
|
||||
## Reference
|
||||
|
||||
### Classes
|
||||
|
||||
#### Public Classes
|
||||
* rsnapshot: Main class, includes all other classes.
|
||||
|
||||
####Private Classes
|
||||
|
||||
* rsnapshot::install: Handles the packages.
|
||||
* rsnapshot::config: Handles configuration and cron files.
|
||||
* rsnapshot::params: default values.
|
||||
|
||||
### Functions
|
||||
####`assert_empty_hash`
|
||||
Sets an empty value to a hash (we need this so a loop doesn't break if just a hostname is given to pick up all defaults.
|
||||
|
||||
####`pick_undef`
|
||||
Like pick but returns undef values.
|
||||
|
||||
####`rand_from_array`
|
||||
Takes an Integer, a String or an Array as input, and returns a random entry from the array (or just the String/Integer)
|
||||
|
||||
### Parameters
|
||||
|
||||
The following parameters are available in the `::rsnapshot` class:
|
||||
|
||||
####`$hosts`
|
||||
Hash containing the hosts to be backed up and optional overrides per host
|
||||
####`$conf_d`
|
||||
The place where the configs will be dropped (Default: /etc/rsnapshot (will be created if it doesn't exist))
|
||||
####`$backup_user`
|
||||
The user to run the backup scripts as (Default: root, also the user used for ssh connections, if you change this make sure you have proper key deployed and the user exists in the nodes to be backed up.)
|
||||
####`$package_name`
|
||||
Default: rsnapshot
|
||||
####`$package_ensure`
|
||||
Default: present
|
||||
####`$cron_dir`
|
||||
Directory to drop the cron files to. Crons will be created per host. (Default: /etc/cron.d)
|
||||
####`$backup_levels`
|
||||
Array containing the backup levels (hourly, daily, weekly, monthly)
|
||||
Configure the backup_levels (valid per host and global, so you may either set: rsnapshot::backup_levels for all hosts or override default backup_levels for specific hosts)
|
||||
####`$backup_defaults`
|
||||
Boolean. Backup default backup dirs or not.
|
||||
####`$cron`
|
||||
Hash. Set time ranges for different backup levels.
|
||||
Hash is of the form:
|
||||
```puppet
|
||||
cron =>{
|
||||
daily => {
|
||||
minute => param,
|
||||
hour => param,
|
||||
}
|
||||
weekly => {
|
||||
minute => param,
|
||||
hour => param,
|
||||
}
|
||||
{...}
|
||||
}
|
||||
```
|
||||
####`$snapshot_root`
|
||||
global. the directory holding your backups. you will end up with a structure like:
|
||||
```
|
||||
/backup/
|
||||
├── example.com
|
||||
│ ├── daily.0
|
||||
│ ├── daily.1
|
||||
│ ├── daily.2
|
||||
│ ├── daily.3
|
||||
│ ├── weekly.0
|
||||
│ ├── weekly.1
|
||||
│ ├── weekly.2
|
||||
│ └── weekly.3
|
||||
└── localhost
|
||||
├── daily.0
|
||||
├── daily.1
|
||||
├── daily.2
|
||||
└── weekly.0
|
||||
```
|
||||
|
||||
####`$default_backup`
|
||||
The default backup directories (may be set per host, even though there is not much sense in doing so)
|
||||
Default is:
|
||||
```puppet
|
||||
default_backup => {
|
||||
'/etc' => './',
|
||||
'/home' => './',
|
||||
}
|
||||
```
|
||||
### rsnapshot configuration variables
|
||||
Please read up on the following in the [rsnapshot manpage](http://linux.die.net/man/1/rsnapshot)
|
||||
####`$cmd_cp`
|
||||
####`$cmd_rm`
|
||||
####`$cmd_rsync`
|
||||
####`$cmd_ssh`
|
||||
####`$cmd_logger`
|
||||
####`$cmd_du`
|
||||
####`$cmd_rsnapshot_diff`
|
||||
####`$cmd_preexec`
|
||||
####`$cmd_postexec`
|
||||
####`$use_lvm`
|
||||
####`$linux_lvm_cmd_lvcreate`
|
||||
####`$linux_lvm_cmd_lvremove`
|
||||
####`$linux_lvm_cmd_mount`
|
||||
####`$linux_lvm_cmd_umount`
|
||||
####`$linux_lvm_snapshotsize`
|
||||
####`$linux_lvm_snapshotname`
|
||||
####`$linux_lvm_vgpath`
|
||||
####`$linux_lvm_mountpath`
|
||||
####`$logpath`
|
||||
####`$logfile`
|
||||
####`$lockpath`
|
||||
####`$no_create_root`
|
||||
####`$verbose`
|
||||
####`$loglevel`
|
||||
####`$stop_on_stale_lockfile`
|
||||
####`$rsync_short_args`
|
||||
####`$rsync_long_args`
|
||||
####`$ssh_args`
|
||||
####`$du_args`
|
||||
####`$one_fs`
|
||||
####`$retain`
|
||||
####`$interval`
|
||||
####`$include`
|
||||
####`$exclude`
|
||||
####`$include_file`
|
||||
####`$exclude_file`
|
||||
####`$link_dest`
|
||||
####`$sync_first`
|
||||
####`$rsync_numtries`
|
||||
####`$use_lazy_deletes`
|
||||
####`$backup_scripts`
|
||||
|
||||
## Limitations
|
||||
Currently, this module support CentOS, Fedora (with the bloonix CentOS Repo), Ubuntu and Debian.
|
||||
|
||||
## Development
|
||||
I have limited access to resources and time, so if you think this module is useful, like it, hate it, want to make it better or
|
||||
want it off the face of the planet, feel free to get in touch with me.
|
||||
|
||||
## Editors
|
||||
Norbert Varzariu (loomsen)
|
||||
|
||||
## Contributors
|
||||
Please see the [list of contributors.](https://github.com/loomsen/puppet-bloonix_agent/graphs/contributors)
|
23
pkg/loomsen-rsnapshot-0.1.1/Rakefile
Normal file
23
pkg/loomsen-rsnapshot-0.1.1/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
|
||||
|
0
pkg/loomsen-rsnapshot-0.1.1/TODO
Normal file
0
pkg/loomsen-rsnapshot-0.1.1/TODO
Normal file
26
pkg/loomsen-rsnapshot-0.1.1/checksums.json
Normal file
26
pkg/loomsen-rsnapshot-0.1.1/checksums.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"CONTRIBUTING.md": "1d1592146aac11936cfda288a04df0e0",
|
||||
"Gemfile": "1291530f9171164c98d314b359bf1d94",
|
||||
"README.md": "f8aa8b62e3137cd2e42b99d853b32c0b",
|
||||
"Rakefile": "53164c731c7c0dee279cbe74fce9371e",
|
||||
"TODO": "d41d8cd98f00b204e9800998ecf8427e",
|
||||
"lib/puppet/parser/functions/assert_empty_hash.rb": "69fbc5b1d1f85fdd4d4266154d2f074c",
|
||||
"lib/puppet/parser/functions/pick_undef.rb": "227f605e6442d77311cc7faa77c1d293",
|
||||
"lib/puppet/parser/functions/rand_from_array.rb": "bd6e47f00da29df03f529cacb12635ea",
|
||||
"manifests/config.pp": "6d84bac803bf0b143d3d75837a038cea",
|
||||
"manifests/cron.pp": "e2cde5fdb7dd677e0d97308f55fae765",
|
||||
"manifests/init.pp": "714aa55c4e1a495b522075e77c334fdc",
|
||||
"manifests/install.pp": "fb9ade1c118a3ea8c124584418bd45ad",
|
||||
"manifests/params.pp": "de10018211fa504d698fa980d2f1a65b",
|
||||
"metadata.json": "9e568b31809ee9caba45a3ae805e9e0d",
|
||||
"spec/acceptance/nodesets/ubuntu-12.04-x86_64-docker.yml": "6e8a9cb235318d510f5931e73ac07c05",
|
||||
"spec/acceptance/nodesets/ubuntu-12.04-x86_64-vagrant.yml": "d170363003b078c180a7263f4b34f53c",
|
||||
"spec/acceptance/nodesets/ubuntu-14.04-x86_64-docker.yml": "2114f58c30427f4c57e1140b1cbdcab9",
|
||||
"spec/acceptance/nodesets/ubuntu-14.04-x86_64-vagrant.yml": "07eedc8f2975ab1c5a5ce28133ef8017",
|
||||
"spec/classes/init_spec.rb": "12aea61c02cc639c7f42a7e988639159",
|
||||
"spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c",
|
||||
"spec/spec_helper.rb": "f3f775caa765cd5ebec8d307f2b07fc5",
|
||||
"templates/cron.erb": "e9455ec3d623a67de0b3fa62255199f7",
|
||||
"templates/rsnapshot.erb": "28250af764432307b330d1ec579afcca",
|
||||
"tests/init.pp": "289ce3c27eea72b5c648097a23bcea61"
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:assert_empty_hash, :type => :rvalue, :doc => <<-EOS
|
||||
This function checks an input struct for undefined hashes in key => hash and assigns {}. This is only a helper function to make a hash.each work if one of the values is undefined
|
||||
EOS
|
||||
)do |args|
|
||||
fail "Must receive one argument." if args.empty?
|
||||
args.each do |arg|
|
||||
h = Hash.new
|
||||
arg.each_pair do |host, hash|
|
||||
unless hash.is_a? Hash
|
||||
hash = {}
|
||||
end
|
||||
h[host] = hash
|
||||
end
|
||||
return h
|
||||
end
|
||||
end
|
||||
end
|
@ -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
|
@ -0,0 +1,37 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:rand_from_array, :type => :rvalue, :doc => <<-EOS
|
||||
This function takes either an int or an array as input and returns the int or a
|
||||
random element from the array
|
||||
EOS
|
||||
)do |args|
|
||||
fail "Must receive two argument." if args.empty?
|
||||
#++ this works if the input is an array
|
||||
# return args.sample
|
||||
# +++++++++++++++++++++++++++++++++++++
|
||||
# args.flatten!
|
||||
params = []
|
||||
params << args[0]
|
||||
params.flatten!
|
||||
arr = []
|
||||
salt = args[1].sum % 60
|
||||
rnd = Random.new(salt)
|
||||
# rnd = Random.new()
|
||||
params.each do |key|
|
||||
if key.is_a?(String) and key =~ /\d\.\.\d/
|
||||
k = key.split('..')
|
||||
r = Range.new(k[0],k[1]).to_a
|
||||
arr << r
|
||||
arr.flatten!
|
||||
elsif key.is_a?(String)
|
||||
arr << key
|
||||
arr.flatten!
|
||||
elsif key.is_a?(Integer)
|
||||
arr << key.to_s
|
||||
arr.flatten!
|
||||
end
|
||||
end
|
||||
last_i = arr.length - 1
|
||||
return arr[rnd.rand(0..last_i)]
|
||||
|
||||
end
|
||||
end
|
148
pkg/loomsen-rsnapshot-0.1.1/manifests/config.pp
Normal file
148
pkg/loomsen-rsnapshot-0.1.1/manifests/config.pp
Normal file
@ -0,0 +1,148 @@
|
||||
# == Class: rsnapshot::config
|
||||
#
|
||||
# manage host configs
|
||||
class rsnapshot::config (
|
||||
$hosts = $rsnapshot::hosts,
|
||||
$cron_dir = $rsnapshot::cron_dir,
|
||||
) {
|
||||
# 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)
|
||||
$snapshot_root = pick($hosts['snapshot_root'], $rsnapshot::params::config_snapshot_root)
|
||||
# make sure lock path and conf path exist
|
||||
file { $conf_d:
|
||||
ensure => 'directory',
|
||||
}
|
||||
file { $lockpath:
|
||||
ensure => 'directory',
|
||||
}
|
||||
file { $cron_dir:
|
||||
ensure => 'directory',
|
||||
}
|
||||
file { $snapshot_root:
|
||||
ensure => 'directory',
|
||||
}
|
||||
# custom function, if only a hostname is given as a param, this is an empty hash
|
||||
# the next loop would break as puppet does not allow to reassign variables
|
||||
# the function checks $hosts for elements like:
|
||||
# { foo => } and converts those to { foo => {} }
|
||||
$hosts_clean = assert_empty_hash($hosts)
|
||||
|
||||
$hosts_clean.each |String $host, Hash $hash | {
|
||||
$backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user)
|
||||
$default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup)
|
||||
$backup_levels = pick($hash['backup_levels'], $rsnapshot::params::config_backup_levels, 'weekly')
|
||||
$backup = $hash['backup']
|
||||
$backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults)
|
||||
$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)
|
||||
$logpath = pick($hash['logpath'], $rsnapshot::logpath, $rsnapshot::params::config_logpath)
|
||||
$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)
|
||||
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
||||
$retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain)
|
||||
$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)
|
||||
$sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first)
|
||||
$use_lazy_deletes = pick_undef($hash['use_lazy_deletes'], $rsnapshot::params::config_use_lazy_deletes)
|
||||
$rsync_numtries = pick_undef($hash['rsync_numtries'], $rsnapshot::params::config_rsync_numtries)
|
||||
$backup_scripts = pick_undef($hash['backup_scripts'], $rsnapshot::params::config_backup_scripts)
|
||||
|
||||
$snapshot_dir = "${config_snapshot_root}/${host}"
|
||||
$config = "${conf_d}/${host}.rsnapshot.conf"
|
||||
$lockfile = "${lockpath}/${host}.pid"
|
||||
$logfile = "${logpath}/${host}.log"
|
||||
|
||||
# fail if $backup_defaults is set to false and no $host[backup] defined
|
||||
if ! $backup_defaults and ! $backup {
|
||||
fail("==> Configuration error: backup_defaults is ${backup_defaults} and backup definitions for this host don't exist <==")
|
||||
}
|
||||
|
||||
# merge the backup hashes to one if backup_default is set (defaults to true)
|
||||
if $backup_defaults {
|
||||
$backups = merge($backup, $default_backup_dirs)
|
||||
} else {
|
||||
$backups = $backup
|
||||
}
|
||||
|
||||
# one of both interval or retain must be present
|
||||
if ! ( $interval and $retain ) {
|
||||
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
||||
}
|
||||
# rsnapshot wants numeric values
|
||||
if $link_dest {
|
||||
$link_dest_num = bool2num($link_dest)
|
||||
}
|
||||
if $sync_first {
|
||||
$sync_first_num = bool2num($sync_first)
|
||||
}
|
||||
if $use_lazy_deletes {
|
||||
$use_lazy_deletes_num = bool2num($use_lazy_deletes)
|
||||
}
|
||||
|
||||
file { $exclude_file:
|
||||
ensure => 'file',
|
||||
}
|
||||
file { $config:
|
||||
content => template('rsnapshot/rsnapshot.erb')
|
||||
}
|
||||
$cronfile = "${cron_dir}/${host}"
|
||||
concat { "${cronfile}":
|
||||
}
|
||||
$backup_levels.each |String $level| {
|
||||
if validate_hash($hash) {
|
||||
# allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly
|
||||
if has_key($host, 'cron'){
|
||||
$c_min = pick($host['cron'][$level]['minute'], $rsnapshot::params::cron[$level]['minute'], '*')
|
||||
$c_hour = pick($host['cron'][$level]['hour'], $rsnapshot::params::cron[$level]['hour'], '*')
|
||||
$c_monthday = pick($host['cron'][$level]['monthday'], $rsnapshot::params::cron[$level]['monthday'], '*')
|
||||
$c_month = pick($host['cron'][$level]['month'], $rsnapshot::params::cron[$level]['month'], '*')
|
||||
$c_weekday = pick($host['cron'][$level]['weekday'], $rsnapshot::params::cron[$level]['weekday'], '*')
|
||||
}
|
||||
} else {
|
||||
$c_min = $rsnapshot::params::cron[$level]['minute']
|
||||
$c_hour = $rsnapshot::params::cron[$level]['hour']
|
||||
$c_monthday = $rsnapshot::params::cron[$level]['monthday']
|
||||
$c_month = $rsnapshot::params::cron[$level]['month']
|
||||
$c_weekday = $rsnapshot::params::cron[$level]['weekday']
|
||||
}
|
||||
$minute = rand_from_array($c_min, "${host}.${level}")
|
||||
$hour = rand_from_array($c_hour, "${host}.${level}")
|
||||
$monthday = rand_from_array($c_monthday, "${host}.${level}")
|
||||
$month = rand_from_array($c_month, "${host}.${level}")
|
||||
$weekday = rand_from_array($c_weekday, "${host}.${level}")
|
||||
concat::fragment { "${host}.${level}":
|
||||
target => "${cronfile}",
|
||||
content => template('rsnapshot/cron.erb'),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
pkg/loomsen-rsnapshot-0.1.1/manifests/cron.pp
Normal file
7
pkg/loomsen-rsnapshot-0.1.1/manifests/cron.pp
Normal file
@ -0,0 +1,7 @@
|
||||
# this class sets up cron
|
||||
# * todo
|
||||
# let the user specify a range of hours and randomize cron creation in this range use rand for #args and return arg[rand]
|
||||
|
||||
class rsnapshot::cron {
|
||||
|
||||
}
|
23
pkg/loomsen-rsnapshot-0.1.1/manifests/init.pp
Normal file
23
pkg/loomsen-rsnapshot-0.1.1/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,
|
||||
$default_backup = $rsnapshot::params::config_default_backup,
|
||||
$package_name = $rsnapshot::params::package_name,
|
||||
$package_ensure = $rsnapshot::params::package_ensure,
|
||||
) inherits rsnapshot::params {
|
||||
if $hosts {
|
||||
class { 'rsnapshot::install': }->
|
||||
class { 'rsnapshot::config': }
|
||||
contain 'rsnapshot::install'
|
||||
contain 'rsnapshot::config'
|
||||
}
|
||||
}
|
||||
|
14
pkg/loomsen-rsnapshot-0.1.1/manifests/install.pp
Normal file
14
pkg/loomsen-rsnapshot-0.1.1/manifests/install.pp
Normal file
@ -0,0 +1,14 @@
|
||||
# == Class: rsnapshot::install
|
||||
#
|
||||
# Installs the rsnapshot package.
|
||||
class rsnapshot::install inherits rsnapshot {
|
||||
case $::operatingsystem {
|
||||
/^CentOS$/: { include epel }
|
||||
default: {}
|
||||
}
|
||||
package { $rsnapshot::package_name:
|
||||
ensure => $rsnapshot::package_ensure,
|
||||
}
|
||||
|
||||
}
|
||||
|
94
pkg/loomsen-rsnapshot-0.1.1/manifests/params.pp
Normal file
94
pkg/loomsen-rsnapshot-0.1.1/manifests/params.pp
Normal file
@ -0,0 +1,94 @@
|
||||
# == Class: rsnapshot
|
||||
#
|
||||
# default params
|
||||
class rsnapshot::params {
|
||||
$hosts = undef
|
||||
$conf_d = '/etc/rsnapshot' # the place where the host specific configs are stored
|
||||
$config_backup_user = 'root'
|
||||
$package_name = 'rsnapshot'
|
||||
$package_ensure = 'present'
|
||||
$cron_dir = '/etc/cron.d'
|
||||
$config_backup_levels = [ 'daily', 'weekly', ]
|
||||
$config_backup_defaults = true
|
||||
$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_default_backup = {
|
||||
'/etc' => './',
|
||||
'/home' => './',
|
||||
}
|
||||
$config_backup_scripts = {}
|
||||
$cron = {
|
||||
'hourly' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '*', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '*',
|
||||
'month' => '*',
|
||||
'weekday' => '*',
|
||||
},
|
||||
'daily' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '*',
|
||||
'month' => '*',
|
||||
'weekday' => '*',
|
||||
},
|
||||
'weekly' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '*',
|
||||
'month' => '*',
|
||||
'weekday' => '0..6',
|
||||
},
|
||||
'monthly' => {
|
||||
'minute' => '0..59',
|
||||
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
|
||||
'monthday' => '0..28',
|
||||
'month' => '*',
|
||||
'weekday' => '*',
|
||||
},
|
||||
}
|
||||
}
|
69
pkg/loomsen-rsnapshot-0.1.1/metadata.json
Normal file
69
pkg/loomsen-rsnapshot-0.1.1/metadata.json
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "loomsen-rsnapshot",
|
||||
"version": "0.1.1",
|
||||
"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",
|
||||
"dependencies": [
|
||||
{"name":"puppetlabs-stdlib"},
|
||||
{"name":"stahnma-epel"}
|
||||
],
|
||||
"data_provider": null,
|
||||
"tags": [
|
||||
"rsnapshot",
|
||||
"backup",
|
||||
"rsync"
|
||||
],
|
||||
"requirements": [
|
||||
{
|
||||
"name": "pe",
|
||||
"version_requirement": ">= 3.0.0"
|
||||
},
|
||||
{
|
||||
"name": "puppet",
|
||||
"version_requirement": ">= 3.0.0"
|
||||
}
|
||||
],
|
||||
"operatingsystem_support": [
|
||||
{
|
||||
"operatingsystem": "CentOS",
|
||||
"operatingsystemrelease": [
|
||||
"5",
|
||||
"6",
|
||||
"7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"operatingsystem": "Debian",
|
||||
"operatingsystemrelease": [
|
||||
"6",
|
||||
"7",
|
||||
"8"
|
||||
]
|
||||
},
|
||||
{
|
||||
"operatingsystem": "Ubuntu",
|
||||
"operatingsystemrelease": [
|
||||
"12.04",
|
||||
"10.04",
|
||||
"14.04"
|
||||
]
|
||||
},
|
||||
{
|
||||
"operatingsystem": "Fedora",
|
||||
"operatingsystemrelease": [
|
||||
"17",
|
||||
"18",
|
||||
"19",
|
||||
"20",
|
||||
"21",
|
||||
"22",
|
||||
"23",
|
||||
"24"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
@ -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
|
@ -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
|
@ -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
pkg/loomsen-rsnapshot-0.1.1/spec/classes/init_spec.rb
Normal file
37
pkg/loomsen-rsnapshot-0.1.1/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
pkg/loomsen-rsnapshot-0.1.1/spec/spec.opts
Normal file
6
pkg/loomsen-rsnapshot-0.1.1/spec/spec.opts
Normal file
@ -0,0 +1,6 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
29
pkg/loomsen-rsnapshot-0.1.1/spec/spec_helper.rb
Normal file
29
pkg/loomsen-rsnapshot-0.1.1/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
|
||||
|
1
pkg/loomsen-rsnapshot-0.1.1/templates/cron.erb
Normal file
1
pkg/loomsen-rsnapshot-0.1.1/templates/cron.erb
Normal file
@ -0,0 +1 @@
|
||||
<%= @minute %> <%= @hour %> <%= @month %> <%= @monthday %> <%= @weekday %> root /usr/bin/rsnapshot -c <%= @config %> <%= @level %>
|
144
pkg/loomsen-rsnapshot-0.1.1/templates/rsnapshot.erb
Normal file
144
pkg/loomsen-rsnapshot-0.1.1/templates/rsnapshot.erb
Normal file
@ -0,0 +1,144 @@
|
||||
# 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 @host == 'localhost' -%>
|
||||
backup <%= source %> <%=dest%>
|
||||
<% elsif @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
pkg/loomsen-rsnapshot-0.1.1/tests/init.pp
Normal file
12
pkg/loomsen-rsnapshot-0.1.1/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