1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-17 01:12:23 +02:00

Move latest backup link functionality to backup/common module.

This function is needed for new expire features.
This commit is contained in:
Cynthia Shang
2020-04-27 13:17:30 -04:00
committed by David Steele
parent 483838233f
commit ad33f545d1
4 changed files with 44 additions and 16 deletions

View File

@ -39,7 +39,6 @@ Backup Command
Backup constants
***********************************************************************************************************************************/
#define BACKUP_PATH_HISTORY "backup.history"
#define BACKUP_LINK_LATEST "latest"
/**********************************************************************************************************************************
Generate a unique backup label that does not contain a timestamp from a previous backup
@ -1901,21 +1900,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest)
// Create a symlink to the most recent backup if supported. This link is purely informational for the user and is never
// used by us since symlinks are not supported on all storage types.
// -------------------------------------------------------------------------------------------------------------------------
const String *const latestLink = storagePathP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/" BACKUP_LINK_LATEST));
// Remove an existing latest link/file in case symlink capabilities have changed
storageRemoveP(storageRepoWrite(), latestLink);
if (storageFeature(storageRepoWrite(), storageFeatureSymLink))
{
THROW_ON_SYS_ERROR_FMT(
symlink(strPtr(backupLabel), strPtr(latestLink)) == -1, FileOpenError,
"unable to create symlink '%s' to '%s'", strPtr(latestLink), strPtr(backupLabel));
}
// Sync backup path if required
if (storageFeature(storageRepoWrite(), storageFeaturePathSync))
storagePathSyncP(storageRepoWrite(), STORAGE_REPO_BACKUP_STR);
backupLinkLatest(backupLabel);
// Add manifest and save backup.info (infoBackupSaveFile() is responsible for proper syncing)
// -------------------------------------------------------------------------------------------------------------------------

View File

@ -3,14 +3,18 @@ Common Functions and Definitions for Backup and Expire Commands
***********************************************************************************************************************************/
#include "build.auto.h"
#include <unistd.h>
#include "command/backup/common.h"
#include "common/debug.h"
#include "common/log.h"
#include "storage/helper.h"
/***********************************************************************************************************************************
Constants
***********************************************************************************************************************************/
#define DATE_TIME_REGEX "[0-9]{8}\\-[0-9]{6}"
#define BACKUP_LINK_LATEST "latest"
STRING_EXTERN(BACKUP_TYPE_FULL_STR, BACKUP_TYPE_FULL);
STRING_EXTERN(BACKUP_TYPE_DIFF_STR, BACKUP_TYPE_DIFF);
@ -138,3 +142,37 @@ const String *backupTypeStr(BackupType type)
FUNCTION_TEST_RETURN(result);
}
/**********************************************************************************************************************************/
void
backupLinkLatest(const String *backupLabel)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING, backupLabel);
FUNCTION_TEST_END();
MEM_CONTEXT_TEMP_BEGIN()
{
// Create a symlink to the most recent backup if supported. This link is purely informational for the user and is never
// used by us since symlinks are not supported on all storage types.
// -------------------------------------------------------------------------------------------------------------------------
const String *const latestLink = storagePathP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/" BACKUP_LINK_LATEST));
// Remove an existing latest link/file in case symlink capabilities have changed
storageRemoveP(storageRepoWrite(), latestLink);
if (storageFeature(storageRepoWrite(), storageFeatureSymLink))
{
THROW_ON_SYS_ERROR_FMT(
symlink(strPtr(backupLabel), strPtr(latestLink)) == -1, FileOpenError,
"unable to create symlink '%s' to '%s'", strPtr(latestLink), strPtr(backupLabel));
}
// Sync backup path if required
if (storageFeature(storageRepoWrite(), storageFeaturePathSync))
storagePathSyncP(storageRepoWrite(), STORAGE_REPO_BACKUP_STR);
}
MEM_CONTEXT_TEMP_END();
FUNCTION_TEST_RETURN_VOID();
}

View File

@ -46,4 +46,7 @@ String *backupRegExp(BackupRegExpParam param);
BackupType backupType(const String *type);
const String *backupTypeStr(BackupType type);
// Create a symlink to the specified backup (if symlinks are supported)
void backupLinkLatest(const String *backupLabel);
#endif

View File

@ -556,6 +556,7 @@ unit:
command/archive/push/push: full
# ----------------------------------------------------------------------------------------------------------------------------
# --test=backup and --test=backup-common must must be run together to get full coverage of backup/common
- name: backup-common
total: 3
@ -570,6 +571,7 @@ unit:
coverage:
command/backup/backup: full
command/backup/common: full
command/backup/file: full
command/backup/protocol: full