2017-11-26 18:43:51 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Main
|
|
|
|
***********************************************************************************************************************************/
|
2019-04-26 08:08:23 -04:00
|
|
|
#include "build.auto.h"
|
|
|
|
|
2017-11-28 21:44:05 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-02-19 20:57:38 +02:00
|
|
|
#include <unistd.h>
|
2017-11-28 21:44:05 -05:00
|
|
|
|
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"
|
2019-08-01 20:35:01 -04:00
|
|
|
#include "command/check/check.h"
|
2019-02-27 22:34:21 +02:00
|
|
|
#include "command/command.h"
|
2019-08-09 15:17:18 -04:00
|
|
|
#include "command/control/start.h"
|
|
|
|
#include "command/control/stop.h"
|
2019-06-18 15:19:20 -04:00
|
|
|
#include "command/expire/expire.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"
|
2019-02-27 22:34:21 +02:00
|
|
|
#include "command/local/local.h"
|
2019-02-19 20:57:38 +02:00
|
|
|
#include "command/remote/remote.h"
|
2019-08-21 16:26:28 -04:00
|
|
|
#include "command/stanza/create.h"
|
|
|
|
#include "command/stanza/delete.h"
|
|
|
|
#include "command/stanza/upgrade.h"
|
2019-05-28 10:03:48 -04:00
|
|
|
#include "command/storage/list.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"
|
2019-08-21 11:29:30 -04:00
|
|
|
#include "storage/helper.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
|
|
|
|
|
2019-01-21 17:41:59 +02:00
|
|
|
FUNCTION_LOG_BEGIN(logLevelDebug);
|
|
|
|
FUNCTION_LOG_PARAM(INT, argListSize);
|
|
|
|
FUNCTION_LOG_PARAM(CHARPY, argList);
|
|
|
|
FUNCTION_LOG_END();
|
2018-05-18 11:57:32 -04:00
|
|
|
|
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();
|
|
|
|
}
|
2019-04-22 08:47:32 -04:00
|
|
|
else
|
2018-04-12 20:42:26 -04:00
|
|
|
{
|
2019-04-22 08:47:32 -04:00
|
|
|
switch (cfgCommand())
|
|
|
|
{
|
|
|
|
// Archive get command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdArchiveGet:
|
|
|
|
{
|
|
|
|
result = cmdArchiveGet();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Archive get async command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdArchiveGetAsync:
|
|
|
|
{
|
|
|
|
cmdArchiveGetAsync();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Archive push command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdArchivePush:
|
|
|
|
{
|
|
|
|
cmdArchivePush();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Archive push async command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdArchivePushAsync:
|
|
|
|
{
|
|
|
|
cmdArchivePushAsync();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backup command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdBackup:
|
|
|
|
{
|
2018-09-25 10:24:42 +01:00
|
|
|
#ifdef DEBUG
|
2019-04-22 08:47:32 -04:00
|
|
|
// 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))
|
2019-08-21 11:29:30 -04:00
|
|
|
pgControlFromFile(storagePg(), cfgOptionStr(cfgOptPgPath));
|
2018-09-25 10:24:42 +01:00
|
|
|
#endif
|
|
|
|
|
2019-04-22 08:47:32 -04:00
|
|
|
// Run backup
|
|
|
|
perlExec();
|
|
|
|
|
|
|
|
// Switch to expire command
|
|
|
|
cmdEnd(0, NULL);
|
|
|
|
cfgCommandSet(cfgCmdExpire);
|
2019-08-17 17:43:56 -04:00
|
|
|
cfgLoadLogFile();
|
|
|
|
cmdBegin(true);
|
2019-04-22 08:47:32 -04:00
|
|
|
|
|
|
|
// Run expire
|
|
|
|
perlExec();
|
2019-06-18 15:19:20 -04:00
|
|
|
cmdExpire();
|
2019-04-22 08:47:32 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdCheck:
|
|
|
|
{
|
2019-08-01 20:35:01 -04:00
|
|
|
// Functionality is currently split between Perl and C
|
2019-04-22 08:47:32 -04:00
|
|
|
perlExec();
|
2019-08-01 20:35:01 -04:00
|
|
|
cmdCheck();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expire command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdExpire:
|
|
|
|
{
|
|
|
|
perlExec();
|
2019-06-18 15:19:20 -04:00
|
|
|
cmdExpire();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Help command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdHelp:
|
|
|
|
case cfgCmdNone:
|
|
|
|
{
|
|
|
|
THROW(AssertError, "'help' and 'none' commands should have been handled already");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Info command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdInfo:
|
|
|
|
{
|
|
|
|
cmdInfo();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdLocal:
|
|
|
|
{
|
2019-07-25 14:34:16 -04:00
|
|
|
cmdLocal(STDIN_FILENO, STDOUT_FILENO);
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remote command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRemote:
|
|
|
|
{
|
2019-05-09 08:55:48 -04:00
|
|
|
if (cfgOptionBool(cfgOptC))
|
2019-04-22 08:47:32 -04:00
|
|
|
{
|
|
|
|
cmdRemote(STDIN_FILENO, STDOUT_FILENO);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
perlExec();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRestore:
|
|
|
|
{
|
|
|
|
perlExec();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stanza create command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdStanzaCreate:
|
|
|
|
{
|
2019-08-21 16:26:28 -04:00
|
|
|
cmdStanzaCreate();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stanza delete command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdStanzaDelete:
|
|
|
|
{
|
2019-08-21 16:26:28 -04:00
|
|
|
cmdStanzaDelete();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stanza upgrade command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdStanzaUpgrade:
|
|
|
|
{
|
2019-08-21 16:26:28 -04:00
|
|
|
cmdStanzaUpgrade();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdStart:
|
|
|
|
{
|
2019-08-09 15:17:18 -04:00
|
|
|
cmdStart();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdStop:
|
|
|
|
{
|
2019-08-09 15:17:18 -04:00
|
|
|
cmdStop();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-28 10:03:48 -04:00
|
|
|
// Storage list command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdLs:
|
|
|
|
{
|
|
|
|
cmdStorageList();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-22 08:47:32 -04:00
|
|
|
// Display version
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdVersion:
|
|
|
|
{
|
|
|
|
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
|
|
|
|
fflush(stdout);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2019-01-21 17:41:59 +02:00
|
|
|
FUNCTION_LOG_RETURN(INT, exitSafe(result, error, 0));
|
2017-11-26 18:43:51 -05:00
|
|
|
}
|