2012-04-24 07:53:59 +02:00
|
|
|
# Class: mysql::backup
|
|
|
|
#
|
|
|
|
# This module handles ...
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# [*backupuser*] - The name of the mysql backup user.
|
|
|
|
# [*backuppassword*] - The password of the mysql backup user.
|
|
|
|
# [*backupdir*] - The target directory of the mysqldump.
|
|
|
|
#
|
|
|
|
# Actions:
|
|
|
|
# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost'
|
|
|
|
# IDENTIFIED BY 'password';
|
|
|
|
#
|
|
|
|
# Requires:
|
|
|
|
# Class['mysql::config']
|
|
|
|
#
|
|
|
|
# Sample Usage:
|
|
|
|
# class { 'mysql::backup':
|
|
|
|
# backupuser => 'myuser',
|
|
|
|
# backuppassword => 'mypassword',
|
|
|
|
# backupdir => '/tmp/backups',
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
class mysql::backup (
|
2012-04-30 17:07:46 +02:00
|
|
|
$backupuser,
|
|
|
|
$backuppassword,
|
|
|
|
$backupdir,
|
|
|
|
$ensure = 'present'
|
2012-04-24 07:53:59 +02:00
|
|
|
) {
|
|
|
|
|
|
|
|
database_user { "${backupuser}@localhost":
|
|
|
|
ensure => $ensure,
|
|
|
|
password_hash => mysql_password($backuppassword),
|
|
|
|
provider => 'mysql',
|
|
|
|
require => Class['mysql::config'],
|
|
|
|
}
|
|
|
|
|
|
|
|
database_grant { "${backupuser}@localhost":
|
2012-05-04 04:54:32 +02:00
|
|
|
privileges => [ 'Select_priv', 'Reload_priv', 'Lock_tables_priv' ],
|
2012-04-24 07:53:59 +02:00
|
|
|
require => Database_user["${backupuser}@localhost"],
|
|
|
|
}
|
|
|
|
|
|
|
|
cron { 'mysql-backup':
|
|
|
|
ensure => $ensure,
|
|
|
|
command => '/usr/local/sbin/mysqlbackup.sh',
|
|
|
|
user => 'root',
|
|
|
|
hour => 23,
|
|
|
|
minute => 5,
|
|
|
|
require => File['mysqlbackup.sh'],
|
|
|
|
}
|
|
|
|
|
|
|
|
file { 'mysqlbackup.sh':
|
|
|
|
ensure => $ensure,
|
|
|
|
path => '/usr/local/sbin/mysqlbackup.sh',
|
|
|
|
mode => '0700',
|
|
|
|
owner => 'root',
|
|
|
|
group => 'root',
|
|
|
|
content => template('mysql/mysqlbackup.sh.erb'),
|
|
|
|
}
|
|
|
|
|
|
|
|
file { 'mysqlbackupdir':
|
|
|
|
ensure => 'directory',
|
|
|
|
path => $backupdir,
|
|
|
|
mode => '0700',
|
|
|
|
owner => 'root',
|
|
|
|
group => 'root',
|
|
|
|
}
|
|
|
|
}
|