pgbackrest.git / summary / log / commit / refs

commit    43098086afd9cbf4e487a18fd2c2d6c486e4e224
Author:   David Steele <david@pgmasters.net>
Date:     Sat Jan 03 21:49:26 2015 +0000

    Implemented timestamp last modified to record the time of the last modified file in the backup.  Also added timestamp-db-start and timestamp-db-stop to for more info.  timestamp-db-start can be used for PITR.


lib/BackRest/Backup.pm | 14 ++++++++++++-- lib/BackRest/Db.pm | 14 +++++++++----- lib/BackRest/File.pm | 2 +- lib/BackRest/Utility.pm | 8 +++++++- test/lib/BackRestTest/BackupTest.pm | 1 + 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/BackRest/Backup.pm b/lib/BackRest/Backup.pm index dfd349bcd..0bb3fea36 100644 --- a/lib/BackRest/Backup.pm +++ b/lib/BackRest/Backup.pm @@ -824,6 +824,8 @@ sub backup_manifest_build $oFile->manifest(PATH_DB_ABSOLUTE, $strDbClusterPath, \%oManifestHash, true); + ${$oBackupManifestRef}{backup}{'timestamp-last-modified'} = 0; + foreach my $strName (sort(keys $oManifestHash{name})) { # Skip certain files during backup @@ -864,6 +866,11 @@ sub backup_manifest_build # ${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{inode} = $oManifestHash{name}{"${strName}"}{inode} + 0; ${$oBackupManifestRef}{"${strSection}"}{"${strName}"}{size} = $oManifestHash{name}{"${strName}"}{size} + 0; + if ($oManifestHash{name}{"${strName}"}{modification_time} + 0 > ${$oBackupManifestRef}{backup}{'timestamp-last-modified'}) + { + ${$oBackupManifestRef}{backup}{'timestamp-last-modified'} = $oManifestHash{name}{"${strName}"}{modification_time} + 0; + } + if (defined(${$oLastManifestRef}{"${strSection}"}{"${strName}"}{size}) && # defined(${$oLastManifestRef}{"${strSection}"}{"${strName}"}{inode}) && defined(${$oLastManifestRef}{"${strSection}"}{"${strName}"}{modification_time})) @@ -927,6 +934,9 @@ sub backup_manifest_build } } } + + ${$oBackupManifestRef}{backup}{'timestamp-last-modified'} = + timestamp_string_get(undef, ${$oBackupManifestRef}{backup}{'timestamp-last-modified'}); } #################################################################################################################################### @@ -1411,7 +1421,7 @@ sub backup } else { - $strArchiveStart = $oDb->backup_start('pg_backrest backup started ' . $strTimestampStart, $bStartFast); + ($strArchiveStart, ${oBackupManifest}{backup}{'timestamp-db-start'}) = $oDb->backup_start('pg_backrest backup started ' . $strTimestampStart, $bStartFast); ${oBackupManifest}{backup}{'archive-start'} = $strArchiveStart; &log(INFO, 'archive start: ' . ${oBackupManifest}{backup}{'archive-start'}); } @@ -1531,7 +1541,7 @@ sub backup if (!$bNoStartStop) { - $strArchiveStop = $oDb->backup_stop(); + ($strArchiveStop, ${oBackupManifest}{backup}{'timestamp-db-stop'}) = $oDb->backup_stop(); ${oBackupManifest}{backup}{'archive-stop'} = $strArchiveStop; &log(INFO, 'archive stop: ' . ${oBackupManifest}{backup}{'archive-stop'}); } diff --git a/lib/BackRest/Db.pm b/lib/BackRest/Db.pm index 2bf9aa47c..bf4bd8131 100644 --- a/lib/BackRest/Db.pm +++ b/lib/BackRest/Db.pm @@ -136,9 +136,11 @@ sub backup_start my $strLabel = shift; my $bStartFast = shift; - return trim($self->psql_execute("set client_min_messages = 'warning';" . - "copy (select pg_xlogfile_name(xlog) from pg_start_backup('${strLabel}'" . - ($bStartFast ? ', true' : '') . ') as xlog) to stdout')); + my @stryField = split("\t", trim($self->psql_execute("set client_min_messages = 'warning';" . + "copy (select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS.US TZ'), pg_xlogfile_name(xlog) from pg_start_backup('${strLabel}'" . + ($bStartFast ? ', true' : '') . ') as xlog) to stdout'))); + + return $stryField[1], $stryField[0]; } #################################################################################################################################### @@ -148,8 +150,10 @@ sub backup_stop { my $self = shift; - return trim($self->psql_execute("set client_min_messages = 'warning';" . - "copy (select pg_xlogfile_name(xlog) from pg_stop_backup() as xlog) to stdout")) + my @stryField = split("\t", trim($self->psql_execute("set client_min_messages = 'warning';" . + "copy (select to_char(clock_timestamp(), 'YYYY-MM-DD HH24:MI:SS.US TZ'), pg_xlogfile_name(xlog) from pg_stop_backup() as xlog) to stdout"))); + + return $stryField[1], $stryField[0]; } 1; diff --git a/lib/BackRest/File.pm b/lib/BackRest/File.pm index 32b2a7cbc..4d10b6f9b 100644 --- a/lib/BackRest/File.pm +++ b/lib/BackRest/File.pm @@ -10,7 +10,7 @@ use Carp; use POSIX qw(ceil); use Net::OpenSSH; -use File::Basename qw(dirname); +use File::Basename qw(dirname basename); use File::Copy qw(cp); use File::Path qw(make_path remove_tree); use Digest::SHA; diff --git a/lib/BackRest/Utility.pm b/lib/BackRest/Utility.pm index f893f6326..66177e0a1 100644 --- a/lib/BackRest/Utility.pm +++ b/lib/BackRest/Utility.pm @@ -295,13 +295,19 @@ sub file_size_format sub timestamp_string_get { my $strFormat = shift; + my $lTime = shift; if (!defined($strFormat)) { $strFormat = '%4d-%02d-%02d %02d:%02d:%02d'; } - my ($iSecond, $iMinute, $iHour, $iMonthDay, $iMonth, $iYear, $iWeekDay, $iYearDay, $bIsDst) = localtime(time); + if (!defined($lTime)) + { + $lTime = time(); + } + + my ($iSecond, $iMinute, $iHour, $iMonthDay, $iMonth, $iYear, $iWeekDay, $iYearDay, $bIsDst) = localtime($lTime); return sprintf($strFormat, $iYear + 1900, $iMonth + 1, $iMonthDay, $iHour, $iMinute, $iSecond); } diff --git a/test/lib/BackRestTest/BackupTest.pm b/test/lib/BackRestTest/BackupTest.pm index 0b9f7fea3..531f9c37a 100755 --- a/test/lib/BackRestTest/BackupTest.pm +++ b/test/lib/BackRestTest/BackupTest.pm @@ -686,6 +686,7 @@ sub BackRestTestBackup_CompareBackup ${$oExpectedManifestRef}{backup}{'timestamp-start'} = $oActualManifest{backup}{'timestamp-start'}; ${$oExpectedManifestRef}{backup}{'timestamp-stop'} = $oActualManifest{backup}{'timestamp-stop'}; + ${$oExpectedManifestRef}{backup}{'timestamp-last-modified'} = $oActualManifest{backup}{'timestamp-last-modified'}; my $strTestPath = BackRestTestCommon_TestPathGet(); [parent: 91b06bef475d]