You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-01 00:25:06 +02:00
The restore command is implemented entirely in C.
For the most part this is a direct migration of the Perl code into C. There is one important behavioral change with regard to how file permissions are handled. The Perl code tried to set ownership as it was in the manifest even when running as an unprivileged user. This usually just led to errors and frustration. The C code works like this: If a restore is run as a non-root user (the typical scenario) then all files restored will belong to the user/group executing pgBackRest. If existing files are not owned by the executing user/group then an error will result if the ownership cannot be updated to the executing user/group. In that case the file ownership will need to be updated by a privileged user before the restore can be retried. If a restore is run as the root user then pgBackRest will attempt to recreate the ownership recorded in the manifest when the backup was made. Only user/group names are stored in the manifest so the same names must exist on the restore host for this to work. If the user/group name cannot be found locally then the user/group of the PostgreSQL data directory will be used and finally root if the data directory user/group cannot be mapped to a name. Reviewed by Cynthia Shang.
This commit is contained in:
@ -600,6 +600,9 @@ sub run
|
||||
# Restore will set invalid user and group to root since the base path user/group are also invalid
|
||||
if (!$bRemote)
|
||||
{
|
||||
$oManifest{&MANIFEST_SECTION_TARGET_PATH}{&MANIFEST_TARGET_PGDATA}{&MANIFEST_SUBKEY_USER} = 'root';
|
||||
$oManifest{&MANIFEST_SECTION_TARGET_PATH}{&MANIFEST_TARGET_PGDATA}{&MANIFEST_SUBKEY_GROUP} = 'root';
|
||||
|
||||
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{MANIFEST_TARGET_PGDATA . '/base/1/' . DB_FILE_PGVERSION}
|
||||
{&MANIFEST_SUBKEY_USER} = 'root';
|
||||
$oManifest{&MANIFEST_SECTION_TARGET_FILE}{MANIFEST_TARGET_PGDATA . '/base/16384/' . DB_FILE_PGVERSION}
|
||||
@ -699,7 +702,7 @@ sub run
|
||||
|
||||
$oHostDbMaster->restore(
|
||||
'error on existing linked file', $strFullBackup,
|
||||
{rhExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_PATH_NOT_EMPTY,
|
||||
{rhExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_FILE_EXISTS,
|
||||
strOptionalParam => '--log-level-console=warn --link-all'});
|
||||
|
||||
executeTest('rm ' . $oHostDbMaster->dbPath() . '/pg_config/pg_hba.conf');
|
||||
@ -725,6 +728,8 @@ sub run
|
||||
# testFileCreate(
|
||||
# $oHostDbMaster->dbPath() . '/pg_config/pg_hba.conf', "CONTENTS2\n", $lTime - 100);
|
||||
|
||||
$oHostDbMaster->dbFileCreate(\%oManifest, MANIFEST_TARGET_PGDATA, 'backup.manifest', '');
|
||||
|
||||
$oHostDbMaster->restore(
|
||||
'restore all links --link-all and mapping', $strFullBackup,
|
||||
{rhExpectedManifest => \%oManifest, bDelta => true,
|
||||
@ -1074,10 +1079,11 @@ sub run
|
||||
$oRemapHash{&MANIFEST_TARGET_PGTBLSPC . '/1'} = $oHostDbMaster->tablespacePath(1, 2);
|
||||
$oRemapHash{&MANIFEST_TARGET_PGTBLSPC . '/2'} = $oHostDbMaster->tablespacePath(2, 2);
|
||||
|
||||
# At this point the $PG_DATA permissions have been reset to 0600
|
||||
# At this point the $PG_DATA permissions have been reset to 0700
|
||||
if (!$bRemote)
|
||||
{
|
||||
delete($oManifest{&MANIFEST_SECTION_TARGET_PATH}{&MANIFEST_TARGET_PGDATA}{&MANIFEST_SUBKEY_MODE});
|
||||
$oManifest{&MANIFEST_SECTION_TARGET_PATH}{&MANIFEST_TARGET_PGDATA}{&MANIFEST_SUBKEY_MODE} = '0777';
|
||||
$oManifest{&MANIFEST_SECTION_TARGET_PATH}{&MANIFEST_TARGET_PGTBLSPC}{&MANIFEST_SUBKEY_MODE} = '0777';
|
||||
}
|
||||
|
||||
$oHostDbMaster->restore(
|
||||
@ -1340,16 +1346,9 @@ sub run
|
||||
$oRemapHash{&MANIFEST_TARGET_PGDATA} = $strDbPath;
|
||||
delete($oRemapHash{&MANIFEST_TARGET_PGTBLSPC . '/2'});
|
||||
|
||||
$oHostDbMaster->restore(
|
||||
'no tablespace remap - error when tablespace dir does not exist', cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET),
|
||||
{rhExpectedManifest => \%oManifest, rhRemapHash => \%oRemapHash, iExpectedExitStatus => ERROR_PATH_MISSING,
|
||||
bTablespace => false, strOptionalParam => '--tablespace-map-all=../../tablespace'});
|
||||
|
||||
storageTest()->pathCreate($oHostDbMaster->dbBasePath(2) . '/tablespace', {strMode => '0700'});
|
||||
|
||||
$oHostDbMaster->restore(
|
||||
'no tablespace remap', cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET),
|
||||
{rhExpectedManifest => \%oManifest, bTablespace => false,
|
||||
{rhExpectedManifest => \%oManifest, rhRemapHash => \%oRemapHash, bTablespace => false,
|
||||
strOptionalParam => '--tablespace-map-all=../../tablespace'});
|
||||
|
||||
$oManifest{&MANIFEST_SECTION_BACKUP_TARGET}{'pg_tblspc/2'}{&MANIFEST_SUBKEY_PATH} = '../../tablespace/ts2';
|
||||
|
Reference in New Issue
Block a user