summaryrefslogtreecommitdiff
path: root/byteback-mysql/scripts.d/Bytemyback/mysqldump-split-db
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2016-11-09 09:41:50 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2016-11-09 09:41:50 +0000
commit3cc8a83938cd4eae9a196375dca2fd9127f23aa0 (patch)
treefa36b507469bdb1c7b4891e336a6928c59bceab5 /byteback-mysql/scripts.d/Bytemyback/mysqldump-split-db
parent25f3947c16b57a9686500534e44423aab90b0bc7 (diff)
parentc68fe975ab4b47436bd90fa701b83a78793b0f32 (diff)
Merge branch 'master' into 12-fix-btrfs-path
Diffstat (limited to 'byteback-mysql/scripts.d/Bytemyback/mysqldump-split-db')
-rwxr-xr-xbyteback-mysql/scripts.d/Bytemyback/mysqldump-split-db44
1 files changed, 44 insertions, 0 deletions
diff --git a/byteback-mysql/scripts.d/Bytemyback/mysqldump-split-db b/byteback-mysql/scripts.d/Bytemyback/mysqldump-split-db
new file mode 100755
index 0000000..b484ef6
--- /dev/null
+++ b/byteback-mysql/scripts.d/Bytemyback/mysqldump-split-db
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Sys::Hostname;
+
+if ((!@ARGV) or ($ARGV[0] ne 'pre')) {
+ exit;
+}
+
+# Quick mysqldump wrapper to dump individual databases and alert if it fails at all
+my $failed = 0; # only set to 0 once
+my $failed_databases = '';
+my $backup_directory = '/var/backups/byteback/mysqldump-split-db/';
+`mkdir -p $backup_directory`;
+
+my @databases = `echo "SHOW DATABASES" | mysql --defaults-file=/etc/mysql/debian.cnf`;
+shift @databases; # Get rid of 'Databases' title from the top
+foreach my $database (@databases) {
+ chomp($database);
+ next if $database eq "lost+found";
+ next if $database =~ /^#mysql..#lost\+found$/;
+ next if $database =~ /^information_schema$/;
+ next if $database =~ /^performance_schema$/;
+ next if $database =~ /^events$/;
+ next if $database =~ /^cond_instances$/;
+ print "Dumping $database\n";
+ # Need to get rid of this -f once we've fixed errors with views (access denied etc.)
+ my $gzip = -x '/usr/bin/pigz' ? '/usr/bin/pigz' : 'gzip';
+ my $error_code = system("mysqldump --defaults-file=/etc/mysql/debian.cnf --events -f $database | $gzip > ${backup_directory}/${database}.sql.gz\n");
+ if ($error_code) {
+ $failed++;
+ $failed_databases .= " $database";
+ }
+}
+
+my $host = hostname;
+if ($failed) {
+ $host = hostname;
+ system("mauvesend -i mysqldump-${host}-low -r now -s 'mysqldump on ${host} failed for $failed_databases' --detail='Please try running them manually to see what the problem was, and check the mailing list'");
+}
+else {
+ system("mauvesend -i mysqldump-${host}-low -c now -s 'mysqldump on ${host} failed for $failed_databases' --detail='Please try running them manually to see what the problem was, and check the mailing list'");
+}