Ottomata has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/277640

Change subject: Add mysql_wmf::mylvmbackup define, use this for backups of 
analytics-meta mysql instance
......................................................................

Add mysql_wmf::mylvmbackup define, use this for backups of analytics-meta mysql 
instance

mylvmbackup's prebackup hook allows us to define our own backup method.  This 
hook runs after
the LVM snapshot has been taken and mounted at $mountdir.  We rsync $mountdir 
to $dest at this
time.

Bug: T127991
Change-Id: I6b0c6e0b819c837b8dbffc97be0c08ee4f66a452
---
M manifests/site.pp
A modules/mysql_wmf/manifests/mylvmbackup.pp
A modules/mysql_wmf/templates/mylvmbackup-prebackup.erb
A modules/role/manifests/analytics_cluster/database/meta/backup.pp
4 files changed, 116 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/40/277640/1

diff --git a/manifests/site.pp b/manifests/site.pp
index 8b80722..654982e 100644
--- a/manifests/site.pp
+++ b/manifests/site.pp
@@ -68,6 +68,7 @@
 node 'analytics1015.eqiad.wmnet' {
     role analytics_cluster::client,
         analytics_cluster::database::meta,
+        analytics_cluster::database::backup,
         analytics_cluster::hive::metastore::database,
         analytics_cluster::oozie::server::database,
         analytics_cluster::hive::metastore,
diff --git a/modules/mysql_wmf/manifests/mylvmbackup.pp 
b/modules/mysql_wmf/manifests/mylvmbackup.pp
new file mode 100644
index 0000000..d5b5073
--- /dev/null
+++ b/modules/mysql_wmf/manifests/mylvmbackup.pp
@@ -0,0 +1,89 @@
+# == Define mysql_wmf::mylvmbackup
+# Uses mylvmbackup to periodically rsync an LVM snapshot of the
+# MySQL data directory to a destination.
+#
+# == Parameters
+#
+# [*dest*]
+#   Rsync destination of backup.
+#
+# [*vgname*]
+#   Specifies the volume group of the logical volume where the MySQL data
+#   directory is located.  Default: $::hostname-vg
+#
+# [*lvname*]
+#   Specifies the name of the logical volume where the MySQL data directory is
+#   located.  Default: mysql
+#
+# [*mountdir*]
+#   Path for mounting the snapshot volume to.
+#   See: --mountdir option for mylvmbackup.
+#   Default: /var/cache/mylvmbackup/mnt/${title}
+#
+# ...standard cron resource parameters...
+#
+# == Usage
+#
+# # Back up the mysql data directory to host.example.org every hour.
+# mysql_wmf::mylvmbackup { 'myinstance':
+#   dest   => 'host.example.org::rsync_module/path/to/backups/'
+#   minute => 0,
+# }
+#
+define mysql_wmf::mylvmbackup(
+    $dest,
+    $vgname   = "${::hostname}-vg",
+    $lvname   = 'mysql',
+    $mountdir = "/var/cache/mylvmbackup/mnt/${title}",
+    $hour     = undef,
+    $minute   = undef,
+    $month    = undef,
+    $monthday = undef,
+    $weekday  = undef,
+    $ensure   = 'present'
+)
+{
+    require_package('mylvmbackup')
+
+    # 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    => 0444,
+        content => template('mysql_wmf/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.
+    $command = "/usr/bin/mylvmbackup --hooksdir ${hooksdir} --vgname ${vgname} 
--lvname ${lvname} --backuptype none",
+    cron { "mylvmbackup-${title}":
+        ensure   => $ensure,
+        command  => $command,
+        user     => 'root',
+        hour     => $hour,
+        minute   => $minute,
+        month    => $month,
+        monthday => $monthday,
+        weekday  => $weekday,
+        require  => File["/usr/share/mylvmbackup/$title/prebackup"],
+    }
+}
diff --git a/modules/mysql_wmf/templates/mylvmbackup-prebackup.erb 
b/modules/mysql_wmf/templates/mylvmbackup-prebackup.erb
new file mode 100644
index 0000000..9a38fbe
--- /dev/null
+++ b/modules/mysql_wmf/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 mysql data directories.
+
+/usr/bin/rsync --progress --delete -av <%= mountdir %>/ <%= destination %>
diff --git a/modules/role/manifests/analytics_cluster/database/meta/backup.pp 
b/modules/role/manifests/analytics_cluster/database/meta/backup.pp
new file mode 100644
index 0000000..d5afec4
--- /dev/null
+++ b/modules/role/manifests/analytics_cluster/database/meta/backup.pp
@@ -0,0 +1,19 @@
+# == Class role::analytics_cluster::database::meta::backup
+# Uses mysql_wmf::mylvmbackup to take backups of the
+# analytics-meta mysql instance.
+#
+# == Parameters
+#
+# [*dest*]
+#   Rsync path for backup.  Default: /srv/backups/mysql/analytics-meta
+#
+class role::analytics_cluster::database::meta::backup(
+    $dest = '/srv/backups/mysql/analytics-meta'
+) {
+    # Take hourly backups of the analytics-meta instance
+    # and rsync those backups to $dest.
+    mysql_wmf::mylvmbackup { 'analytics-meta':
+        dest => $dest,
+        hour => 0,
+    }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/277640
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b0c6e0b819c837b8dbffc97be0c08ee4f66a452
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ottomata <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to