Skip to content
Permalink
Browse files

Add ls command.

Allows listing repo paths/files from the command-line, to be used primarily for testing and debugging.

This command is internal-only so the interface may change at any time without notice.
  • Loading branch information...
dwsteele committed May 28, 2019
1 parent 3b3327e commit 20e5b92f366848ec1464e2272c6af2c29ac7b36d
@@ -108,6 +108,8 @@ use constant CFGCMD_START => 'start';
push @EXPORT, qw(CFGCMD_START);
use constant CFGCMD_STOP => 'stop';
push @EXPORT, qw(CFGCMD_STOP);
use constant CFGCMD_STORAGE_LIST => 'ls';
push @EXPORT, qw(CFGCMD_STORAGE_LIST);
use constant CFGCMD_VERSION => 'version';
push @EXPORT, qw(CFGCMD_VERSION);

@@ -157,6 +159,13 @@ use constant CFGOPT_PROCESS => 'process'
use constant CFGOPT_HOST_ID => 'host-id';
push @EXPORT, qw(CFGOPT_HOST_ID);

# Command-line only storage options
#-----------------------------------------------------------------------------------------------------------------------------------
use constant CFGOPT_FILTER => 'filter';
push @EXPORT, qw(CFGOPT_FILTER);
use constant CFGOPT_SORT => 'sort';
push @EXPORT, qw(CFGOPT_SORT);

# Command-line only test options
#-----------------------------------------------------------------------------------------------------------------------------------
use constant CFGOPT_TEST => 'test';
@@ -681,6 +690,13 @@ my $rhCommandDefine =
{
},

&CFGCMD_STORAGE_LIST =>
{
&CFGDEF_LOG_FILE => false,
&CFGDEF_LOG_LEVEL_DEFAULT => DEBUG,
&CFGDEF_PARAMETER_ALLOWED => true,
},

&CFGCMD_VERSION =>
{
&CFGDEF_LOG_FILE => false,
@@ -718,6 +734,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -1049,6 +1066,33 @@ my %hConfigDefine =
},
},

# Command-line only storage options
#-------------------------------------------------------------------------------------------------------------------------------
&CFGOPT_FILTER =>
{
&CFGDEF_TYPE => CFGDEF_TYPE_STRING,
&CFGDEF_REQUIRED => false,
&CFGDEF_COMMAND =>
{
&CFGCMD_STORAGE_LIST => {},
}
},

&CFGOPT_SORT =>
{
&CFGDEF_TYPE => CFGDEF_TYPE_STRING,
&CFGDEF_DEFAULT => 'asc',
&CFGDEF_ALLOW_LIST =>
[
'asc',
'desc',
],
&CFGDEF_COMMAND =>
{
&CFGCMD_STORAGE_LIST => {},
}
},

# Command-line only test options
#-------------------------------------------------------------------------------------------------------------------------------
&CFGOPT_TEST =>
@@ -1138,6 +1182,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_CREATE => {},
&CFGCMD_STANZA_DELETE => {},
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -1160,6 +1205,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_CREATE => {},
&CFGCMD_STANZA_DELETE => {},
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -1261,6 +1307,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -1286,6 +1333,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
},
},

@@ -1337,6 +1385,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
},
},

@@ -1387,6 +1436,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_CREATE => {},
&CFGCMD_STANZA_DELETE => {},
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -1491,6 +1541,7 @@ my %hConfigDefine =
},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
},
},

@@ -1517,6 +1568,7 @@ my %hConfigDefine =
&CFGCMD_RESTORE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
},
&CFGDEF_DEPEND =>
{
@@ -1767,6 +1819,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
},
},

@@ -1870,6 +1923,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
},
},

@@ -1952,6 +2006,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -1985,6 +2040,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -2012,6 +2068,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -2038,6 +2095,7 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_START => {},
&CFGCMD_STOP => {},
&CFGCMD_STORAGE_LIST => {},
}
},

@@ -196,7 +196,7 @@ sub process
foreach my $strCommand (cfgDefineCommandList())
{
if ($strCommand eq CFGCMD_REMOTE || $strCommand eq CFGCMD_LOCAL || $strCommand eq CFGCMD_ARCHIVE_GET_ASYNC ||
$strCommand eq CFGCMD_ARCHIVE_PUSH_ASYNC)
$strCommand eq CFGCMD_ARCHIVE_PUSH_ASYNC || $strCommand eq CFGCMD_STORAGE_LIST)
{
next;
}
@@ -1218,6 +1218,23 @@
</command-example-list>
</command>

<!-- OPERATION - STORAGE-LIST COMMAND -->
<command id="storage-list" name="Storage List">
<summary>List paths/files in the repository.</summary>

<text>This is intended to be a general purpose list function, but for now it only works on the repository.</text>

<command-example-list>
<command-example title="List all backups in a stanza">
<text><code-block title="">
{[backrest-exe]} storage-list backup/demo
</code-block>

List all backups in the demo stanza.</text>
</command-example>
</command-example-list>
</command>

<!-- OPERATION - VERSION COMMAND -->
<command id="version" name="Version">
<summary>Get version.</summary>
@@ -182,7 +182,7 @@
<variable key="host-repo1-mount">{[host-mount]}</variable>

<!-- Commands for various operations -->
<variable key="cmd-backup-last">ls -1 {[backrest-repo-path]}/backup/demo | tail -5 | head -1</variable>
<variable key="cmd-backup-last">pgbackrest ls backup/demo --filter="(F|D|I)$" --sort=desc | head -1</variable>

<!-- Data used to demonstrate backup/restore operations -->
<variable key="test-table-data">Important Data</variable>
@@ -25,6 +25,9 @@ sub libcAutoConstant
CFGOPTVAL_REPO_TYPE_POSIX => 'posix',
CFGOPTVAL_REPO_TYPE_S3 => 's3',

CFGOPTVAL_SORT_ASC => 'asc',
CFGOPTVAL_SORT_DESC => 'desc',

CFGOPTVAL_RESTORE_TARGET_ACTION_PAUSE => 'pause',
CFGOPTVAL_RESTORE_TARGET_ACTION_PROMOTE => 'promote',
CFGOPTVAL_RESTORE_TARGET_ACTION_SHUTDOWN => 'shutdown',
@@ -87,6 +90,8 @@ sub libcAutoExportTag
'CFGOPTVAL_REPO_TYPE_CIFS',
'CFGOPTVAL_REPO_TYPE_POSIX',
'CFGOPTVAL_REPO_TYPE_S3',
'CFGOPTVAL_SORT_ASC',
'CFGOPTVAL_SORT_DESC',
'CFGOPTVAL_RESTORE_TARGET_ACTION_PAUSE',
'CFGOPTVAL_RESTORE_TARGET_ACTION_PROMOTE',
'CFGOPTVAL_RESTORE_TARGET_ACTION_SHUTDOWN',
@@ -114,6 +119,7 @@ sub libcAutoExportTag
'CFGCMD_HELP',
'CFGCMD_INFO',
'CFGCMD_LOCAL',
'CFGCMD_LS',
'CFGCMD_REMOTE',
'CFGCMD_RESTORE',
'CFGCMD_STANZA_CREATE',
@@ -144,6 +150,7 @@ sub libcAutoExportTag
'CFGOPT_DB_TIMEOUT',
'CFGOPT_DELTA',
'CFGOPT_EXCLUDE',
'CFGOPT_FILTER',
'CFGOPT_FORCE',
'CFGOPT_HOST_ID',
'CFGOPT_LINK_ALL',
@@ -272,6 +279,7 @@ sub libcAutoExportTag
'CFGOPT_REPO_TYPE',
'CFGOPT_RESUME',
'CFGOPT_SET',
'CFGOPT_SORT',
'CFGOPT_SPOOL_PATH',
'CFGOPT_STANZA',
'CFGOPT_START_FAST',
@@ -58,6 +58,7 @@ SRCS = \
command/restore/file.c \
command/restore/protocol.c \
command/remote/remote.c \
command/storage/list.c \
common/compress/gzip/common.c \
common/compress/gzip/compress.c \
common/compress/gzip/decompress.c \
@@ -236,6 +237,9 @@ command/restore/file.o: command/restore/file.c build.auto.h command/restore/file
command/restore/protocol.o: command/restore/protocol.c build.auto.h command/restore/file.h command/restore/protocol.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/io.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h protocol/server.h storage/helper.h storage/info.h storage/read.h storage/storage.h storage/write.h
$(CC) $(CFLAGS) $(CMAKE) -c command/restore/protocol.c -o command/restore/protocol.o

command/storage/list.o: command/storage/list.c build.auto.h common/assert.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/handleWrite.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h storage/helper.h storage/info.h storage/read.h storage/storage.h storage/write.h
$(CC) $(CFLAGS) $(CMAKE) -c command/storage/list.c -o command/storage/list.o

common/compress/gzip/common.o: common/compress/gzip/common.c build.auto.h common/assert.h common/compress/gzip/common.h common/debug.h common/error.auto.h common/error.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/convert.h
$(CC) $(CFLAGS) $(CMAKE) -c common/compress/gzip/common.c -o common/compress/gzip/common.o

@@ -410,7 +414,7 @@ info/infoManifest.o: info/infoManifest.c build.auto.h common/error.auto.h common
info/infoPg.o: info/infoPg.c build.auto.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/ini.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/list.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h info/info.h info/infoPg.h postgres/interface.h postgres/version.h storage/helper.h storage/info.h storage/read.h storage/storage.h storage/write.h
$(CC) $(CFLAGS) $(CMAKE) -c info/infoPg.c -o info/infoPg.o

main.o: main.c build.auto.h command/archive/get/get.h command/archive/push/push.h command/command.h command/help/help.h command/info/info.h command/local/local.h command/remote/remote.h common/assert.h common/debug.h common/error.auto.h common/error.h common/exit.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/load.h perl/exec.h postgres/interface.h version.h
main.o: main.c build.auto.h command/archive/get/get.h command/archive/push/push.h command/command.h command/help/help.h command/info/info.h command/local/local.h command/remote/remote.h command/storage/list.h common/assert.h common/debug.h common/error.auto.h common/error.h common/exit.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h config/load.h perl/exec.h postgres/interface.h version.h
$(CC) $(CFLAGS) $(CMAKE) -c main.c -o main.o

perl/config.o: perl/config.c build.auto.h common/assert.h common/debug.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/json.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h
@@ -0,0 +1,64 @@
/***********************************************************************************************************************************
Storage List Command
***********************************************************************************************************************************/
#include "build.auto.h"

#include <unistd.h>

#include "common/debug.h"
#include "common/io/handleWrite.h"
#include "common/memContext.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/type/string.h"
#include "config/config.h"
#include "storage/helper.h"

/***********************************************************************************************************************************
Render storage list as a string
***********************************************************************************************************************************/
static String *
storageListRender(void)
{
FUNCTION_LOG_VOID(logLevelDebug);

// Get the path if passed
const String *path = NULL;

if (strLstSize(cfgCommandParam()) == 1)
path = strLstGet(cfgCommandParam(), 0);

// Output the list
String *result = strNew("");
StringList *list = storageListP(storageRepo(), path, .nullOnMissing = true, .expression = cfgOptionStr(cfgOptFilter));

if (list != NULL)
{
strLstSort(list, strEqZ(cfgOptionStr(cfgOptSort), "asc") ? sortOrderAsc : sortOrderDesc);

for (unsigned int listIdx = 0; listIdx < strLstSize(list); listIdx++)
{
strCat(result, strPtr(strLstGet(list, listIdx)));
strCat(result, "\n");
}
}

FUNCTION_LOG_RETURN(STRING, result);
}

/***********************************************************************************************************************************
Render storage list and output to stdout
***********************************************************************************************************************************/
void
cmdStorageList(void)
{
FUNCTION_LOG_VOID(logLevelDebug);

MEM_CONTEXT_TEMP_BEGIN()
{
ioHandleWriteOneStr(STDOUT_FILENO, storageListRender());
}
MEM_CONTEXT_TEMP_END();

FUNCTION_LOG_RETURN_VOID();
}
@@ -0,0 +1,12 @@
/***********************************************************************************************************************************
Storage List Command
***********************************************************************************************************************************/
#ifndef COMMAND_STORAGE_LIST_H
#define COMMAND_STORAGE_LIST_H

/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
void cmdStorageList(void);

#endif

0 comments on commit 20e5b92

Please sign in to comment.
You can’t perform that action at this time.