Jcrespo has submitted this change and it was merged. Change subject: Copy over mysql_wmf::mylvmbackup to mariadb ......................................................................
Copy over mysql_wmf::mylvmbackup to mariadb Change-Id: I2183b8dbaad1365b99e0f76419a464c7f7406a47 --- A files/mylvmbackup.logrotate A manifests/mylvmbackup.pp A templates/mylvmbackup-prebackup.erb 3 files changed, 133 insertions(+), 0 deletions(-) Approvals: Jcrespo: Looks good to me, approved jenkins-bot: Verified diff --git a/files/mylvmbackup.logrotate b/files/mylvmbackup.logrotate new file mode 100644 index 0000000..37a31e2 --- /dev/null +++ b/files/mylvmbackup.logrotate @@ -0,0 +1,10 @@ +/var/log/mylvmbackup/*.log +{ + rotate 4 + weekly + missingok + notifempty + compress + delaycompress + nocreate +} diff --git a/manifests/mylvmbackup.pp b/manifests/mylvmbackup.pp new file mode 100644 index 0000000..81e2614 --- /dev/null +++ b/manifests/mylvmbackup.pp @@ -0,0 +1,116 @@ +# == Define mariadb::mylvmbackup +# Uses mylvmbackup to periodically rsync an LVM snapshot of the +# MariaDB data directory to a destination. +# +# == Parameters +# +# [*dest*] +# Rsync destination of backup. +# +# [*vgname*] +# Specifies the volume group of the logical volume where the MariaDB data +# directory is located. Default: $::hostname-vg +# +# [*lvname*] +# Specifies the name of the logical volume where the MariaDB data directory is +# located. Default: mariadb +# +# [*mountdir*] +# Path for mounting the snapshot volume to. +# See: --mountdir option for mylvmbackup. +# Default: /var/cache/mylvmbackup/mnt/${title} +# +# [*socket*] +# Path to mariadb socket. Default: /tmp/mysql.sock +# +# ...standard cron resource parameters... +# +# == Usage +# +# # Back up the MariaDB data directory to host.example.org every hour. +# mariadb::mylvmbackup { 'myinstance': +# dest => 'host.example.org::rsync_module/path/to/backups/' +# minute => 0, +# } +# +define mariadb::mylvmbackup( + $dest, + $vgname = "${::hostname}-vg", + $lvname = 'mariadb', + $mountdir = "/var/cache/mylvmbackup/mnt/${title}", + $socket = '/tmp/mysql.sock', + $hour = undef, + $minute = undef, + $month = undef, + $monthday = undef, + $weekday = undef, + $ensure = 'present' +) +{ + require_package('mylvmbackup') + + if !defined(File['/var/log/mylvmbackup']) { + file { '/var/log/mylvmbackup': + ensure => 'directory', + owner => 'root', + group => 'root', + mode => '0755', + } + } + if !defined(Logrotate::Conf['mylvmbackup']) { + logrotate::conf { 'mylvmbackup': + ensure => $ensure, + source => 'puppet:///modules/mariadb/mylvmbackup.logrotate', + } + } + + # The prebackup rsync hook for this mylvmbackup + # job will be stored in this directory. + $hooksdir = "/usr/share/mylvmbackup/${title}" + file { $hooksdir: + ensure => ensure_directory($ensure), + owner => 'root', + group => 'root', + mode => '0555', + } + # Always use the preflush.pm that ships with mylvmbackup + file { "${hooksdir}/preflush.pm": + ensure => ensure_link($ensure), + target => '/usr/share/mylvmbackup/preflush.pm', + require => Package['mylvmbackup'], + } + + # prebackup rsyncs the LVM snapshot to $dest. + file { "${hooksdir}/prebackup": + ensure => $ensure, + owner => 'root', + group => 'root', + mode => '0544', + content => template('mariadb/mylvmbackup-prebackup.erb'), + require => Package['mylvmbackup'], + } + + # --backuptype none will mean no copy of the lvm snapshot will be made + # by mylvmbackup. Instead, this is handled by the prebackup hook, + # which just rsyncs the lvm snapshot to a destination. + # Use flock to make sure this only ever runs one mylvmbackup at a time. + # PATH seems to be funky in flock subshell(?), and mylvmbackup runs + # commands like lvm and mount unqualfied. Reconstruct PATH inside + # of the flock command appropriately. + $command = "/usr/bin/flock -n /var/lock/mylvmbackup-${title} -c 'PATH=/usr/bin:/sbin:/bin /usr/bin/mylvmbackup --socket ${socket} --hooksdir ${hooksdir} --vgname ${vgname} --lvname ${lvname} --mountdir ${mountdir} --backuptype none' >>/var/log/mylvmbackup/${title}.log 2>&1" + cron { "mylvmbackup-${title}": + ensure => $ensure, + command => $command, + user => 'root', + hour => $hour, + minute => $minute, + month => $month, + monthday => $monthday, + weekday => $weekday, + require => [ + Package['mylvmbackup'], + File["${hooksdir}/preflush.pm"], + File["${hooksdir}/prebackup"], + ], + } +} diff --git a/templates/mylvmbackup-prebackup.erb b/templates/mylvmbackup-prebackup.erb new file mode 100644 index 0000000..1d7d74e --- /dev/null +++ b/templates/mylvmbackup-prebackup.erb @@ -0,0 +1,7 @@ +# NOTE: This file is managed by Puppet. + +# This command will be run instead of using one of mylvmbackup's +# default backup types. This allows us to do incremental backups +# directly from mariadb data directories. + +/usr/bin/rsync --delete -rt <%= @mountdir %>/ <%= @dest %>/ -- To view, visit https://gerrit.wikimedia.org/r/308785 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2183b8dbaad1365b99e0f76419a464c7f7406a47 Gerrit-PatchSet: 3 Gerrit-Project: operations/puppet/mariadb Gerrit-Branch: master Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com> Gerrit-Reviewer: Dzahn <dz...@wikimedia.org> Gerrit-Reviewer: Jcrespo <jcre...@wikimedia.org> Gerrit-Reviewer: Marostegui <maroste...@wikimedia.org> Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits