1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-05 15:05:48 +02:00
pgbackrest/src/main.c

122 lines
4.1 KiB
C
Raw Normal View History

/***********************************************************************************************************************************
Main
***********************************************************************************************************************************/
2017-11-28 21:44:05 -05:00
#include <stdio.h>
#include <stdlib.h>
#include "command/archive/get/get.h"
#include "command/archive/push/push.h"
2018-01-23 13:34:24 -05:00
#include "command/help/help.h"
#include "command/info/info.h"
#include "command/command.h"
#include "common/debug.h"
2017-11-28 21:44:05 -05:00
#include "common/error.h"
2018-01-17 09:15:51 -05:00
#include "common/exit.h"
2017-11-28 21:44:05 -05:00
#include "config/config.h"
2018-01-16 13:52:20 -05:00
#include "config/load.h"
#include "postgres/interface.h"
#include "perl/exec.h"
2017-11-28 21:44:05 -05:00
#include "version.h"
int
main(int argListSize, const char *argList[])
{
#ifdef WITH_BACKTRACE
stackTraceInit(argList[0]);
#endif
FUNCTION_DEBUG_BEGIN(logLevelDebug);
FUNCTION_DEBUG_PARAM(INT, argListSize);
FUNCTION_DEBUG_PARAM(CHARPY, argList);
FUNCTION_DEBUG_END();
// Initialize command with the start time
cmdInit();
volatile bool result = 0;
volatile bool error = false;
// Initialize exit handler
exitInit();
2017-11-28 21:44:05 -05:00
TRY_BEGIN()
{
2018-01-16 13:52:20 -05:00
// Load the configuration
// -------------------------------------------------------------------------------------------------------------------------
cfgLoad((unsigned int)argListSize, argList);
2017-11-28 21:44:05 -05:00
2018-01-23 13:34:24 -05:00
// Display help
// -------------------------------------------------------------------------------------------------------------------------
if (cfgCommandHelp())
{
cmdHelp();
}
2017-11-28 21:44:05 -05:00
// Display version
2018-01-16 13:52:20 -05:00
// -------------------------------------------------------------------------------------------------------------------------
else if (cfgCommand() == cfgCmdVersion)
2017-11-28 21:44:05 -05:00
{
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
2017-11-28 21:44:05 -05:00
fflush(stdout);
}
// Archive get command
// -------------------------------------------------------------------------------------------------------------------------
else if (cfgCommand() == cfgCmdArchiveGet)
{
result = cmdArchiveGet();
}
// Archive push command. Currently only implements local operations of async archive push.
// -------------------------------------------------------------------------------------------------------------------------
else if (cfgCommand() == cfgCmdArchivePush && cfgOptionBool(cfgOptArchiveAsync))
{
cmdArchivePush();
}
// Backup command. Still executed in Perl but this implements running expire after backup.
// -------------------------------------------------------------------------------------------------------------------------
else if (cfgCommand() == cfgCmdBackup)
{
#ifdef DEBUG
// Check pg_control during testing so errors are more obvious. Otherwise errors only happen in archive-get/archive-push
// and end up in the PostgreSQL log which is not output in CI. This can be removed once backup is written in C.
if (cfgOptionBool(cfgOptOnline) && !cfgOptionBool(cfgOptBackupStandby) && !cfgOptionTest(cfgOptPgHost))
pgControlFromFile(cfgOptionStr(cfgOptPgPath));
#endif
// Run backup
perlExec();
// Switch to expire command
cmdEnd(0, NULL);
cfgCommandSet(cfgCmdExpire);
cmdBegin(false);
// Run expire
perlExec();
}
// Info command
// -------------------------------------------------------------------------------------------------------------------------
else if (cfgCommand() == cfgCmdInfo)
{
cmdInfo();
}
2017-11-28 21:44:05 -05:00
// Execute Perl for commands not implemented in C
2018-01-17 09:15:51 -05:00
// -------------------------------------------------------------------------------------------------------------------------
else
{
result = perlExec();
}
2017-11-28 21:44:05 -05:00
}
CATCH_ANY()
{
error = true;
2017-11-28 21:44:05 -05:00
}
TRY_END();
2018-01-17 09:15:51 -05:00
FUNCTION_DEBUG_RESULT(INT, exitSafe(result, error, 0));
}