Commit 53f68419 authored by Micah Anderson's avatar Micah Anderson

install anarcats backupninja module changes

parent 4a59f0db
...@@ -26,6 +26,19 @@ backupninja::rdiff { backup_all: ...@@ -26,6 +26,19 @@ backupninja::rdiff { backup_all:
exclude => '/home/*/.gnupg' exclude => '/home/*/.gnupg'
} }
A remove rdiff backup handler:
backupninja::rdiff { "main":
host => "backup.example.com",
type => "remote",
directory => "/backup/$fqdn",
user => "backup-$hostname",
}
If you configure a backupninja::server, it will collect those users and create
them. We have yet to create proper authorized_keys management to make that
process completely automatic.
At the moment, only the mysql and rdiff handlers have types defined for At the moment, only the mysql and rdiff handlers have types defined for
them, as they're the only handlers we currently use at Solutions First. them, as they're the only handlers we currently use at Solutions First.
Writing others is fairly simple; feel free to contribute them, or ask really Writing others is fairly simple; feel free to contribute them, or ask really
......
class backupninja {
package { 'backupninja':
ensure => '0.9.5-3'
}
}
class backupninja::client {
$configdir = $cfg_override ? {
'' => "/etc/backup.d",
default => $cfg_override,
}
package { 'backupninja':
ensure => '0.9.5-3';
}
file { $configdir:
ensure => directory
}
}
import "*.pp" import "*.pp"
class backupninja {
}
# Mount a labelled partition on a directory as part of a backupninja run.
#
# This type will automatically create an unmount action with an order of 99
# for the destination directory you specify here.
#
# Valid attributes for this type are:
#
# order: The prefix to give to the handler config filename, to set
# order in which the actions are executed during the backup run. Note
# that the value given here should be less than any action which
# requires the filesystem to be mounted!
#
# ensure: Allows you to delete an entry if you don't want it any more
# (but be sure to keep the configdir, name, and order the same, so
# that we can find the correct file to remove).
#
# label: The partition label to mount.
#
# dest: The directory to mount the partition onto.
#
define backupninja::labelmount($order = 10,
$ensure = present,
$label,
$dest
) {
include backupninja::client
file { "${backup::client::configdir}/${order}_${name}.labelmount":
ensure => $ensure,
content => template('backupninja/labelmount.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backup::client::configdir}"]
}
file { "${backup::client::configdir}/99_${name}.umount":
ensure => $ensure,
content => template('backupninja/umount.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${backup::client::configdir}"]
}
# Copy over the handler scripts themselves, since they're not in the
# standard distribution, and are unlikely to end up there any time
# soon because backupninja's "build" system is balls.
file { "/usr/share/backupninja/labelmount":
content => template('backupninja/labelmount.handler'),
owner => root,
group => root,
mode => 0755,
require => Package[backupninja]
}
file { "/usr/share/backupninja/umount":
content => template('backupninja/umount.handler'),
owner => root,
group => root,
mode => 0755,
require => Package[backupninja]
}
}
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
# #
# Valid attributes for this type are: # Valid attributes for this type are:
# #
# configdir: The directory to write the handler config file into.
#
# order: The prefix to give to the handler config filename, to set # order: The prefix to give to the handler config filename, to set
# order in which the actions are executed during the backup run. # order in which the actions are executed during the backup run.
# #
...@@ -16,8 +14,7 @@ ...@@ -16,8 +14,7 @@
# backupninja documentation, with the caveat that hotcopy, sqldump, # backupninja documentation, with the caveat that hotcopy, sqldump,
# and compress take true/false rather than yes/no. # and compress take true/false rather than yes/no.
# #
define backupninja::mysql($configdir = '/etc/backup.d', define backupninja::mysql($order = 10,
$order = 10,
$ensure = present, $ensure = present,
$user = false, $user = false,
$dbusername = false, $dbusername = false,
...@@ -30,23 +27,13 @@ define backupninja::mysql($configdir = '/etc/backup.d', ...@@ -30,23 +27,13 @@ define backupninja::mysql($configdir = '/etc/backup.d',
$compress = false, $compress = false,
$configfile = '/etc/mysql/debian.cnf' $configfile = '/etc/mysql/debian.cnf'
) { ) {
# Make sure the directory that the config goes into exists already include backupninja::client
if defined(File["${configdir}"]) { file { "${backup::client::configdir}/${order}_${name}.mysql":
# Yay for a lack of a negation operator, and the inability
# to provide empty blocks
include null_class
} else {
file { $configdir:
ensure => directory
}
}
file { "${configdir}/${order}_${name}.mysql":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/mysql.conf.erb'), content => template('backupninja/mysql.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${configdir}"] require => File["${backupninja::client::configdir}"]
} }
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
# #
# Valid attributes for this type are: # Valid attributes for this type are:
# #
# configdir: The directory to write the handler config file into.
#
# order: The prefix to give to the handler config filename, to set # order: The prefix to give to the handler config filename, to set
# order in which the actions are executed during the backup run. # order in which the actions are executed during the backup run.
# #
...@@ -17,36 +15,31 @@ ...@@ -17,36 +15,31 @@
# options should be given as arrays if you want to specify multiple # options should be given as arrays if you want to specify multiple
# directories. # directories.
# #
define backupninja::rdiff($configdir = '/etc/backup.d', define backupninja::rdiff($order = 90,
$order = 90,
$ensure = present, $ensure = present,
$user = false, $user = false,
$directory = false, $directory = false,
$host = false, $host = false,
$type = 'local', $type = 'local',
$exclude = false, $exclude = [ "/home/*/.gnupg", "/home/*/.local/share/Trash", "/home/*/.Trash", "/home/*/.thumbnails", "/home/*/.beagle", "/home/*/.aMule", "/home/*/gtk-gnutella-downloads" ],
$include = false, $include = [ "/var/spool/cron/crontabs", "/var/backups", "/etc", "/root", "/home", "/usr/local/*bin", "/var/lib/dpkg/status*" ],
$keep = 30, $keep = 30,
$sshoptions = false, $sshoptions = false,
$options = false $options = false
) { ) {
# Make sure the directory that the config goes into exists already include backupninja::client
if defined(File["${configdir}"]) { case $type {
# Yay for a lack of a negation operator, and the inability 'remote': {
# to provide empty blocks case $host { false: { err("need to define a host for remote backups!") } }
include null_class backupninja::server::sandbox { $user: host => $host, dir => $directory }
} else {
file { $configdir:
ensure => directory
} }
} }
file { "${backupninja::client::configdir}/${order}_${name}.rdiff":
file { "${configdir}/${order}_${name}.rdiff":
ensure => $ensure, ensure => $ensure,
content => template('backupninja/rdiff.conf.erb'), content => template('backupninja/rdiff.conf.erb'),
owner => root, owner => root,
group => root, group => root,
mode => 0600, mode => 0600,
require => File["${configdir}"] require => File["${backupninja::client::configdir}"]
} }
} }
class backupninja::server {
$backupdir = $backupdir_override ? {
'' => "/backup",
default => $backupdir_override,
}
group { "backupninjas":
ensure => "present",
gid => 700
}
file { "$backupdir":
ensure => "directory",
mode => 750, owner => root, group => "backupninjas"
}
User <<| tag == "backupninja-$fqdn" |>>
# this define allows nodes to declare a remote backup sandbox, that have to
# get created on the server
define sandbox($host, $dir = false, $uid = false, $gid = "backupninjas") {
$real_dir = $dir ? {
false => "${backupninja::server::backupdir}/$fqdn",
default => $dir,
}
case $uid {
false: {
@@user { "$name":
ensure => "present",
gid => "$gid",
comment => "$name backup sandbox",
home => "$real_dir",
managehome => true,
shell => "/bin/sh",
password => '*',
require => [ Group['backupninjas'], File["/backup"] ],
tag => "backupninja-$host"
}
}
default: {
@@user { "$name":
ensure => "present",
uid => "$uid",
gid => "$gid",
comment => "$name backup sandbox",
home => "$real_dir",
managehome => true,
shell => "/bin/sh",
password => '*',
require => [ Group['backupninjas'], File["/backup"] ],
tag => "backupninja-$host"
}
}
}
}
}
label = <%= label %>
dest = <%= dest %>
#!/bin/sh
# Mount a block device with the specified label ('label') onto the given
# directory ('dest').
getconf label
getconf dest
if [ ! -b "/dev/disk/by-label/$label" ]; then
halt "No partition labelled '$label' is available"
fi
if [ ! -d "$dest" ]; then
halt "Destination directory does not exist"
fi
mount -t auto /dev/disk/by-label/$label $dest || halt "Mount failed"
#!/bin/sh
# Unmount the specified directory ('dir'), forcefully if necessary.
getconf dir
if ! umount $dir; then
warning "Simple unmount failed for $dir; being forceful"
if ! umount -f $dir; then
warning "Forceful unmount failed for $dir; being lazy"
if ! umount -l $dir; then
warning "Lazy unmount failed for $dir; you're on your own"
fi
fi
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment