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-12-13 17:14:26 -05:00
|
|
|
#include "command/backup/backup.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"
|
2020-03-09 17:15:03 -04:00
|
|
|
#include "command/repo/create.h"
|
|
|
|
#include "command/repo/get.h"
|
2020-03-09 16:41:04 -04:00
|
|
|
#include "command/repo/ls.h"
|
2020-03-09 17:15:03 -04:00
|
|
|
#include "command/repo/put.h"
|
|
|
|
#include "command/repo/rm.h"
|
2019-09-26 07:52:02 -04:00
|
|
|
#include "command/restore/restore.h"
|
2021-10-18 14:32:41 -04:00
|
|
|
#include "command/server/ping.h"
|
|
|
|
#include "command/server/server.h"
|
2019-08-21 16:26:28 -04:00
|
|
|
#include "command/stanza/create.h"
|
|
|
|
#include "command/stanza/delete.h"
|
|
|
|
#include "command/stanza/upgrade.h"
|
2020-09-22 11:57:38 -04:00
|
|
|
#include "command/verify/verify.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"
|
2021-07-23 10:35:36 -04:00
|
|
|
#include "common/io/fdRead.h"
|
|
|
|
#include "common/io/fdWrite.h"
|
2020-08-20 14:04:26 -04:00
|
|
|
#include "common/stat.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"
|
2021-07-23 10:35:36 -04:00
|
|
|
#include "protocol/helper.h"
|
2021-10-06 19:27:04 -04:00
|
|
|
#include "storage/azure/helper.h"
|
|
|
|
#include "storage/cifs/helper.h"
|
|
|
|
#include "storage/gcs/helper.h"
|
2019-08-21 11:29:30 -04:00
|
|
|
#include "storage/helper.h"
|
2021-10-06 19:27:04 -04:00
|
|
|
#include "storage/s3/helper.h"
|
2017-11-28 21:44:05 -05:00
|
|
|
#include "version.h"
|
2017-11-26 18:43:51 -05:00
|
|
|
|
2021-09-08 18:16:06 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Include automatically generated help data
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#include "command/help/help.auto.c"
|
|
|
|
|
2018-01-31 18:22:25 -05:00
|
|
|
int
|
|
|
|
main(int argListSize, const char *argList[])
|
2017-11-26 18:43:51 -05:00
|
|
|
{
|
2021-01-27 17:25:13 -05:00
|
|
|
// Set stack trace and mem context error cleanup handlers
|
|
|
|
static const ErrorHandlerFunction errorHandlerList[] = {stackTraceClean, memContextClean};
|
|
|
|
errorHandlerSet(errorHandlerList, sizeof(errorHandlerList) / sizeof(ErrorHandlerFunction));
|
|
|
|
|
2021-10-06 19:27:04 -04:00
|
|
|
// Set storage helpers
|
|
|
|
static const StorageHelper storageHelperList[] =
|
|
|
|
{
|
|
|
|
STORAGE_AZURE_HELPER,
|
|
|
|
STORAGE_CIFS_HELPER,
|
|
|
|
STORAGE_GCS_HELPER,
|
|
|
|
STORAGE_S3_HELPER,
|
|
|
|
STORAGE_END_HELPER
|
|
|
|
};
|
|
|
|
|
|
|
|
storageHelperInit(storageHelperList);
|
|
|
|
|
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();
|
|
|
|
|
2020-08-20 14:04:26 -04:00
|
|
|
// Initialize statistics collector
|
|
|
|
statInit();
|
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
// Initialize exit handler
|
|
|
|
exitInit();
|
2018-02-18 15:45:32 -05:00
|
|
|
|
2021-06-23 13:02:19 -04:00
|
|
|
// Process commands
|
|
|
|
volatile int result = 0;
|
|
|
|
volatile bool error = false;
|
|
|
|
|
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);
|
2020-01-15 12:24:58 -07:00
|
|
|
ConfigCommandRole commandRole = cfgCommandRole();
|
2017-11-28 21:44:05 -05:00
|
|
|
|
2018-01-23 13:34:24 -05:00
|
|
|
// Display help
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (cfgCommandHelp())
|
|
|
|
{
|
2021-09-08 18:16:06 -04:00
|
|
|
cmdHelp(BUF(helpData, sizeof(helpData)));
|
2018-01-23 13:34:24 -05:00
|
|
|
}
|
2020-01-15 12:24:58 -07:00
|
|
|
// Local role
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
else if (commandRole == cfgCmdRoleLocal)
|
|
|
|
{
|
2021-07-23 10:35:36 -04:00
|
|
|
String *name = strNewFmt(PROTOCOL_SERVICE_LOCAL "-%s", strZ(cfgOptionDisplay(cfgOptProcess)));
|
|
|
|
|
|
|
|
cmdLocal(
|
|
|
|
protocolServerNew(
|
|
|
|
name, PROTOCOL_SERVICE_LOCAL_STR, ioFdReadNewOpen(name, STDIN_FILENO, cfgOptionUInt64(cfgOptProtocolTimeout)),
|
|
|
|
ioFdWriteNewOpen(name, STDOUT_FILENO, cfgOptionUInt64(cfgOptProtocolTimeout))));
|
2020-01-15 12:24:58 -07:00
|
|
|
}
|
|
|
|
// Remote role
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
else if (commandRole == cfgCmdRoleRemote)
|
|
|
|
{
|
2021-07-23 10:35:36 -04:00
|
|
|
String *name = strNewFmt(PROTOCOL_SERVICE_REMOTE "-%s", strZ(cfgOptionDisplay(cfgOptProcess)));
|
|
|
|
|
|
|
|
cmdRemote(
|
|
|
|
protocolServerNew(
|
|
|
|
name, PROTOCOL_SERVICE_REMOTE_STR, ioFdReadNewOpen(name, STDIN_FILENO, cfgOptionUInt64(cfgOptProtocolTimeout)),
|
|
|
|
ioFdWriteNewOpen(name, STDOUT_FILENO, cfgOptionUInt64(cfgOptProtocolTimeout))));
|
2020-01-15 12:24:58 -07:00
|
|
|
}
|
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:
|
|
|
|
{
|
2020-01-15 12:24:58 -07:00
|
|
|
if (commandRole == cfgCmdRoleAsync)
|
|
|
|
cmdArchiveGetAsync();
|
|
|
|
else
|
|
|
|
result = cmdArchiveGet();
|
2019-04-22 08:47:32 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Archive push command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdArchivePush:
|
|
|
|
{
|
2020-01-15 12:24:58 -07:00
|
|
|
if (commandRole == cfgCmdRoleAsync)
|
|
|
|
cmdArchivePushAsync();
|
|
|
|
else
|
|
|
|
cmdArchivePush();
|
2019-04-22 08:47:32 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backup command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdBackup:
|
|
|
|
{
|
|
|
|
// Run backup
|
2019-12-13 17:14:26 -05:00
|
|
|
cmdBackup();
|
2019-04-22 08:47:32 -04:00
|
|
|
|
2020-07-14 14:12:25 +02:00
|
|
|
if (cfgOptionBool(cfgOptExpireAuto))
|
|
|
|
{
|
|
|
|
// Switch to expire command
|
|
|
|
cmdEnd(0, NULL);
|
2021-05-20 14:39:47 -04:00
|
|
|
cfgCommandSet(cfgCmdExpire, cfgCmdRoleMain);
|
2020-07-14 14:12:25 +02:00
|
|
|
cfgLoadLogFile();
|
2020-08-20 14:16:36 -04:00
|
|
|
cmdBegin();
|
2020-07-14 14:12:25 +02:00
|
|
|
|
|
|
|
// Run expire
|
|
|
|
cmdExpire();
|
|
|
|
}
|
2019-04-22 08:47:32 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdCheck:
|
2019-08-01 20:35:01 -04:00
|
|
|
cmdCheck();
|
2019-04-22 08:47:32 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Expire command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdExpire:
|
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;
|
|
|
|
|
2020-03-09 17:15:03 -04:00
|
|
|
// Repository create command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRepoCreate:
|
|
|
|
cmdRepoCreate();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Repository get file command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRepoGet:
|
|
|
|
result = cmdStorageGet();
|
|
|
|
break;
|
|
|
|
|
2020-03-09 16:41:04 -04:00
|
|
|
// Repository list paths/files command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRepoLs:
|
|
|
|
cmdStorageList();
|
|
|
|
break;
|
|
|
|
|
2020-03-09 17:15:03 -04:00
|
|
|
// Repository put file command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRepoPut:
|
|
|
|
cmdStoragePut();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Repository remove paths/files command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRepoRm:
|
|
|
|
cmdStorageRemove();
|
|
|
|
break;
|
|
|
|
|
2021-11-18 17:23:11 -05:00
|
|
|
// Server command
|
2021-10-18 14:32:41 -04:00
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
2021-11-18 17:23:11 -05:00
|
|
|
case cfgCmdServer:
|
2021-12-07 18:18:43 -05:00
|
|
|
cmdServer((unsigned int)argListSize, argList);
|
2021-10-18 14:32:41 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Server ping command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdServerPing:
|
|
|
|
cmdServerPing();
|
|
|
|
break;
|
|
|
|
|
2019-04-22 08:47:32 -04:00
|
|
|
// Restore command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdRestore:
|
2019-09-26 07:52:02 -04:00
|
|
|
cmdRestore();
|
2019-04-22 08:47:32 -04:00
|
|
|
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;
|
|
|
|
|
2020-09-22 11:57:38 -04:00
|
|
|
// Verify command
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
|
|
case cfgCmdVerify:
|
|
|
|
cmdVerify();
|
|
|
|
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;
|
2021-06-23 13:02:19 -04:00
|
|
|
result = exitSafe(result, true, 0);
|
2017-11-28 21:44:05 -05:00
|
|
|
}
|
|
|
|
TRY_END();
|
2018-01-17 09:15:51 -05:00
|
|
|
|
2021-06-23 13:02:19 -04:00
|
|
|
FUNCTION_LOG_RETURN(INT, error ? result : exitSafe(result, false, 0));
|
2017-11-26 18:43:51 -05:00
|
|
|
}
|