diff --git a/manifests/server/backup.pp b/manifests/server/backup.pp new file mode 100644 index 0000000..a0dd8ca --- /dev/null +++ b/manifests/server/backup.pp @@ -0,0 +1,50 @@ +# == Class: ldap::server::backup +# +# Class to manage OpenLDAP Backup. +# +# +# === Parameters +# +# [ensure] +# *Optional* (defaults to 'present') +# +# [backup_path] +# *Optional* (defaults to /var/backups/ldap) +# +# [backup_dbs] +# *Optional* Hash that specifies the databases to Backup +# in the format: DBnumber => backup_filename.ldif + + +class ldap::server::backup ( + $ensure = present, + $backup_path = '/var/backups/ldap', + $backup_dbs = { 0 => 'config.ldif', + 1 => 'domain.ldif' } +) { + + if !defined (Class['Ldap::Server::Master']) and !defined ( Class['Ldap::Server::Slave']) { + fail('You must include ldap::server::master or ldap::server::slave before ldap::server::backup.') + } + + require ldap + + file { $backup_path: + ensure => $ensure ? { + present => 'directory', + default => $ensure, + }, + mode => '0640', + owner => 'root', + group => $ldap::params::server_group, + } + + file { "${ldap::params::prefix}/ldapbackup.sh": + ensure => $ensure, + mode => 'ug+x', + owner => 'root', + group => $ldap::params::server_group, + content => template("ldap/${ldap::params::prefix}/ldapbackup.sh.erb"), + } + +} diff --git a/templates/etc/ldap/ldapbackup.sh.erb b/templates/etc/ldap/ldapbackup.sh.erb new file mode 120000 index 0000000..359f015 --- /dev/null +++ b/templates/etc/ldap/ldapbackup.sh.erb @@ -0,0 +1 @@ +../openldap/ldapbackup.sh.erb \ No newline at end of file diff --git a/templates/etc/openldap/ldapbackup.sh.erb b/templates/etc/openldap/ldapbackup.sh.erb new file mode 100644 index 0000000..6e067cb --- /dev/null +++ b/templates/etc/openldap/ldapbackup.sh.erb @@ -0,0 +1,9 @@ +#!/bin/bash + +BACKUP_PATH=<%= @backup_path %> +SLAPCAT=`which slapcat` + +<% @backup_dbs.each_pair do |key, value| -%> +nice ${SLAPCAT} -n <%= key %> > ${BACKUP_PATH}/<%= value %> +<% end -%> +chmod 640 ${BACKUP_PATH}/*.ldif