[mylvmbackup] rotate and purge proposal
- From: "Boehm, Matthew" <mboehm@xxxxxxxxxxxxx>
- To: <mylvmbackup@xxxxxxxxxxxxx>
- Date: Fri, 5 Sep 2008 12:10:53 -0500
Again, for us, once a full backup has been completed, we no longer have
use for the previous day's binlogs. So once a successful full backup has
occurred, flush the logs (to close the current one and open a new one)
and then purge up to the new one.
The purge_log code is inside the $snapshot_created if-block because we'd
only want to purge on successful creation of the snapshot.
Had to move the disconnect() call to after the tar/rsync happens but
this is ok as we no longer have the locks on the tables, we can stay
connected and not affect anything.
[root@15000Dmys01 trunk]# bzr diff
=== modified file 'trunk/mylvmbackup.conf'
--- trunk/mylvmbackup.conf 2008-09-03 19:42:21 +0000
+++ trunk/mylvmbackup.conf 2008-09-05 17:02:08 +0000
@@ -60,10 +60,12 @@
pidfile=/var/tmp/mylvmbackup_recoverserver.pid
skip_flush_tables=0
extra_flush_tables=0
+skip_flush_logs=0
skip_mycnf=0
hooksdir=/usr/share/mylvmbackup
skip_hooks=0
keep_snapshot=0
+purge_logs=0
#
# Logging options. The Sys::Syslog module is required for syslog option
=== modified file 'trunk/mylvmbackup.pl.in'
--- trunk/mylvmbackup.pl.in 2008-09-03 20:06:47 +0000
+++ trunk/mylvmbackup.pl.in 2008-09-05 17:03:39 +0000
@@ -43,6 +43,7 @@
my $host;
my $innodb_recover;
my $skip_flush_tables;
+my $skip_flush_logs;
my $skip_hooks;
my $skip_mycnf;
my $extra_flush_tables;
@@ -77,6 +78,8 @@
my $syslog_socktype;
my $syslog_facility;
my $syslog_remotehost;
+my $purge_logs;
+my $current_binlog_filename;
# Load defaults into variables
load_defaults();
@@ -205,6 +208,13 @@
or log_msg ($DBI::errstr, LOG_ERR) && die $DBI::errstr;
}
+unless ($skip_flush_logs == 1)
+{
+ run_hook ("prelogflush");
+ log_msg ("Flushing/Rotating log files...", LOG_INFO);
+ $dbh->do("FLUSH LOGS") or log_msg ($DBI::errstr, LOG_ERR) && die
$DBI::errstr;
+}
+
log_msg ("Taking position record...", LOG_INFO);
&create_pos_file($dbh);
@@ -217,10 +227,6 @@
$dbh->do("UNLOCK TABLES")
or log_msg ($DBI::errstr, LOG_ERR) && die $DBI::errstr;
-run_hook ("predisconnect");
-log_msg ("Disconnecting from database...", LOG_INFO);
-$dbh->disconnect;
-
if ($snapshot_created)
{
run_hook("premount");
@@ -251,8 +257,19 @@
run_hook("backupfailure");
}
}
+
+ if ($purge_logs)
+ {
+ run_hook ("prepurgelogs");
+ log_msg ("Purging binary logs to '$current_binlog_filename'...",
LOG_INFO);
+ $dbh->do("PURGE BINARY LOGS TO '$current_binlog_filename'") or
log_msg ("Purge Failed: $DBI::errstr", LOG_ERR);
+ }
}
+run_hook ("predisconnect");
+log_msg ("Disconnecting from database...", LOG_INFO);
+$dbh->disconnect;
+
run_hook("precleanup");
log_msg ("Cleaning up...", LOG_INFO);
cleanup();
@@ -284,6 +301,7 @@
$innodb_recover=$cfg->val ('misc', 'innodb_recover',
$innodb_recover);
$pidfile=$cfg->val ('misc', 'pidfile', $pidfile);
$skip_flush_tables=$cfg->val ('misc', 'skip_flush_tables',
$skip_flush_tables);
+ $skip_flush_logs=$cfg->val ('misc', 'skip_flush_logs',
$skip_flush_logs);
$extra_flush_tables=$cfg->val ('misc', 'extra_flush_tables',
$extra_flush_tables);
$skip_mycnf=$cfg->val ('misc', 'skip_mycnf', $skip_mycnf);
$rsyncarg=$cfg->val ('misc', 'rsyncarg', $rsyncarg);
@@ -293,6 +311,7 @@
$hooksdir = $cfg->val ('misc', 'hooksdir', $hooksdir);
$skip_hooks=$cfg->val ('misc', 'skip_hooks', $skip_hooks);
$keep_snapshot=$cfg->val ('misc', 'keep_snapshot', $keep_snapshot);
+ $purge_logs = $cfg->val ('misc', 'purge_logs', $purge_logs);
$mountdir=$cfg->val ('fs', 'mountdir', $mountdir);
$backupdir=$cfg->val ('fs', 'backupdir', $backupdir);
@@ -343,6 +362,7 @@
"innodb_recover" => \&innodb_recover,
"pidfile=s" => \$pidfile,
"skip_flush_tables" => \&skip_flush_tables,
+ "skip_flush_logs" => \&skip_flush_logs,
"extra_flush_tables" => \&extra_flush_tables,
"skip_mycnf" => \&skip_mycnf,
"tararg=s" => \$tararg,
@@ -352,6 +372,7 @@
"hooksdir=s" => \$hooksdir,
"skip_hooks" => \&skip_hooks,
"keep_snapshot" => \&keep_snapshot,
+ "purge_logs" => \&purge_logs,
# fs
"mountdir=s" => \$mountdir,
@@ -401,6 +422,7 @@
$innodb_recover=0;
$pidfile = '/var/tmp/mylvmbackup_recoverserver.pid';
$skip_flush_tables=0;
+ $skip_flush_logs=0;
$extra_flush_tables=0;
$skip_mycnf=0;
$tararg='cvzf';
@@ -410,6 +432,7 @@
$hooksdir='/usr/share/mylvmbackup';
$skip_hooks=0;
$keep_snapshot=0;
+ $purge_logs=0;
# fs
$mountdir='/var/tmp/mylvmbackup/mnt/';
@@ -460,6 +483,8 @@
$v = '' if (!defined($v));
my $line = "$pos_prefix:$f=$v\n";
print $fh $line;
+
+ $current_binlog_filename = $v if ($pos_prefix eq
'Master' && $f eq 'File');
}
}
$sth->finish;
@@ -645,6 +670,10 @@
$skip_flush_tables = 1;
}
+sub skip_flush_logs {
+ $skip_flush_logs = 1;
+}
+
sub extra_flush_tables {
$extra_flush_tables = 1;
}
@@ -657,6 +686,10 @@
$keep_snapshot = 1;
}
+sub purge_logs {
+ $puge_logs = 0;
+}
+
sub skip_mycnf {
$skip_mycnf = 1;
}
Matthew Boehm
Senior MySQL DBA, The Planet - Northstar Managed Hosting
Certified MySQL 5.0 DBA
Office: 281-714-4018
Mobile: 832-253-8258
Email: mboehm@xxxxxxxxxxxxx
Other related posts:
- » [mylvmbackup] rotate and purge proposal