pgbackrest.git / summary / log / commit / refs
commit 7ffade2453afafb98d2d67d3612742e17075947e
Author: David Steele <github@thelabyrinth.net>
Date: Wed Feb 05 16:35:09 2014 +0000
Fixed file mod time and permissions
pg_backrest_backup.pm | 7 ++++---
pg_backrest_file.pm | 28 +++++++++++++++++++++++++++-
test/test.pl | 2 ++
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/pg_backrest_backup.pm b/pg_backrest_backup.pm
index 07f356b69..dc8fb0b38 100644
--- a/pg_backrest_backup.pm
+++ b/pg_backrest_backup.pm
@@ -423,7 +423,7 @@ sub backup_file
{
my $strBackupSourceFile = "${strBackupSourcePath}/${strFile}";
- # If the file is a has reference it does not need to be copied since it can be retrieved from the referenced backup.
+ # If the file has a reference it does not need to be copied since it can be retrieved from the referenced backup.
# However, if hard-linking is turned on the link will need to be created
my $strReference = ${$oBackupManifestRef}{"${strSectionFile}"}{"$strFile"}{reference};
@@ -444,8 +444,9 @@ sub backup_file
# Copy the file from db to backup
&log(DEBUG, " backing up ${strBackupSourceFile}");
- my $lModificationTime = ${$oBackupManifestRef}{"${strSectionFile}"}{"$strFile"}{modification_time};
- file_copy(PATH_DB_ABSOLUTE, $strBackupSourceFile, PATH_BACKUP_TMP, "${strBackupDestinationPath}/${strFile}");
+ file_copy(PATH_DB_ABSOLUTE, $strBackupSourceFile, PATH_BACKUP_TMP, "${strBackupDestinationPath}/${strFile}",
+ undef, ${$oBackupManifestRef}{"${strSectionFile}"}{"$strFile"}{modification_time},
+ $pg_backrest_file::strDefaultFilePermission);
# Write the hash into the backup manifest (if not suppressed)
if (!$bNoChecksum)
diff --git a/pg_backrest_file.pm b/pg_backrest_file.pm
index 7814357ad..fcbcac085 100644
--- a/pg_backrest_file.pm
+++ b/pg_backrest_file.pm
@@ -24,6 +24,7 @@ our @EXPORT = qw(file_init_archive file_init_backup
# Extension and permissions
our $strCompressExtension = "gz";
my $strDefaultPathPermission = "0750";
+our $strDefaultFilePermission = "0640";
# Command strings
my $strCommandChecksum;
@@ -457,6 +458,14 @@ sub file_copy
my $strDestinationPathType = shift;
my $strDestinationFile = shift;
my $bNoCompressionOverride = shift;
+ my $lModificationTime = shift;
+ my $strPermission = shift;
+
+ # Modification time and permissions cannot be set remotely
+ if ((defined($lModificationTime) || defined($strPermission)) && is_remote($strDestinationPathType))
+ {
+ confess &log(ASSERT, "modification time and permissions cannot be set on remote destination file");
+ }
# Generate source, destination and tmp filenames
my $strSource = path_get($strSourcePathType, $strSourceFile);
@@ -567,10 +576,27 @@ sub file_copy
else
{
&log(DEBUG, " file_copy: local '${strCommand}'");
-
system($strCommand) == 0 or confess &log(ERROR, "unable to copy local $strSource to local $strDestinationTmp");
}
}
+
+ # Set the file permission if required (this only works locally for now)
+ if (defined($strPermission))
+ {
+ &log(DEBUG, " file_copy: chmod ${strPermission}");
+
+ system("chmod ${strPermission} ${strDestinationTmp}") == 0
+ or confess &log(ERROR, "unable to set permissions for local ${strDestinationTmp}");
+ }
+
+ # Set the file modification time if required (this only works locally for now)
+ if (defined($lModificationTime))
+ {
+ &log(DEBUG, " file_copy: time ${lModificationTime}");
+
+ utime($lModificationTime, $lModificationTime, $strDestinationTmp)
+ or confess &log(ERROR, "unable to set time for local ${strDestinationTmp}");
+ }
# Move the file from tmp to final destination
file_move(path_type_get($strDestinationPathType) . ":absolute", $strDestinationTmp, $strDestination);
diff --git a/test/test.pl b/test/test.pl
index 33109bd47..6d7991b41 100755
--- a/test/test.pl
+++ b/test/test.pl
@@ -1,5 +1,7 @@
#!/usr/bin/perl
+# /Library/PostgreSQL/9.3/bin/pg_ctl start -o "-c port=7000" -D /Users/backrest/test/backup/db/20140205-103801F/base -l /Users/backrest/test/backup/db/20140205-103801F/base/postgresql.log -w -s
+
#use strict;
use DBI;
use IPC::System::Simple qw(capture);
[parent: c86a61ca3e15]