diff --git a/README.md b/README.md index 772f3c1f5..76e18b428 100644 --- a/README.md +++ b/README.md @@ -16,24 +16,16 @@ Put something here, there are people to recognize! * Async archive-get. -* Database restore. - -* --version param (with with version written into backup.manifest). - * Threading for archive-get and archive-put. * Add configurable sleep to archiver process to reduce ssh connections. * Fix bug where .backup files written into old directories can cause the archive process to error. -* Default restore.conf is written to each backup. +* Default restore.conf is written to each backup (with everything commented out). * Able to set timeout on ssh connection in config file. -* File->wait() function. Waits for a file or directory to exist with configurable retry and timeout. - -* Missing files during backup generate an ERROR in the log - the backup works but this message should probably be suppressed. - ## required perl modules * Net::OpenSSH diff --git a/bin/pg_backrest.pl b/bin/pg_backrest.pl index ff1822d30..81003ab23 100755 --- a/bin/pg_backrest.pl +++ b/bin/pg_backrest.pl @@ -71,6 +71,7 @@ use constant my $strConfigFile; # Configuration file my $strStanza; # Stanza in the configuration file to load my $strType; # Type of backup: full, differential (diff), incremental (incr) +my $bVersion = false; # Display the version and exit # Test parameters - not for general use my $bNoFork = false; # Prevents the archive process from forking when local archiving is enabled @@ -80,13 +81,21 @@ my $iTestDelay = 5; # Amount of time to delay after hitting a test point (th GetOptions ("config=s" => \$strConfigFile, "stanza=s" => \$strStanza, "type=s" => \$strType, + "version" => \$bVersion, - # Test parameters - not for general use + # Test parameters - not for general use (and subject to change without notice) "no-fork" => \$bNoFork, "test" => \$bTest, "test-delay=s" => \$iTestDelay) or confess("Error in command line arguments\n"); +# Display the version and exit if requested +if ($bVersion) +{ + print 'pg_backrest ' . version_get() . "\n"; + exit 0; +} + # Set test parameters test_set($bTest, $iTestDelay); diff --git a/lib/BackRest/Backup.pm b/lib/BackRest/Backup.pm index 457610717..7b2885d61 100644 --- a/lib/BackRest/Backup.pm +++ b/lib/BackRest/Backup.pm @@ -1268,7 +1268,7 @@ sub backup my $bStartFast = shift; # Record timestamp start - my $strTimestampStart = timestamp_get(); + my $strTimestampStart = timestamp_string_get(); # Not supporting remote backup hosts yet if ($oFile->is_remote(PATH_BACKUP)) @@ -1339,6 +1339,12 @@ sub backup $oFile->path_create(PATH_BACKUP_TMP); } + # Write the VERSION file + my $hVersionFile; + open($hVersionFile, '>', "${strBackupTmpPath}/version") or confess "unable to open version file"; + print $hVersionFile version_get(); + close($hVersionFile); + # Save the backup conf file first time - so we can see what is happening in the backup config_save($strBackupConfFile, \%oBackupManifest); @@ -1397,14 +1403,14 @@ sub backup if ($strType eq "full" || !defined($strBackupLastPath)) { - $strBackupPath = date_string_get() . "F"; + $strBackupPath = timestamp_file_string_get() . "F"; $strType = "full"; } else { $strBackupPath = substr($strBackupLastPath, 0, 16); - $strBackupPath .= "_" . date_string_get(); + $strBackupPath .= "_" . timestamp_file_string_get(); if ($strType eq "differential") { @@ -1417,7 +1423,7 @@ sub backup } # Record timestamp stop in the config - ${oBackupManifest}{backup}{timestamp_stop} = timestamp_get(); + ${oBackupManifest}{backup}{timestamp_stop} = timestamp_string_get(); ${oBackupManifest}{backup}{label} = $strBackupPath; # Save the backup conf file final time diff --git a/lib/BackRest/Utility.pm b/lib/BackRest/Utility.pm index e0240b341..b3a299a6c 100644 --- a/lib/BackRest/Utility.pm +++ b/lib/BackRest/Utility.pm @@ -19,10 +19,10 @@ use BackRest::Exception; use Exporter qw(import); our @EXPORT = qw(version_get - data_hash_build trim common_prefix wait_for_file date_string_get file_size_format execute + data_hash_build trim common_prefix wait_for_file file_size_format execute log log_file_set log_level_set test_set test_check lock_file_create lock_file_remove - config_save config_load timestamp_get + config_save config_load timestamp_string_get timestamp_file_string_get TRACE DEBUG ERROR ASSERT WARN INFO OFF true false TEST TEST_ENCLOSE TEST_MANIFEST_BUILD); @@ -258,7 +258,7 @@ sub common_prefix last; } - $iCommonLen ++; + $iCommonLen++; } return $iCommonLen; @@ -290,20 +290,28 @@ sub file_size_format } #################################################################################################################################### -# DATE_STRING_GET - Get the date and time string +# TIMESTAMP_STRING_GET - Get backrest standard timestamp (or formatted as specified #################################################################################################################################### -sub date_string_get +sub timestamp_string_get { my $strFormat = shift; if (!defined($strFormat)) { - $strFormat = "%4d%02d%02d-%02d%02d%02d"; + $strFormat = "%4d-%02d-%02d %02d:%02d:%02d"; } - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + my ($iSecond, $iMinute, $iHour, $iMonthDay, $iMonth, $iYear, $iWeekDay, $iYearDay, $bIsDst) = localtime(time); - return(sprintf($strFormat, $year+1900, $mon+1, $mday, $hour, $min, $sec)); + return sprintf($strFormat, $iYear + 1900, $iMonth + 1, $iMonthDay, $iHour, $iMinute, $iSecond); +} + +#################################################################################################################################### +# TIMESTAMP_FILE_STRING_GET - Get the date and time string formatted for filenames +#################################################################################################################################### +sub timestamp_file_string_get +{ + return timestamp_string_get("%4d%02d%02d-%02d%02d%02d"); } #################################################################################################################################### @@ -318,7 +326,7 @@ sub log_file_set mkdir(dirname($strFile)) or die "unable to create directory for log file ${strFile}"; } - $strFile .= "-" . date_string_get("%4d%02d%02d") . ".log"; + $strFile .= "-" . timestamp_string_get("%4d%02d%02d") . ".log"; my $bExists = false; if (-e $strFile) @@ -400,16 +408,6 @@ sub test_check return index($strLog, TEST_ENCLOSE . '-' . $strTest . '-' . TEST_ENCLOSE) != -1; } -#################################################################################################################################### -# TIMESTAMP_GET - Get backrest standard timestamp -#################################################################################################################################### -sub timestamp_get -{ - my ($iSecond, $iMinute, $iHour, $iMonthDay, $iMonth, $iYear, $iWeekDay, $iYearDay, $bIsDst) = localtime(time); - - return sprintf("%4d-%02d-%02d %02d:%02d:%02d", $iYear + 1900, $iMonth + 1, $iMonthDay, $iHour, $iMinute, $iSecond); -} - #################################################################################################################################### # LOG - log messages #################################################################################################################################### @@ -459,7 +457,7 @@ sub log # Format the message text my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); - $strMessageFormat = timestamp_get() . sprintf(" T%02d", threads->tid()) . + $strMessageFormat = timestamp_string_get() . sprintf(" T%02d", threads->tid()) . (" " x (7 - length($strLevel))) . "${strLevel}: ${strMessageFormat}" . (defined($iCode) ? " (code ${iCode})" : "") . "\n";