1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2025-09-13 07:49:29 +00:00

21 Commits
0.4.0 ... 0.5.0

Author SHA1 Message Date
Norbert Varzariu
e8a287c4f8 bump version to 0.5.0 2016-01-22 09:10:12 +01:00
Norbert Varzariu
a28b27c505 Merge branch 'feature/rewrite_to_use_deep_merge' into develop
- rewrite large parts of cron file generation
- now using deep_merge to merge possible overrides into the default hash
  (eliminates a lit of spaghetti code)
2016-01-22 09:08:28 +01:00
Norbert Varzariu
0235f202b4 rewrite cron file generation using deep_merge (why is this function undocumented?) 2016-01-22 09:08:12 +01:00
Norbert Varzariu
80d1756087 Merge branch 'release/0.4.2' into develop 2016-01-21 15:19:31 +01:00
Norbert Varzariu
413ca69760 bump version to 0.4.2 2016-01-21 15:19:02 +01:00
Norbert Varzariu
c7756458f1 Merge branch 'feature/rewrite_to_use_deep_merge' 2016-01-21 15:15:12 +01:00
Norbert Varzariu
d5e4ebbb9c add backup script templates 2016-01-21 15:11:10 +01:00
Norbert Varzariu
d6ea0821c0 Merge branch 'release/0.4.1' into develop 2016-01-20 11:45:58 +01:00
Norbert Varzariu
2cccc86433 Merge branch 'release/0.4.1' 2016-01-20 11:45:41 +01:00
Norbert Varzariu
e39f638dfa bump version to 0.4.1 2016-01-20 11:45:31 +01:00
Norbert Varzariu
ab9ec44ced ensure in-/exclude file is absent if no in-/excludes given 2016-01-20 11:41:59 +01:00
Norbert Varzariu
941036d986 testing 2016-01-20 10:38:27 +01:00
Norbert Varzariu
396d71cb8e testing 2016-01-20 10:27:29 +01:00
Norbert Varzariu
d1008c99eb add warning to README about configuration change in 0.4.0 2016-01-19 17:39:46 +01:00
Norbert Varzariu
ed9de1e8cd Merge branch 'release/0.4.0' into develop 2016-01-19 17:38:14 +01:00
Norbert Varzariu
d5d7507fa9 Merge branch 'release/0.4.0' 2016-01-19 17:38:03 +01:00
Norbert Varzariu
5f65000606 Merge branch 'develop' 2016-01-18 20:53:46 +01:00
Norbert Varzariu
fce58cf09a Merge branch 'develop' 2016-01-18 19:58:32 +01:00
Norbert Varzariu
5cccf8200d Merge branch 'release/0.3.2' 2016-01-18 19:56:18 +01:00
Norbert Varzariu
ae2083c6ee Merge branch 'develop' 2016-01-18 12:11:28 +01:00
Norbert Varzariu
8e62ff526e Merge branch 'release/0.3.1' 2016-01-18 11:23:21 +01:00
9 changed files with 70 additions and 60 deletions

View File

@@ -1,5 +1,7 @@
# rsnapshot # rsnapshot
## NOTE: ! Configuration for backup_scripts changed with version 0.4.0 (it was pretty useless in prior versions) !
#### Table of Contents #### Table of Contents
1. [Overview](#overview) 1. [Overview](#overview)

View File

@@ -5,12 +5,13 @@ class rsnapshot::config (
$hosts = $rsnapshot::hosts, $hosts = $rsnapshot::hosts,
$cron_dir = $rsnapshot::cron_dir, $cron_dir = $rsnapshot::cron_dir,
) { ) {
# these are global settings, no point in setting them per host # these are global settings, no point in setting them per host
$config_version = $rsnapshot::params::config_version $config_version = $rsnapshot::params::config_version
$lockpath = pick($rsnapshot::lockpath, $rsnapshot::params::config_lockpath, '/var/run/rsnapshot') $lockpath = pick($rsnapshot::lockpath, $rsnapshot::params::config_lockpath, '/var/run/rsnapshot')
$conf_d = pick($rsnapshot::conf_d, $rsnapshot::params::conf_d, '/etc/rsnapshot') $conf_d = pick($rsnapshot::conf_d, $rsnapshot::params::conf_d, '/etc/rsnapshot')
$snapshot_root = pick($hosts['snapshot_root'], $rsnapshot::snapshot_root, '/backup') $snapshot_root = pick($hosts['snapshot_root'], $rsnapshot::snapshot_root, '/backup')
$default_cron = assert_empty_hash($::rsnapshot::cron)
# make sure lock path and conf path exist # make sure lock path and conf path exist
file { $conf_d: file { $conf_d:
ensure => 'directory', ensure => 'directory',
@@ -33,7 +34,7 @@ class rsnapshot::config (
$hosts_clean.each |String $host, $hash | { $hosts_clean.each |String $host, $hash | {
$backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user) $backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user)
$default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup) $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_levels = pick($hash['backup_levels'], $rsnapshot::backup_levels, 'weekly')
$backup = $hash['backup'] $backup = $hash['backup']
$backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults) $backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults)
$cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp) $cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp)
@@ -66,9 +67,9 @@ class rsnapshot::config (
$one_fs = pick_undef($hash['one_fs'], $rsnapshot::params::config_one_fs) $one_fs = pick_undef($hash['one_fs'], $rsnapshot::params::config_one_fs)
$interval = pick($hash['interval'], $rsnapshot::params::config_interval) $interval = pick($hash['interval'], $rsnapshot::params::config_interval)
$retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain) $retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain)
$include = pick_undef($hash['include'], $rsnapshot::params::config_include) $include = pick($hash['include'], [])
$exclude = pick_undef($hash['exclude'], $rsnapshot::params::config_exclude) $exclude = pick($hash['exclude'], [])
$include_file = pick_undef($hash['include_file'], $rsnapshot::params::config_include_file) $include_file = pick($hash['include_file'], $rsnapshot::params::config_include_file, "${conf_d}/${host}.include")
$exclude_file = pick($hash['exclude_file'], $rsnapshot::params::config_exclude_file, "${conf_d}/${host}.exclude") $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) $link_dest = pick_undef($hash['link_dest'], $rsnapshot::params::config_link_dest)
$sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first) $sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first)
@@ -108,19 +109,22 @@ class rsnapshot::config (
$use_lazy_deletes_num = bool2num($use_lazy_deletes) $use_lazy_deletes_num = bool2num($use_lazy_deletes)
} }
if $include != '' { $real_include = $rsnapshot::include + $include
unless empty($real_include) {
file { $include_file: file { $include_file:
ensure => 'file', ensure => 'file',
content => template('rsnapshot/include.erb'), content => template('rsnapshot/include.erb'),
} }
} }
if $exclude != '' { $real_exclude = $rsnapshot::exclude + $exclude
unless empty($real_exclude) {
file { $exclude_file: file { $exclude_file:
ensure => 'file', ensure => 'file',
content => template('rsnapshot/exclude.erb'), content => template('rsnapshot/exclude.erb'),
} }
} }
concat { $config: concat { $config:
} }
concat::fragment { "${config} for ${host}": concat::fragment { "${config} for ${host}":
@@ -158,57 +162,16 @@ class rsnapshot::config (
concat { $cronfile: concat { $cronfile:
} }
# create cron files for each backup level # create cron files for each backup level
# merge possible cron definitions to one
$real_cron = deep_merge($rsnapshot::params::cron, $rsnapshot::cron, $hash[cron])
$backup_levels.each |String $level| { $backup_levels.each |String $level| {
$minute = rand_from_array($real_cron[$level][minute], "${host}.${level}.minute")
$hour = rand_from_array($real_cron[$level][hour], "${host}.${level}.hour")
$monthday = rand_from_array($real_cron[$level][monthday], "${host}.${level}.monthday")
$month = rand_from_array($real_cron[$level][month], "${host}.${level}.month")
$weekday = rand_from_array($real_cron[$level][weekday], "${host}.${level}.weekday")
# allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly
if has_key($hash,cron){
if has_key($hash[cron], $level) {
$cron = $hash[cron][$level]
} else {
if has_key($default_cron, $level) {
$cron = $default_cron[$level]
} else {
$cron = $rsnapshot::params::cron[$level]
}
}
} else {
if has_key($default_cron, $level) {
$cron = $default_cron[$level]
} else {
$cron = $rsnapshot::params::cron[$level]
}
}
if has_key($cron, minute) {
$c_min = $cron[minute]
} else {
$c_min = $rsnapshot::params::cron[$level][minute]
}
if has_key($cron, hour) {
$c_hour = $cron[hour]
} else {
$c_hour = $rsnapshot::params::cron[$level][hour]
}
if has_key($cron, monthday) {
$c_monthday = $cron[monthday]
} else {
$c_monthday = $rsnapshot::params::cron[$level][monthday]
}
if has_key($cron, month) {
$c_month = $cron[month]
} else {
$c_month = $rsnapshot::params::cron[$level][month]
}
if has_key($cron, weekday) {
$c_weekday = $cron[weekday]
} else {
$c_weekday = $rsnapshot::params::cron[$level][weekday]
}
$minute = rand_from_array($c_min, "${host}.${level}.minute")
$hour = rand_from_array($c_hour, "${host}.${level}.hour")
$monthday = rand_from_array($c_monthday, "${host}.${level}.monthday")
$month = rand_from_array($c_month, "${host}.${level}.month")
$weekday = rand_from_array($c_weekday, "${host}.${level}.weekday")
concat::fragment { "${host}.${level}": concat::fragment { "${host}.${level}":
target => $cronfile, target => $cronfile,
content => template('rsnapshot/cron.erb'), content => template('rsnapshot/cron.erb'),

View File

@@ -14,8 +14,10 @@ class rsnapshot (
$package_ensure = $rsnapshot::params::package_ensure, $package_ensure = $rsnapshot::params::package_ensure,
$cron = $rsnapshot::params::cron, $cron = $rsnapshot::params::cron,
$backup_scripts = $rsnapshot::params::backup_scripts, $backup_scripts = $rsnapshot::params::backup_scripts,
$include = $rsnapshot::params::config_include,
$exclude = $rsnapshot::params::config_exclude, $exclude = $rsnapshot::params::config_exclude,
$snapshot_root = $rsnapshot::params::config_snapshot_root, $snapshot_root = $rsnapshot::params::config_snapshot_root,
$backup_levels = $rsnapshot::params::config_backup_levels,
) inherits rsnapshot::params { ) inherits rsnapshot::params {
$default_backup_scripts = $rsnapshot::params::backup_scripts + $backup_scripts $default_backup_scripts = $rsnapshot::params::backup_scripts + $backup_scripts

View File

@@ -1,6 +1,6 @@
{ {
"name": "loomsen-rsnapshot", "name": "loomsen-rsnapshot",
"version": "0.4.0", "version": "0.5.0",
"author": "loomsen", "author": "loomsen",
"summary": "Configures rsnapshot.", "summary": "Configures rsnapshot.",
"license": "Apache-2.0", "license": "Apache-2.0",

View File

@@ -1,3 +1,3 @@
<% @exclude.each do |exc| -%> <% @real_exclude.each do |exc| -%>
<%= exc %> <%= exc %>
<% end %> <% end %>

View File

@@ -1,3 +1,3 @@
<% @include.each do |inc| -%> <% @real_include.each do |inc| -%>
<%= inc %> <%= inc %>
<% end %> <% end %>

10
templates/misc.sh.erb Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
# add custom stuff here
# FIXME: remember to concat for custom stuff after the last line of the puppet generated script
<% if @osfamily == 'RedHat' -%>
ssh <%=@host-%> rpm -qa --qf='%{name},' > packages.txt
<%end-%>
#
#
#
# ++++++++++++++++++++++++++++++++++++++++++++

16
templates/mysql.sh.erb Normal file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
# written by Norbert Varzariu <loomsen@gmail.com>
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
#
host=<%=@host%>
user=<%=@dbbackup_user%>
pass=<%=@dbbackup_password%>
dbs=( $(mysql -h "$host" -u "$user" -p"$pass" -e 'show databases' | sed '1d;/information_schema/d;/performance_schema/d') )
for db in "${dbs[@]}"; do
mysqldump --host="$host" --user="$user" --password="$pass" --single-transaction --quick --routines --ignore-table=mysql.event "$db" > "$db".sql
wait
pbzip2 -p3 "$db".sql
done

17
templates/psql.sh.erb Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# written by Norbert Varzariu <loomsen@gmail.com>
# This Script is triggered by rsnapshot and dumps the specified dbs on the configured host.
#
host=<%=@host%>
user=<%=@dbbackup_user%>
pass=<%=@dbbackup_password%>
PGPASSWORD="$pass"
dbs=( $(psql -h "$host" -U "$user" -Atc "SELECT datname FROM pg_database WHERE NOT datistemplate AND datname <> 'postgres'") )
for db in "${dbs[@]}"; do
ssh -l root "$host" "pg_dump -U ${user} -Fc ${db}" > "$db".sql
wait
pbzip2 -p3 "$db".sql
done