2017-11-26 18:43:51 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Main
|
|
|
|
***********************************************************************************************************************************/
|
2017-11-28 21:44:05 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
#include "command/archive/get/get.h"
|
2018-01-17 15:52:00 -05:00
|
|
|
#include "command/archive/push/push.h"
|
2018-01-23 13:34:24 -05:00
|
|
|
#include "command/help/help.h"
|
2019-01-13 22:44:58 +02:00
|
|
|
#include "command/info/info.h"
|
2018-04-12 20:42:26 -04:00
|
|
|
#include "command/command.h"
|
2018-05-18 11:57:32 -04:00
|
|
|
#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"
|
2018-09-25 10:24:42 +01:00
|
|
|
#include "postgres/interface.h"
|
2017-11-26 18:43:51 -05:00
|
|
|
#include "perl/exec.h"
|
2017-11-28 21:44:05 -05:00
|
|
|
#include "version.h"
|
2017-11-26 18:43:51 -05:00
|
|
|
|
2018-01-31 18:22:25 -05:00
|
|
|
int
|
|
|
|
main(int argListSize, const char *argList[])
|
2017-11-26 18:43:51 -05:00
|
|
|
{
|
2018-05-18 11:57:32 -04:00
|
|
|
#ifdef WITH_BACKTRACE
|
|
|
|
stackTraceInit(argList[0]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FUNCTION_DEBUG_BEGIN(logLevelDebug);
|
|
|
|
FUNCTION_DEBUG_PARAM(INT, argListSize);
|
|
|
|
FUNCTION_DEBUG_PARAM(CHARPY, argList);
|
|
|
|
FUNCTION_DEBUG_END();
|
|
|
|
|
2018-05-18 12:03:39 -04:00
|
|
|
// Initialize command with the start time
|
|
|
|
cmdInit();
|
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
volatile bool result = 0;
|
|
|
|
volatile bool error = false;
|
|
|
|
|
|
|
|
// Initialize exit handler
|
|
|
|
exitInit();
|
2018-02-18 15:45:32 -05:00
|
|
|
|
2017-11-28 21:44:05 -05:00
|
|
|
TRY_BEGIN()
|
|
|
|
{
|
2018-01-16 13:52:20 -05:00
|
|
|
// Load the configuration
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-03-02 12:07:12 -05:00
|
|
|
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
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-02-18 15:45:32 -05:00
|
|
|
else if (cfgCommand() == cfgCmdVersion)
|
2017-11-28 21:44:05 -05:00
|
|
|
{
|
2018-11-24 19:05:03 -05:00
|
|
|
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
|
2017-11-28 21:44:05 -05:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2018-04-30 17:27:39 -04:00
|
|
|
// Archive get command
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
else if (cfgCommand() == cfgCmdArchiveGet)
|
|
|
|
{
|
|
|
|
result = cmdArchiveGet();
|
|
|
|
}
|
|
|
|
|
2018-02-05 12:41:42 -05:00
|
|
|
// Archive push command. Currently only implements local operations of async archive push.
|
2018-01-17 15:52:00 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-02-18 15:45:32 -05:00
|
|
|
else if (cfgCommand() == cfgCmdArchivePush && cfgOptionBool(cfgOptArchiveAsync))
|
2018-01-17 15:52:00 -05:00
|
|
|
{
|
|
|
|
cmdArchivePush();
|
|
|
|
}
|
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
// Backup command. Still executed in Perl but this implements running expire after backup.
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
else if (cfgCommand() == cfgCmdBackup)
|
|
|
|
{
|
2018-09-25 10:24:42 +01:00
|
|
|
#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
|
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
// Run backup
|
|
|
|
perlExec();
|
|
|
|
|
|
|
|
// Switch to expire command
|
|
|
|
cmdEnd(0, NULL);
|
|
|
|
cfgCommandSet(cfgCmdExpire);
|
|
|
|
cmdBegin(false);
|
|
|
|
|
|
|
|
// Run expire
|
|
|
|
perlExec();
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:51:45 +02:00
|
|
|
// 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
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2018-02-18 15:45:32 -05:00
|
|
|
else
|
|
|
|
{
|
2018-04-12 20:42:26 -04:00
|
|
|
result = perlExec();
|
2018-02-18 15:45:32 -05:00
|
|
|
}
|
2017-11-28 21:44:05 -05:00
|
|
|
}
|
|
|
|
CATCH_ANY()
|
|
|
|
{
|
2018-02-18 15:45:32 -05:00
|
|
|
error = true;
|
2017-11-28 21:44:05 -05:00
|
|
|
}
|
|
|
|
TRY_END();
|
2018-01-17 09:15:51 -05:00
|
|
|
|
2018-05-18 11:57:32 -04:00
|
|
|
FUNCTION_DEBUG_RESULT(INT, exitSafe(result, error, 0));
|
2017-11-26 18:43:51 -05:00
|
|
|
}
|