1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Add HRN_STORAGE_MOVE() macro.

Update command/expire test to show how it is used.
This commit is contained in:
Cynthia Shang 2021-06-09 12:41:23 -04:00 committed by David Steele
parent 15dfbf4c1d
commit c5897007c4
3 changed files with 61 additions and 12 deletions

View File

@ -335,6 +335,30 @@ hrnStorageMode(const Storage *const storage, const char *const path, HrnStorageM
hrnTestResultEnd();
}
/**********************************************************************************************************************************/
void
hrnStorageMove(
const Storage *const storage, const char *const fileSource, const char *const fileDest, HrnStorageMoveParam param)
{
hrnTestResultBegin(__func__, false);
ASSERT(storage != NULL);
ASSERT(fileSource != NULL);
ASSERT(fileDest != NULL);
const String *const fileSourceStr = storagePathP(storage, STR(fileSource));
const String *const fileDestStr = storagePathP(storage, STR(fileDest));
printf("move '%s' to '%s'", strZ(fileSourceStr), strZ(fileDestStr));
hrnTestResultComment(param.comment);
// Move (rename) the file
storageMoveP(storage, storageNewReadP(storage, fileSourceStr), storageNewWriteP(storage,fileDestStr));
hrnTestResultEnd();
}
/**********************************************************************************************************************************/
void
hrnStoragePut(

View File

@ -99,6 +99,26 @@ typedef struct HrnStorageModeParam
void hrnStorageMode(const Storage *const storage, const char *const path, HrnStorageModeParam param);
/***********************************************************************************************************************************
Move a file
***********************************************************************************************************************************/
typedef struct HrnStorageMoveParam
{
VAR_PARAM_HEADER;
const char *comment; // Comment
} HrnStorageMoveParam;
#define HRN_STORAGE_MOVE(storage, fileSource, fileDest, ...) \
do \
{ \
hrnTestLogPrefix(__LINE__); \
hrnStorageMove(storage, fileSource, fileDest, (HrnStorageMoveParam){VAR_PARAM_INIT, __VA_ARGS__}); \
} \
while (0)
void hrnStorageMove(
const Storage *const storage, const char *const fileSource, const char *const fileDest, HrnStorageMoveParam param);
/***********************************************************************************************************************************
Create a path
***********************************************************************************************************************************/

View File

@ -876,17 +876,22 @@ testRun(void)
hrnCfgArgKeyRawZ(argList, cfgOptRepoRetentionArchive, 2, "1");
hrnCfgArgKeyRawZ(argList, cfgOptRepoRetentionArchiveType, 2, "diff");
// Create default storage object for dry-run testing
Storage *storageTest = storagePosixNewP(TEST_PATH_STR, .write = true);
harnessLogLevelSet(logLevelDetail);
// Rename backup.info files on repo1 to cause error
HRN_SYSTEM("mv " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE " " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE ".save");
HRN_SYSTEM(
"mv " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE INFO_COPY_EXT " " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE
INFO_COPY_EXT ".save");
HRN_STORAGE_MOVE(
storageTest, TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE, TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE ".save");
HRN_STORAGE_MOVE(
storageTest, TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE INFO_COPY_EXT,
TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE INFO_COPY_EXT ".save");
// Rename archive.info file on repo2 to cause error
HRN_SYSTEM(
"mv " TEST_PATH "/repo2/archive/db/" INFO_ARCHIVE_FILE " " TEST_PATH "/repo2/archive/db/" INFO_ARCHIVE_FILE ".save");
HRN_STORAGE_MOVE(
storageTest, TEST_PATH "/repo2/archive/db/" INFO_ARCHIVE_FILE,
TEST_PATH "/repo2/archive/db/" INFO_ARCHIVE_FILE ".save");
// Configure dry-run
argList2 = strLstDup(argList);
@ -921,8 +926,7 @@ testRun(void)
" archiving scheme.");
// Restore saved archive.info file
HRN_SYSTEM(
"mv " TEST_PATH_REPO "2/archive/db/" INFO_ARCHIVE_FILE ".save " TEST_PATH "/repo2/archive/db/" INFO_ARCHIVE_FILE);
HRN_STORAGE_MOVE(storageTest, "repo2/archive/db/" INFO_ARCHIVE_FILE ".save", "repo2/archive/db/" INFO_ARCHIVE_FILE);
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("expire command - multi-repo, continue to next repo after error");
@ -952,10 +956,11 @@ testRun(void)
"P00 INFO: [DRY-RUN] repo2: 10-2 no archive to remove");
// Restore saved backup.info files
HRN_SYSTEM("mv " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE ".save " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE);
HRN_SYSTEM(
"mv " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE INFO_COPY_EXT ".save " TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE
INFO_COPY_EXT);
HRN_STORAGE_MOVE(
storageTest, TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE ".save", TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE);
HRN_STORAGE_MOVE(
storageTest, TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE INFO_COPY_EXT ".save",
TEST_PATH_REPO "/backup/db/" INFO_BACKUP_FILE INFO_COPY_EXT);
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("expire command - multi-repo, dry run: archive and backups not removed");