Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***********************************************************************************************************************************
Annotate Command
***********************************************************************************************************************************/
#include <build.h>
 
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
 
#include "command/annotate/annotate.h"
#include "command/backup/backup.h"
#include "common/crypto/cipherBlock.h"
#include "common/debug.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/regExp.h"
#include "config/config.h"
#include "info/helper.h"
#include "storage/helper.h"
 
/**********************************************************************************************************************************/
FN_EXTERN void
cmdAnnotate(void)
{
    FUNCTION_LOG_VOID(logLevelDebug);
 
    MEM_CONTEXT_TEMP_BEGIN()
    {
        // Initialize the repo index
        unsigned int repoIdxMin = 0;
        unsigned int repoIdxMax = cfgOptionGroupIdxTotal(cfgOptGrpRepo) - 1;
 
        // If the repo was specified then set index to the array location and max to loop only once
        if (cfgOptionTest(cfgOptRepo))
        {
            repoIdxMin = cfgOptionGroupIdxDefault(cfgOptGrpRepo);
            repoIdxMax = repoIdxMin;
        }
 
        // Check the backup label format
        const String *const backupLabel = cfgOptionStr(cfgOptSet);
 
        if (!regExpMatchOne(backupRegExpP(.full = true, .differential = true, .incremental = true), backupLabel))
            THROW_FMT(OptionInvalidValueError, "'%s' is not a valid backup label format", strZ(backupLabel));
 
        // Track the number of backup sets to update in the backup info file and any errors that may occur
        unsigned int backupTotalProcessed = 0;
        unsigned int errorTotal = 0;
 
        for (unsigned int repoIdx = repoIdxMin; repoIdx <= repoIdxMax; repoIdx++)
        {
            TRY_BEGIN()
            {
                // Attempt to load the backup info file
                InfoBackup *const infoBackup = infoBackupRepoIdxP(repoIdx, .reconstruct = true);
 
                if (infoBackupLabelExists(infoBackup, backupLabel))
                {
                    // Backup label found in backup.info
                    backupTotalProcessed++;
 
                    LOG_INFO_FMT(
                        "backup set '%s' to annotate found in %s",
                        strZ(backupLabel), cfgOptionGroupName(cfgOptGrpRepo, repoIdx));
 
                    // Update annotations
                    infoBackupDataAnnotationSet(infoBackup, backupLabel, cfgOptionKv(cfgOptAnnotation));
 
                    // Write the updated backup info
                    infoBackupRepoIdxSave(repoIdx);
                }
            }
            CATCH_ANY()
            {
                LOG_ERROR_FMT(errorTypeCode(errorType()), "%s: %s", cfgOptionGroupName(cfgOptGrpRepo, repoIdx), errorMessage());
                errorTotal++;
            }
            TRY_END();
        }
 
        // Error if any errors encountered on one or more repos
        if (errorTotal > 0)
            THROW_FMT(CommandError, CFGCMD_ANNOTATE " command encountered %u error(s), check the log file for details", errorTotal);
 
        if (backupTotalProcessed == 0)
            THROW(BackupSetInvalidError, "no backup set to annotate found");
    }
    MEM_CONTEXT_TEMP_END();
 
    FUNCTION_LOG_RETURN_VOID();
}