2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* backup.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-03-05 02:42:45 +08:00
|
|
|
#include "contrib/fmt-8.1.1/include/fmt/format.h"
|
2021-04-06 03:21:32 +08:00
|
|
|
#include "fdbbackup/BackupTLSConfig.h"
|
2020-09-06 09:55:09 +08:00
|
|
|
#include "fdbclient/JsonBuilder.h"
|
2020-08-30 10:53:04 +08:00
|
|
|
#include "flow/Arena.h"
|
2021-12-15 04:01:44 +08:00
|
|
|
#include "flow/ArgParseUtil.h"
|
2020-09-18 08:58:58 +08:00
|
|
|
#include "flow/Error.h"
|
2022-04-07 11:06:24 +08:00
|
|
|
#include "flow/SystemMonitor.h"
|
2020-09-06 09:55:09 +08:00
|
|
|
#include "flow/Trace.h"
|
2019-02-06 08:46:08 +08:00
|
|
|
#define BOOST_DATE_TIME_NO_LIB
|
|
|
|
#include <boost/interprocess/managed_shared_memory.hpp>
|
|
|
|
|
2018-08-11 07:05:40 +08:00
|
|
|
#include "flow/flow.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/FastAlloc.h"
|
|
|
|
#include "flow/serialize.h"
|
|
|
|
#include "flow/IRandom.h"
|
|
|
|
#include "flow/genericactors.actor.h"
|
2020-03-05 12:14:47 +08:00
|
|
|
#include "flow/TLSConfig.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
#include "fdbclient/FDBTypes.h"
|
2019-02-18 07:19:05 +08:00
|
|
|
#include "fdbclient/BackupAgent.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbclient/Status.h"
|
|
|
|
#include "fdbclient/BackupContainer.h"
|
2021-10-11 11:44:56 +08:00
|
|
|
#include "fdbclient/ClusterConnectionFile.h"
|
2017-12-15 05:54:01 +08:00
|
|
|
#include "fdbclient/KeyBackedTypes.h"
|
2021-06-03 14:40:52 +08:00
|
|
|
#include "fdbclient/IKnobCollection.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbclient/RunTransaction.actor.h"
|
2020-10-30 11:42:23 +08:00
|
|
|
#include "fdbclient/S3BlobStore.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbclient/json_spirit/json_spirit_writer_template.h"
|
|
|
|
|
2020-02-29 06:56:10 +08:00
|
|
|
#include "flow/Platform.h"
|
2018-10-27 04:49:42 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2019-05-05 01:48:09 +08:00
|
|
|
#include <cinttypes>
|
2021-03-11 02:06:03 +08:00
|
|
|
#include <algorithm> // std::transform
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
2017-12-15 05:54:01 +08:00
|
|
|
#include <ctime>
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2019-02-06 08:46:08 +08:00
|
|
|
#define NOMINMAX
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
#include <time.h>
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
#ifdef __linux__
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <execinfo.h>
|
|
|
|
#ifdef ALLOC_INSTRUMENTATION
|
|
|
|
#include <cxxabi.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-05-21 04:23:02 +08:00
|
|
|
#include "fdbclient/versions.h"
|
2020-09-11 06:53:12 +08:00
|
|
|
#include "fdbclient/BuildFlags.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
#include "flow/SimpleOpt.h"
|
2021-03-11 02:06:03 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Type of program being executed
|
2020-11-15 14:02:46 +08:00
|
|
|
enum class ProgramExe { AGENT, BACKUP, RESTORE, FASTRESTORE_TOOL, DR_AGENT, DB_BACKUP, UNDEFINED };
|
|
|
|
|
|
|
|
enum class BackupType {
|
2021-01-31 05:30:43 +08:00
|
|
|
UNDEFINED = 0,
|
|
|
|
START,
|
|
|
|
MODIFY,
|
|
|
|
STATUS,
|
|
|
|
ABORT,
|
|
|
|
WAIT,
|
|
|
|
DISCONTINUE,
|
|
|
|
PAUSE,
|
|
|
|
RESUME,
|
|
|
|
EXPIRE,
|
|
|
|
DELETE_BACKUP,
|
|
|
|
DESCRIBE,
|
|
|
|
LIST,
|
|
|
|
QUERY,
|
|
|
|
DUMP,
|
2022-01-18 15:41:29 +08:00
|
|
|
CLEANUP,
|
|
|
|
TAGS,
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
enum class DBType { UNDEFINED = 0, START, STATUS, SWITCH, ABORT, PAUSE, RESUME };
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-01-25 08:26:57 +08:00
|
|
|
// New fast restore reuses the type from legacy slow restore
|
2020-11-15 14:02:46 +08:00
|
|
|
enum class RestoreType { UNKNOWN, START, STATUS, ABORT, WAIT };
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
enum {
|
|
|
|
// Backup constants
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_DESTCONTAINER,
|
|
|
|
OPT_SNAPSHOTINTERVAL,
|
2021-04-16 06:24:24 +08:00
|
|
|
OPT_INITIAL_SNAPSHOT_INTERVAL,
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_ERRORLIMIT,
|
|
|
|
OPT_NOSTOPWHENDONE,
|
|
|
|
OPT_EXPIRE_BEFORE_VERSION,
|
|
|
|
OPT_EXPIRE_BEFORE_DATETIME,
|
|
|
|
OPT_EXPIRE_DELETE_BEFORE_DAYS,
|
|
|
|
OPT_EXPIRE_RESTORABLE_AFTER_VERSION,
|
|
|
|
OPT_EXPIRE_RESTORABLE_AFTER_DATETIME,
|
|
|
|
OPT_EXPIRE_MIN_RESTORABLE_DAYS,
|
|
|
|
OPT_BASEURL,
|
|
|
|
OPT_BLOB_CREDENTIALS,
|
|
|
|
OPT_DESCRIBE_DEEP,
|
|
|
|
OPT_DESCRIBE_TIMESTAMPS,
|
|
|
|
OPT_DUMP_BEGIN,
|
|
|
|
OPT_DUMP_END,
|
|
|
|
OPT_JSON,
|
|
|
|
OPT_DELETE_DATA,
|
|
|
|
OPT_MIN_CLEANUP_SECONDS,
|
2020-04-01 05:54:32 +08:00
|
|
|
OPT_USE_PARTITIONED_LOG,
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Backup and Restore constants
|
2022-03-29 08:10:49 +08:00
|
|
|
OPT_PROXY,
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_TAGNAME,
|
|
|
|
OPT_BACKUPKEYS,
|
|
|
|
OPT_WAITFORDONE,
|
2020-09-25 08:27:05 +08:00
|
|
|
OPT_BACKUPKEYS_FILTER,
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_INCREMENTALONLY,
|
2021-06-26 06:11:03 +08:00
|
|
|
OPT_ENCRYPTION_KEY_FILE,
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-03-05 20:00:11 +08:00
|
|
|
// Backup Modify
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_MOD_ACTIVE_INTERVAL,
|
|
|
|
OPT_MOD_VERIFY_UID,
|
2019-03-05 20:00:11 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// Restore constants
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_RESTORECONTAINER,
|
|
|
|
OPT_RESTORE_VERSION,
|
|
|
|
OPT_RESTORE_TIMESTAMP,
|
|
|
|
OPT_PREFIX_ADD,
|
|
|
|
OPT_PREFIX_REMOVE,
|
|
|
|
OPT_RESTORE_CLUSTERFILE_DEST,
|
|
|
|
OPT_RESTORE_CLUSTERFILE_ORIG,
|
2020-08-29 02:29:22 +08:00
|
|
|
OPT_RESTORE_BEGIN_VERSION,
|
2021-04-23 04:53:37 +08:00
|
|
|
OPT_RESTORE_INCONSISTENT_SNAPSHOT_ONLY,
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Shared constants
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_CLUSTERFILE,
|
|
|
|
OPT_QUIET,
|
|
|
|
OPT_DRYRUN,
|
|
|
|
OPT_FORCE,
|
|
|
|
OPT_HELP,
|
|
|
|
OPT_DEVHELP,
|
|
|
|
OPT_VERSION,
|
2020-09-11 06:53:12 +08:00
|
|
|
OPT_BUILD_FLAGS,
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_PARENTPID,
|
|
|
|
OPT_CRASHONERROR,
|
|
|
|
OPT_NOBUFSTDOUT,
|
|
|
|
OPT_BUFSTDOUTERR,
|
|
|
|
OPT_TRACE,
|
|
|
|
OPT_TRACE_DIR,
|
|
|
|
OPT_KNOB,
|
|
|
|
OPT_TRACE_LOG_GROUP,
|
|
|
|
OPT_MEMLIMIT,
|
2022-04-07 11:06:24 +08:00
|
|
|
OPT_VMEMLIMIT,
|
2020-07-22 04:07:16 +08:00
|
|
|
OPT_LOCALITY,
|
|
|
|
|
|
|
|
// DB constants
|
2017-05-26 04:48:44 +08:00
|
|
|
OPT_SOURCE_CLUSTER,
|
|
|
|
OPT_DEST_CLUSTER,
|
2018-12-21 05:51:06 +08:00
|
|
|
OPT_CLEANUP,
|
2020-07-05 02:31:23 +08:00
|
|
|
OPT_DSTONLY,
|
2018-12-21 05:51:06 +08:00
|
|
|
|
2019-07-13 01:19:28 +08:00
|
|
|
OPT_TRACE_FORMAT,
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2020-09-11 05:51:52 +08:00
|
|
|
// Top level binary commands.
|
2021-03-11 02:06:03 +08:00
|
|
|
CSimpleOpt::SOption g_rgOptions[] = { { OPT_VERSION, "-v", SO_NONE },
|
|
|
|
{ OPT_VERSION, "--version", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BUILD_FLAGS, "--build-flags", SO_NONE },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
2020-09-11 07:14:00 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
SO_END_OF_OPTIONS };
|
2020-09-11 05:51:52 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
CSimpleOpt::SOption g_rgAgentOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2019-07-13 01:19:28 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2019-07-13 01:19:28 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2019-07-13 01:19:28 +08:00
|
|
|
{ OPT_VERSION, "--version", SO_NONE },
|
|
|
|
{ OPT_VERSION, "-v", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BUILD_FLAGS, "--build-flags", SO_NONE },
|
2019-07-13 01:19:28 +08:00
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2019-07-13 01:19:28 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_LOCALITY, "--locality-", SO_REQ_SEP },
|
2019-07-13 01:19:28 +08:00
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2019-07-13 01:19:28 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupStartOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_WAITFORDONE, "-w", SO_NONE },
|
|
|
|
{ OPT_WAITFORDONE, "--waitfordone", SO_NONE },
|
|
|
|
{ OPT_NOSTOPWHENDONE, "-z", SO_NONE },
|
|
|
|
{ OPT_NOSTOPWHENDONE, "--no-stop-when-done", SO_NONE },
|
|
|
|
{ OPT_DESTCONTAINER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DESTCONTAINER, "--destcontainer", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2020-05-05 04:45:54 +08:00
|
|
|
// Enable "-p" option after GA
|
|
|
|
// { OPT_USE_PARTITIONED_LOG, "-p", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_USE_PARTITIONED_LOG, "--partitioned-log-experimental", SO_NONE },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SNAPSHOTINTERVAL, "-s", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_SNAPSHOTINTERVAL, "--snapshot-interval", SO_REQ_SEP },
|
|
|
|
{ OPT_INITIAL_SNAPSHOT_INTERVAL, "--initial-snapshot-interval", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_BACKUPKEYS, "-k", SO_REQ_SEP },
|
|
|
|
{ OPT_BACKUPKEYS, "--keys", SO_REQ_SEP },
|
|
|
|
{ OPT_DRYRUN, "-n", SO_NONE },
|
|
|
|
{ OPT_DRYRUN, "--dryrun", SO_NONE },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_INCREMENTALONLY, "--incremental", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_ENCRYPTION_KEY_FILE, "--encryption-key-file", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2019-03-05 20:00:11 +08:00
|
|
|
CSimpleOpt::SOption g_rgBackupModifyOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2019-03-05 20:00:11 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_MOD_VERIFY_UID, "--verify-uid", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_DESTCONTAINER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DESTCONTAINER, "--destcontainer", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SNAPSHOTINTERVAL, "-s", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_SNAPSHOTINTERVAL, "--snapshot-interval", SO_REQ_SEP },
|
|
|
|
{ OPT_MOD_ACTIVE_INTERVAL, "--active-snapshot-interval", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
SO_END_OF_OPTIONS
|
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupStatusOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_ERRORLIMIT, "-e", SO_REQ_SEP },
|
|
|
|
{ OPT_ERRORLIMIT, "--errorlimit", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
|
|
|
{ OPT_JSON, "--json", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupAbortOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2019-09-28 09:32:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupCleanupOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2019-09-28 09:32:27 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
|
|
|
{ OPT_DELETE_DATA, "--delete-data", SO_NONE },
|
|
|
|
{ OPT_MIN_CLEANUP_SECONDS, "--min-cleanup-seconds", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupDiscontinueOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_WAITFORDONE, "-w", SO_NONE },
|
|
|
|
{ OPT_WAITFORDONE, "--waitfordone", SO_NONE },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupWaitOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_NOSTOPWHENDONE, "-z", SO_NONE },
|
|
|
|
{ OPT_NOSTOPWHENDONE, "--no-stop-when-done", SO_NONE },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 01:59:14 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
CSimpleOpt::SOption g_rgBackupPauseOptions[] = {
|
2017-10-31 03:35:00 +08:00
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-10-31 03:35:00 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-10-31 03:35:00 +08:00
|
|
|
};
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
CSimpleOpt::SOption g_rgBackupExpireOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-12-15 05:54:01 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_DESTCONTAINER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DESTCONTAINER, "--destcontainer", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_FORCE, "-f", SO_NONE },
|
|
|
|
{ OPT_FORCE, "--force", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_EXPIRE_RESTORABLE_AFTER_VERSION, "--restorable-after-version", SO_REQ_SEP },
|
|
|
|
{ OPT_EXPIRE_RESTORABLE_AFTER_DATETIME, "--restorable-after-timestamp", SO_REQ_SEP },
|
|
|
|
{ OPT_EXPIRE_BEFORE_VERSION, "--expire-before-version", SO_REQ_SEP },
|
|
|
|
{ OPT_EXPIRE_BEFORE_DATETIME, "--expire-before-timestamp", SO_REQ_SEP },
|
|
|
|
{ OPT_EXPIRE_MIN_RESTORABLE_DAYS, "--min-restorable-days", SO_REQ_SEP },
|
|
|
|
{ OPT_EXPIRE_DELETE_BEFORE_DAYS, "--delete-before-days", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-12-15 05:54:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupDeleteOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-12-15 05:54:01 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_DESTCONTAINER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DESTCONTAINER, "--destcontainer", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-12-15 05:54:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgBackupDescribeOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-12-15 05:54:01 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_DESTCONTAINER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DESTCONTAINER, "--destcontainer", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_DESCRIBE_DEEP, "--deep", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_DESCRIBE_TIMESTAMPS, "--version-timestamps", SO_NONE },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_JSON, "--json", SO_NONE },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-12-15 05:54:01 +08:00
|
|
|
};
|
|
|
|
|
2019-01-03 18:35:31 +08:00
|
|
|
CSimpleOpt::SOption g_rgBackupDumpOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2019-01-03 18:35:31 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_DESTCONTAINER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DESTCONTAINER, "--destcontainer", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_DUMP_BEGIN, "--begin", SO_REQ_SEP },
|
|
|
|
{ OPT_DUMP_END, "--end", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2019-01-03 18:35:31 +08:00
|
|
|
};
|
|
|
|
|
2022-01-18 15:41:29 +08:00
|
|
|
CSimpleOpt::SOption g_rgBackupTagsOptions[] = {
|
|
|
|
#ifdef _WIN32
|
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
|
|
|
#endif
|
|
|
|
{ OPT_CLUSTERFILE, "-C", SO_REQ_SEP },
|
|
|
|
{ OPT_CLUSTERFILE, "--cluster-file", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2022-01-18 15:41:29 +08:00
|
|
|
};
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
CSimpleOpt::SOption g_rgBackupListOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-12-15 05:54:01 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_BASEURL, "-b", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BASEURL, "--base-url", SO_REQ_SEP },
|
2022-05-03 08:34:22 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-12-15 05:54:01 +08:00
|
|
|
};
|
|
|
|
|
2020-08-30 10:53:04 +08:00
|
|
|
CSimpleOpt::SOption g_rgBackupQueryOptions[] = {
|
|
|
|
#ifdef _WIN32
|
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
|
|
|
#endif
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_RESTORE_TIMESTAMP, "--query-restore-timestamp", SO_REQ_SEP },
|
2020-08-30 10:53:04 +08:00
|
|
|
{ OPT_DESTCONTAINER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DESTCONTAINER, "--destcontainer", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2020-09-01 00:31:57 +08:00
|
|
|
{ OPT_RESTORE_VERSION, "-qrv", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_RESTORE_VERSION, "--query-restore-version", SO_REQ_SEP },
|
2020-09-06 09:55:09 +08:00
|
|
|
{ OPT_BACKUPKEYS_FILTER, "-k", SO_REQ_SEP },
|
|
|
|
{ OPT_BACKUPKEYS_FILTER, "--keys", SO_REQ_SEP },
|
2020-08-30 10:53:04 +08:00
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2020-08-30 10:53:04 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_VERSION, "-v", SO_NONE },
|
|
|
|
{ OPT_VERSION, "--version", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2020-08-30 10:53:04 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2020-08-30 10:53:04 +08:00
|
|
|
};
|
|
|
|
|
2020-07-28 12:40:20 +08:00
|
|
|
// g_rgRestoreOptions is used by fdbrestore and fastrestore_tool
|
2017-05-26 04:48:44 +08:00
|
|
|
CSimpleOpt::SOption g_rgRestoreOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_RESTORE_CLUSTERFILE_DEST, "--dest-cluster-file", SO_REQ_SEP },
|
|
|
|
{ OPT_RESTORE_CLUSTERFILE_ORIG, "--orig-cluster-file", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_RESTORE_TIMESTAMP, "--timestamp", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_RESTORECONTAINER, "-r", SO_REQ_SEP },
|
2022-03-29 08:10:49 +08:00
|
|
|
{ OPT_PROXY, "--proxy", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_PREFIX_ADD, "--add-prefix", SO_REQ_SEP },
|
|
|
|
{ OPT_PREFIX_REMOVE, "--remove-prefix", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_BACKUPKEYS, "-k", SO_REQ_SEP },
|
|
|
|
{ OPT_BACKUPKEYS, "--keys", SO_REQ_SEP },
|
|
|
|
{ OPT_WAITFORDONE, "-w", SO_NONE },
|
|
|
|
{ OPT_WAITFORDONE, "--waitfordone", SO_NONE },
|
|
|
|
{ OPT_RESTORE_VERSION, "--version", SO_REQ_SEP },
|
|
|
|
{ OPT_RESTORE_VERSION, "-v", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_DRYRUN, "-n", SO_NONE },
|
|
|
|
{ OPT_DRYRUN, "--dryrun", SO_NONE },
|
|
|
|
{ OPT_FORCE, "-f", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BLOB_CREDENTIALS, "--blob-credentials", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_INCREMENTALONLY, "--incremental", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_RESTORE_BEGIN_VERSION, "--begin-version", SO_REQ_SEP },
|
|
|
|
{ OPT_RESTORE_INCONSISTENT_SNAPSHOT_ONLY, "--inconsistent-snapshot-only", SO_NONE },
|
|
|
|
{ OPT_ENCRYPTION_KEY_FILE, "--encryption-key-file", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgDBAgentOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SOURCE_CLUSTER, "-s", SO_REQ_SEP },
|
|
|
|
{ OPT_SOURCE_CLUSTER, "--source", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "--destination", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_VERSION, "--version", SO_NONE },
|
|
|
|
{ OPT_VERSION, "-v", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_BUILD_FLAGS, "--build-flags", SO_NONE },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_LOCALITY, "--locality-", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgDBStartOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SOURCE_CLUSTER, "-s", SO_REQ_SEP },
|
|
|
|
{ OPT_SOURCE_CLUSTER, "--source", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "--destination", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_BACKUPKEYS, "-k", SO_REQ_SEP },
|
|
|
|
{ OPT_BACKUPKEYS, "--keys", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgDBStatusOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SOURCE_CLUSTER, "-s", SO_REQ_SEP },
|
|
|
|
{ OPT_SOURCE_CLUSTER, "--source", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "--destination", SO_REQ_SEP },
|
|
|
|
{ OPT_ERRORLIMIT, "-e", SO_REQ_SEP },
|
|
|
|
{ OPT_ERRORLIMIT, "--errorlimit", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgDBSwitchOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SOURCE_CLUSTER, "-s", SO_REQ_SEP },
|
|
|
|
{ OPT_SOURCE_CLUSTER, "--source", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "--destination", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_FORCE, "-f", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
CSimpleOpt::SOption g_rgDBAbortOptions[] = {
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SOURCE_CLUSTER, "-s", SO_REQ_SEP },
|
|
|
|
{ OPT_SOURCE_CLUSTER, "--source", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "--destination", SO_REQ_SEP },
|
|
|
|
{ OPT_CLEANUP, "--cleanup", SO_NONE },
|
|
|
|
{ OPT_DSTONLY, "--dstonly", SO_NONE },
|
|
|
|
{ OPT_TAGNAME, "-t", SO_REQ_SEP },
|
|
|
|
{ OPT_TAGNAME, "--tagname", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
CSimpleOpt::SOption g_rgDBPauseOptions[] = {
|
2017-10-31 03:35:00 +08:00
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_PARENTPID, "--parentpid", SO_REQ_SEP },
|
2017-10-31 03:35:00 +08:00
|
|
|
#endif
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_SOURCE_CLUSTER, "-s", SO_REQ_SEP },
|
|
|
|
{ OPT_SOURCE_CLUSTER, "--source", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "-d", SO_REQ_SEP },
|
|
|
|
{ OPT_DEST_CLUSTER, "--destination", SO_REQ_SEP },
|
|
|
|
{ OPT_TRACE, "--log", SO_NONE },
|
|
|
|
{ OPT_TRACE_DIR, "--logdir", SO_REQ_SEP },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_TRACE_FORMAT, "--trace-format", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_TRACE_LOG_GROUP, "--loggroup", SO_REQ_SEP },
|
|
|
|
{ OPT_QUIET, "-q", SO_NONE },
|
|
|
|
{ OPT_QUIET, "--quiet", SO_NONE },
|
|
|
|
{ OPT_CRASHONERROR, "--crash", SO_NONE },
|
|
|
|
{ OPT_MEMLIMIT, "-m", SO_REQ_SEP },
|
|
|
|
{ OPT_MEMLIMIT, "--memory", SO_REQ_SEP },
|
2022-04-07 11:06:24 +08:00
|
|
|
{ OPT_VMEMLIMIT, "--memory-vsize", SO_REQ_SEP },
|
2021-03-11 02:06:03 +08:00
|
|
|
{ OPT_HELP, "-?", SO_NONE },
|
|
|
|
{ OPT_HELP, "-h", SO_NONE },
|
|
|
|
{ OPT_HELP, "--help", SO_NONE },
|
|
|
|
{ OPT_DEVHELP, "--dev-help", SO_NONE },
|
2021-12-15 00:44:39 +08:00
|
|
|
{ OPT_KNOB, "--knob-", SO_REQ_SEP },
|
2022-05-03 13:56:06 +08:00
|
|
|
TLS_OPTION_FLAGS,
|
|
|
|
SO_END_OF_OPTIONS
|
2017-10-31 03:35:00 +08:00
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef exeAgent = LiteralStringRef("backup_agent");
|
|
|
|
const KeyRef exeBackup = LiteralStringRef("fdbbackup");
|
|
|
|
const KeyRef exeRestore = LiteralStringRef("fdbrestore");
|
2020-07-02 23:16:39 +08:00
|
|
|
const KeyRef exeFastRestoreTool = LiteralStringRef("fastrestore_tool"); // must be lower case
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef exeDatabaseAgent = LiteralStringRef("dr_agent");
|
|
|
|
const KeyRef exeDatabaseBackup = LiteralStringRef("fdbdr");
|
|
|
|
|
2019-11-16 04:26:51 +08:00
|
|
|
extern const char* getSourceVersion();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2021-03-11 02:06:03 +08:00
|
|
|
void parentWatcher(void* parentHandle) {
|
2017-05-26 04:48:44 +08:00
|
|
|
HANDLE parent = (HANDLE)parentHandle;
|
|
|
|
int signal = WaitForSingleObject(parent, INFINITE);
|
|
|
|
CloseHandle(parentHandle);
|
|
|
|
if (signal == WAIT_OBJECT_0)
|
|
|
|
criticalError(FDB_EXIT_SUCCESS, "ParentProcessExited", "Parent process exited");
|
|
|
|
TraceEvent(SevError, "ParentProcessWaitFailed").detail("RetCode", signal).GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void printVersion() {
|
|
|
|
printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n");
|
2019-11-16 04:26:51 +08:00
|
|
|
printf("source version %s\n", getSourceVersion());
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("protocol %llx\n", (long long)currentProtocolVersion.version());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-09-11 06:53:12 +08:00
|
|
|
static void printBuildInformation() {
|
|
|
|
printf("%s", jsonBuildInformation().c_str());
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const char* BlobCredentialInfo =
|
|
|
|
" BLOB CREDENTIALS\n"
|
|
|
|
" Blob account secret keys can optionally be omitted from blobstore:// URLs, in which case they will be\n"
|
|
|
|
" loaded, if possible, from 1 or more blob credentials definition files.\n\n"
|
2021-12-15 01:59:14 +08:00
|
|
|
" These files can be specified with the --blob-credentials argument described above or via the environment "
|
2021-03-11 02:06:03 +08:00
|
|
|
"variable\n"
|
|
|
|
" FDB_BLOB_CREDENTIALS, whose value is a colon-separated list of files. The command line takes priority over\n"
|
|
|
|
" over the environment but all files from both sources are used.\n\n"
|
|
|
|
" At connect time, the specified files are read in order and the first matching account specification "
|
|
|
|
"(user@host)\n"
|
|
|
|
" will be used to obtain the secret key.\n\n"
|
|
|
|
" The JSON schema is:\n"
|
|
|
|
" { \"accounts\" : { \"user@host\" : { \"secret\" : \"SECRETKEY\" }, \"user2@host2\" : { \"secret\" : "
|
|
|
|
"\"SECRET\" } } }\n";
|
|
|
|
|
|
|
|
static void printHelpTeaser(const char* name) {
|
2017-05-26 04:48:44 +08:00
|
|
|
fprintf(stderr, "Try `%s --help' for more information.\n", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printAgentUsage(bool devhelp) {
|
|
|
|
printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n");
|
|
|
|
printf("Usage: %s [OPTIONS]\n\n", exeAgent.toString().c_str());
|
|
|
|
printf(" -C CONNFILE The path of a file containing the connection string for the\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" FoundationDB cluster. The default is first the value of the\n"
|
|
|
|
" FDB_CLUSTER_FILE environment variable, then `./fdb.cluster',\n"
|
|
|
|
" then `%s'.\n",
|
|
|
|
platform::getDefaultClusterFilePath().c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" --log Enables trace file logging for the CLI session.\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" --logdir PATH Specifes the output directory for trace files. If\n"
|
|
|
|
" unspecified, defaults to the current directory. Has\n"
|
|
|
|
" no effect unless --log is specified.\n");
|
2019-08-20 03:59:14 +08:00
|
|
|
printf(" --loggroup LOG_GROUP\n"
|
|
|
|
" Sets the LogGroup field with the specified value for all\n"
|
|
|
|
" events in the trace output (defaults to `default').\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --trace-format FORMAT\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Select the format of the trace files. xml (the default) and json are supported.\n"
|
|
|
|
" Has no effect unless --log is specified.\n");
|
2017-09-30 03:38:42 +08:00
|
|
|
printf(" -m SIZE, --memory SIZE\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Memory limit. The default value is 8GiB. When specified\n"
|
|
|
|
" without a unit, MiB is assumed.\n");
|
2019-01-31 09:36:51 +08:00
|
|
|
printf(TLS_HELP);
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --build-flags Print build information and exit.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -v, --version Print version information and exit.\n");
|
|
|
|
printf(" -h, --help Display this help and exit.\n");
|
2018-01-23 07:50:28 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
if (devhelp) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
printf(" -n Create a new console.\n");
|
|
|
|
printf(" -q Disable error dialog on crash.\n");
|
|
|
|
printf(" --parentpid PID\n");
|
|
|
|
printf(" Specify a process after whose termination to exit.\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-01-23 07:50:28 +08:00
|
|
|
printf("\n");
|
|
|
|
puts(BlobCredentialInfo);
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printBackupContainerInfo() {
|
|
|
|
printf(" Backup URL forms:\n\n");
|
|
|
|
std::vector<std::string> formats = IBackupContainer::getURLFormats();
|
2021-03-11 02:06:03 +08:00
|
|
|
for (const auto& f : formats)
|
|
|
|
printf(" %s\n", f.c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printBackupUsage(bool devhelp) {
|
|
|
|
printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n");
|
2020-09-12 02:35:35 +08:00
|
|
|
printf("Usage: %s [TOP_LEVEL_OPTIONS] (start | status | abort | wait | discontinue | pause | resume | expire | "
|
2022-01-18 15:41:29 +08:00
|
|
|
"delete | describe | list | query | cleanup | tags) [ACTION_OPTIONS]\n\n",
|
2020-08-30 10:53:04 +08:00
|
|
|
exeBackup.toString().c_str());
|
2020-09-12 02:35:35 +08:00
|
|
|
printf(" TOP LEVEL OPTIONS:\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --build-flags Print build information and exit.\n");
|
2020-09-12 02:35:35 +08:00
|
|
|
printf(" -v, --version Print version information and exit.\n");
|
|
|
|
printf(" -h, --help Display this help and exit.\n");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf(" ACTION OPTIONS:\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -C CONNFILE The path of a file containing the connection string for the\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" FoundationDB cluster. The default is first the value of the\n"
|
|
|
|
" FDB_CLUSTER_FILE environment variable, then `./fdb.cluster',\n"
|
|
|
|
" then `%s'.\n",
|
|
|
|
platform::getDefaultClusterFilePath().c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -d, --destcontainer URL\n"
|
2020-08-30 10:53:04 +08:00
|
|
|
" The Backup container URL for start, modify, describe, query, expire, and delete "
|
|
|
|
"operations.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printBackupContainerInfo();
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" -b, --base-url BASEURL\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Base backup URL for list operations. This looks like a Backup URL but without a backup "
|
|
|
|
"name.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --blob-credentials FILE\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" File containing blob credentials in JSON format. Can be specified multiple times for "
|
|
|
|
"multiple files. See below for more details.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --expire-before-timestamp DATETIME\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Datetime cutoff for expire operations. Requires a cluster file and will use "
|
|
|
|
"version/timestamp metadata\n"
|
|
|
|
" in the database to obtain a cutoff version very close to the timestamp given in %s.\n",
|
|
|
|
BackupAgentBase::timeFormat().c_str());
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --expire-before-version VERSION\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Version cutoff for expire operations. Deletes data files containing no data at or after "
|
|
|
|
"VERSION.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --delete-before-days NUM_DAYS\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Another way to specify version cutoff for expire operations. Deletes data files "
|
|
|
|
"containing no data at or after a\n"
|
|
|
|
" version approximately NUM_DAYS days worth of versions prior to the latest log version in "
|
|
|
|
"the backup.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" -qrv --query-restore-version VERSION\n"
|
2020-09-06 09:55:09 +08:00
|
|
|
" For query operations, set target version for restoring a backup. Set -1 for maximum\n"
|
|
|
|
" restorable version (default) and -2 for minimum restorable version.\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
printf(
|
2021-12-15 00:44:39 +08:00
|
|
|
" --query-restore-timestamp DATETIME\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" For query operations, instead of a numeric version, use this to specify a timestamp in %s\n",
|
|
|
|
BackupAgentBase::timeFormat().c_str());
|
|
|
|
printf(
|
|
|
|
" and it will be converted to a version from that time using metadata in the cluster file.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --restorable-after-timestamp DATETIME\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" For expire operations, set minimum acceptable restorability to the version equivalent of "
|
|
|
|
"DATETIME and later.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --restorable-after-version VERSION\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" For expire operations, set minimum acceptable restorability to the VERSION and later.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --min-restorable-days NUM-DAYS\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" For expire operations, set minimum acceptable restorability to approximately NUM_DAYS "
|
|
|
|
"days worth of versions\n"
|
|
|
|
" prior to the latest log version in the backup.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --version-timestamps\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
printf(" For describe operations, lookup versions in the database to obtain timestamps. A cluster "
|
|
|
|
"file is required.\n");
|
|
|
|
printf(
|
|
|
|
" -f, --force For expire operations, force expiration even if minimum restorability would be violated.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" -s, --snapshot-interval DURATION\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" For start or modify operations, specifies the backup's default target snapshot interval "
|
|
|
|
"as DURATION seconds. Defaults to %d for start operations.\n",
|
|
|
|
CLIENT_KNOBS->BACKUP_DEFAULT_SNAPSHOT_INTERVAL_SEC);
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --active-snapshot-interval DURATION\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" For modify operations, sets the desired interval for the backup's currently active "
|
|
|
|
"snapshot, relative to the start of the snapshot.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --verify-uid UID\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Specifies a UID to verify against the BackupUID of the running backup. If provided, the "
|
|
|
|
"UID is verified in the same transaction\n"
|
2019-03-06 02:44:14 +08:00
|
|
|
" which sets the new backup parameters (if the UID matches).\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -e ERRORLIMIT The maximum number of errors printed by status (default is 10).\n");
|
2020-09-01 00:43:11 +08:00
|
|
|
printf(" -k KEYS List of key ranges to backup or to filter the backup in query operations.\n"
|
2020-08-30 10:53:04 +08:00
|
|
|
" If not specified, the entire database will be backed up or no filter will be applied.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --partitioned-log-experimental Starts with new type of backup system using partitioned logs.\n");
|
2019-07-30 04:19:28 +08:00
|
|
|
printf(" -n, --dryrun For backup start or restore start, performs a trial run with no actual changes made.\n");
|
2019-07-13 01:42:06 +08:00
|
|
|
printf(" --log Enables trace file logging for the CLI session.\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" --logdir PATH Specifes the output directory for trace files. If\n"
|
|
|
|
" unspecified, defaults to the current directory. Has\n"
|
|
|
|
" no effect unless --log is specified.\n");
|
2019-08-20 03:59:14 +08:00
|
|
|
printf(" --loggroup LOG_GROUP\n"
|
|
|
|
" Sets the LogGroup field with the specified value for all\n"
|
|
|
|
" events in the trace output (defaults to `default').\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --trace-format FORMAT\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Select the format of the trace files. xml (the default) and json are supported.\n"
|
|
|
|
" Has no effect unless --log is specified.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --max-cleanup-seconds SECONDS\n"
|
2019-11-01 00:52:21 +08:00
|
|
|
" Specifies the amount of time a backup or DR needs to be stale before cleanup will\n"
|
|
|
|
" remove mutations for it. By default this is set to one hour.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --delete-data\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" This flag will cause cleanup to remove mutations for the most stale backup or DR.\n");
|
2021-02-26 05:29:23 +08:00
|
|
|
printf(" --incremental\n"
|
|
|
|
" Performs incremental backup without the base backup.\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" This option indicates to the backup agent that it will only need to record the log files, "
|
|
|
|
"and ignore the range files.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --encryption-key-file"
|
2021-06-26 06:11:03 +08:00
|
|
|
" The AES-128-GCM key in the provided file is used for encrypting backup files.\n");
|
2019-01-31 09:36:51 +08:00
|
|
|
printf(TLS_HELP);
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -w, --wait Wait for the backup to complete (allowed with `start' and `discontinue').\n");
|
|
|
|
printf(" -z, --no-stop-when-done\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Do not stop backup when restorable.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -h, --help Display this help and exit.\n");
|
2018-01-17 20:09:43 +08:00
|
|
|
|
|
|
|
if (devhelp) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
printf(" -n Create a new console.\n");
|
|
|
|
printf(" -q Disable error dialog on crash.\n");
|
|
|
|
printf(" --parentpid PID\n");
|
|
|
|
printf(" Specify a process after whose termination to exit.\n");
|
|
|
|
#endif
|
|
|
|
printf(" --deep For describe operations, do not use cached metadata. Warning: Very slow\n");
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" KEYS FORMAT: \"<BEGINKEY> <ENDKEY>\" [...]\n");
|
2018-01-23 07:50:28 +08:00
|
|
|
printf("\n");
|
|
|
|
puts(BlobCredentialInfo);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
static void printRestoreUsage(bool devhelp) {
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("Usage: %s [TOP_LEVEL_OPTIONS] (start | status | abort | wait) [OPTIONS]\n\n",
|
|
|
|
exeRestore.toString().c_str());
|
2020-09-12 02:35:35 +08:00
|
|
|
|
|
|
|
printf(" TOP LEVEL OPTIONS:\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --build-flags Print build information and exit.\n");
|
2020-09-12 02:35:35 +08:00
|
|
|
printf(" -v, --version Print version information and exit.\n");
|
|
|
|
printf(" -h, --help Display this help and exit.\n");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf(" ACTION OPTIONS:\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
// printf(" FOLDERS Paths to folders containing the backup files.\n");
|
2020-09-12 02:35:35 +08:00
|
|
|
printf(" Options for all commands:\n\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --dest-cluster-file CONNFILE\n");
|
2019-03-06 04:28:05 +08:00
|
|
|
printf(" The cluster file to restore data into.\n");
|
|
|
|
printf(" -t, --tagname TAGNAME\n");
|
|
|
|
printf(" The restore tag to act on. Default is 'default'\n");
|
2020-09-12 02:35:35 +08:00
|
|
|
printf("\n");
|
|
|
|
printf(" Options for start:\n\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -r URL The Backup URL for the restore to read from.\n");
|
|
|
|
printBackupContainerInfo();
|
2019-03-06 04:28:05 +08:00
|
|
|
printf(" -w, --waitfordone\n");
|
|
|
|
printf(" Wait for the restore to complete before exiting. Prints progress updates.\n");
|
|
|
|
printf(" -k KEYS List of key ranges from the backup to restore.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --remove-prefix PREFIX\n");
|
2019-03-06 04:28:05 +08:00
|
|
|
printf(" Prefix to remove from the restored keys.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --add-prefix PREFIX\n");
|
2019-03-06 04:28:05 +08:00
|
|
|
printf(" Prefix to add to the restored keys\n");
|
|
|
|
printf(" -n, --dryrun Perform a trial run with no changes made.\n");
|
2019-07-13 01:42:06 +08:00
|
|
|
printf(" --log Enables trace file logging for the CLI session.\n"
|
2020-07-28 12:40:20 +08:00
|
|
|
" --logdir PATH Specifies the output directory for trace files. If\n"
|
|
|
|
" unspecified, defaults to the current directory. Has\n"
|
|
|
|
" no effect unless --log is specified.\n");
|
2019-08-20 03:59:14 +08:00
|
|
|
printf(" --loggroup LOG_GROUP\n"
|
|
|
|
" Sets the LogGroup field with the specified value for all\n"
|
|
|
|
" events in the trace output (defaults to `default').\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --trace-format FORMAT\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Select the format of the trace files. xml (the default) and json are supported.\n"
|
|
|
|
" Has no effect unless --log is specified.\n");
|
2021-02-26 05:29:23 +08:00
|
|
|
printf(" --incremental\n"
|
|
|
|
" Performs incremental restore without the base backup.\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" This tells the backup agent to only replay the log files from the backup source.\n"
|
|
|
|
" This also allows a restore to be performed into a non-empty destination database.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --begin-version\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" To be used in conjunction with incremental restore.\n"
|
|
|
|
" Indicates to the backup agent to only begin replaying log files from a certain version, "
|
|
|
|
"instead of the entire set.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --encryption-key-file"
|
2021-06-26 06:11:03 +08:00
|
|
|
" The AES-128-GCM key in the provided file is used for decrypting backup files.\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
printf(TLS_HELP);
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -v DBVERSION The version at which the database will be restored.\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
printf(" --timestamp Instead of a numeric version, use this to specify a timestamp in %s\n",
|
|
|
|
BackupAgentBase::timeFormat().c_str());
|
|
|
|
printf(
|
|
|
|
" and it will be converted to a version from that time using metadata in orig_cluster_file.\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --orig-cluster-file CONNFILE\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
printf(" The cluster file for the original database from which the backup was created. The "
|
|
|
|
"original database\n");
|
2019-03-06 04:28:05 +08:00
|
|
|
printf(" is only needed to convert a --timestamp argument to a database version.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (devhelp) {
|
2017-05-26 04:48:44 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
printf(" -q Disable error dialog on crash.\n");
|
|
|
|
printf(" --parentpid PID\n");
|
|
|
|
printf(" Specify a process after whose termination to exit.\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-01-23 07:50:28 +08:00
|
|
|
printf("\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" KEYS FORMAT: \"<BEGINKEY> <ENDKEY>\" [...]\n");
|
2018-01-23 07:50:28 +08:00
|
|
|
printf("\n");
|
|
|
|
puts(BlobCredentialInfo);
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-02 08:00:13 +08:00
|
|
|
static void printFastRestoreUsage(bool devhelp) {
|
2020-07-28 12:40:20 +08:00
|
|
|
printf(" NOTE: Fast restore aims to support the same fdbrestore option list.\n");
|
|
|
|
printf(" But fast restore is still under development. The options may not be fully supported.\n");
|
2021-12-15 01:59:14 +08:00
|
|
|
printf(" Supported options are: --dest-cluster-file, -r, --waitfordone, --logdir\n");
|
2020-07-28 12:40:20 +08:00
|
|
|
printRestoreUsage(devhelp);
|
2019-01-25 08:26:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
static void printDBAgentUsage(bool devhelp) {
|
|
|
|
printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n");
|
|
|
|
printf("Usage: %s [OPTIONS]\n\n", exeDatabaseAgent.toString().c_str());
|
2021-08-21 03:55:13 +08:00
|
|
|
printf(" -d, --destination CONNFILE\n"
|
|
|
|
" The path of a file containing the connection string for the\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" destination FoundationDB cluster.\n");
|
2021-08-21 03:55:13 +08:00
|
|
|
printf(" -s, --source CONNFILE\n"
|
|
|
|
" The path of a file containing the connection string for the\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" source FoundationDB cluster.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" --log Enables trace file logging for the CLI session.\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" --logdir PATH Specifes the output directory for trace files. If\n"
|
|
|
|
" unspecified, defaults to the current directory. Has\n"
|
|
|
|
" no effect unless --log is specified.\n");
|
2019-08-20 03:59:14 +08:00
|
|
|
printf(" --loggroup LOG_GROUP\n"
|
|
|
|
" Sets the LogGroup field with the specified value for all\n"
|
|
|
|
" events in the trace output (defaults to `default').\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --trace-format FORMAT\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Select the format of the trace files. xml (the default) and json are supported.\n"
|
|
|
|
" Has no effect unless --log is specified.\n");
|
2021-08-21 03:55:13 +08:00
|
|
|
printf(" -m, --memory SIZE\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Memory limit. The default value is 8GiB. When specified\n"
|
|
|
|
" without a unit, MiB is assumed.\n");
|
2019-01-31 09:36:51 +08:00
|
|
|
printf(TLS_HELP);
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --build-flags Print build information and exit.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -v, --version Print version information and exit.\n");
|
|
|
|
printf(" -h, --help Display this help and exit.\n");
|
|
|
|
if (devhelp) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
printf(" -n Create a new console.\n");
|
|
|
|
printf(" -q Disable error dialog on crash.\n");
|
|
|
|
printf(" --parentpid PID\n");
|
|
|
|
printf(" Specify a process after whose termination to exit.\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printDBBackupUsage(bool devhelp) {
|
|
|
|
printf("FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("Usage: %s [TOP_LEVEL_OPTIONS] (start | status | switch | abort | pause | resume) [OPTIONS]\n\n",
|
|
|
|
exeDatabaseBackup.toString().c_str());
|
2020-09-12 02:35:35 +08:00
|
|
|
|
|
|
|
printf(" TOP LEVEL OPTIONS:\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --build-flags Print build information and exit.\n");
|
2020-09-12 02:35:35 +08:00
|
|
|
printf(" -v, --version Print version information and exit.\n");
|
|
|
|
printf(" -h, --help Display this help and exit.\n");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf(" ACTION OPTIONS:\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -d, --destination CONNFILE\n"
|
|
|
|
" The path of a file containing the connection string for the\n");
|
|
|
|
printf(" destination FoundationDB cluster.\n");
|
|
|
|
printf(" -s, --source CONNFILE\n"
|
|
|
|
" The path of a file containing the connection string for the\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" source FoundationDB cluster.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -e ERRORLIMIT The maximum number of errors printed by status (default is 10).\n");
|
|
|
|
printf(" -k KEYS List of key ranges to backup.\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" If not specified, the entire database will be backed up.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" --cleanup Abort will attempt to stop mutation logging on the source cluster.\n");
|
2020-07-08 01:18:18 +08:00
|
|
|
printf(" --dstonly Abort will not make any changes on the source cluster.\n");
|
2019-01-31 09:36:51 +08:00
|
|
|
printf(TLS_HELP);
|
2019-07-13 01:42:06 +08:00
|
|
|
printf(" --log Enables trace file logging for the CLI session.\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" --logdir PATH Specifes the output directory for trace files. If\n"
|
|
|
|
" unspecified, defaults to the current directory. Has\n"
|
|
|
|
" no effect unless --log is specified.\n");
|
2019-08-20 03:59:14 +08:00
|
|
|
printf(" --loggroup LOG_GROUP\n"
|
|
|
|
" Sets the LogGroup field with the specified value for all\n"
|
|
|
|
" events in the trace output (defaults to `default').\n");
|
2021-12-15 00:44:39 +08:00
|
|
|
printf(" --trace-format FORMAT\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" Select the format of the trace files. xml (the default) and json are supported.\n"
|
|
|
|
" Has no effect unless --log is specified.\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
printf(" -h, --help Display this help and exit.\n");
|
|
|
|
printf("\n"
|
2021-03-11 02:06:03 +08:00
|
|
|
" KEYS FORMAT: \"<BEGINKEY> <ENDKEY>\" [...]\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
if (devhelp) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
printf(" -n Create a new console.\n");
|
|
|
|
printf(" -q Disable error dialog on crash.\n");
|
|
|
|
printf(" --parentpid PID\n");
|
|
|
|
printf(" Specify a process after whose termination to exit.\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
static void printUsage(ProgramExe programExe, bool devhelp) {
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (programExe) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::AGENT:
|
2017-05-26 04:48:44 +08:00
|
|
|
printAgentUsage(devhelp);
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::BACKUP:
|
2017-05-26 04:48:44 +08:00
|
|
|
printBackupUsage(devhelp);
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::RESTORE:
|
2017-05-26 04:48:44 +08:00
|
|
|
printRestoreUsage(devhelp);
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::FASTRESTORE_TOOL:
|
2019-01-25 08:26:57 +08:00
|
|
|
printFastRestoreUsage(devhelp);
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DR_AGENT:
|
2017-05-26 04:48:44 +08:00
|
|
|
printDBAgentUsage(devhelp);
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DB_BACKUP:
|
2017-05-26 04:48:44 +08:00
|
|
|
printDBBackupUsage(devhelp);
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern bool g_crashOnError;
|
|
|
|
|
|
|
|
// Return the type of program executable based on the name of executable file
|
2020-11-15 14:02:46 +08:00
|
|
|
ProgramExe getProgramType(std::string programExe) {
|
|
|
|
ProgramExe enProgramExe = ProgramExe::UNDEFINED;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// lowercase the string
|
|
|
|
std::transform(programExe.begin(), programExe.end(), programExe.begin(), ::tolower);
|
|
|
|
|
|
|
|
// Remove the extension, if Windows
|
|
|
|
#ifdef _WIN32
|
|
|
|
size_t lastDot = programExe.find_last_of(".");
|
|
|
|
if (lastDot != std::string::npos) {
|
|
|
|
size_t lastSlash = programExe.find_last_of("\\");
|
|
|
|
|
|
|
|
// Ensure last dot is after last slash, if present
|
2021-03-11 02:06:03 +08:00
|
|
|
if ((lastSlash == std::string::npos) || (lastSlash < lastDot)) {
|
2017-05-26 04:48:44 +08:00
|
|
|
programExe = programExe.substr(0, lastDot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-03-06 13:17:56 +08:00
|
|
|
// For debugging convenience, remove .debug suffix if present.
|
2021-03-11 02:06:03 +08:00
|
|
|
if (StringRef(programExe).endsWith(LiteralStringRef(".debug")))
|
2019-03-06 13:17:56 +08:00
|
|
|
programExe = programExe.substr(0, programExe.size() - 6);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Check if backup agent
|
2021-03-11 02:06:03 +08:00
|
|
|
if ((programExe.length() >= exeAgent.size()) &&
|
|
|
|
(programExe.compare(programExe.length() - exeAgent.size(), exeAgent.size(), (const char*)exeAgent.begin()) ==
|
|
|
|
0)) {
|
2020-11-15 14:02:46 +08:00
|
|
|
enProgramExe = ProgramExe::AGENT;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if backup
|
2021-03-11 02:06:03 +08:00
|
|
|
else if ((programExe.length() >= exeBackup.size()) &&
|
|
|
|
(programExe.compare(
|
|
|
|
programExe.length() - exeBackup.size(), exeBackup.size(), (const char*)exeBackup.begin()) == 0)) {
|
2020-11-15 14:02:46 +08:00
|
|
|
enProgramExe = ProgramExe::BACKUP;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if restore
|
2021-03-11 02:06:03 +08:00
|
|
|
else if ((programExe.length() >= exeRestore.size()) &&
|
|
|
|
(programExe.compare(
|
|
|
|
programExe.length() - exeRestore.size(), exeRestore.size(), (const char*)exeRestore.begin()) == 0)) {
|
2020-11-15 14:02:46 +08:00
|
|
|
enProgramExe = ProgramExe::RESTORE;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2019-04-13 04:49:53 +08:00
|
|
|
// Check if restore
|
2020-07-02 23:16:39 +08:00
|
|
|
else if ((programExe.length() >= exeFastRestoreTool.size()) &&
|
2021-03-11 02:06:03 +08:00
|
|
|
(programExe.compare(programExe.length() - exeFastRestoreTool.size(),
|
|
|
|
exeFastRestoreTool.size(),
|
2020-07-02 23:16:39 +08:00
|
|
|
(const char*)exeFastRestoreTool.begin()) == 0)) {
|
2020-11-15 14:02:46 +08:00
|
|
|
enProgramExe = ProgramExe::FASTRESTORE_TOOL;
|
2019-01-25 08:26:57 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// Check if db agent
|
2019-08-02 08:00:13 +08:00
|
|
|
else if ((programExe.length() >= exeDatabaseAgent.size()) &&
|
2021-03-11 02:06:03 +08:00
|
|
|
(programExe.compare(programExe.length() - exeDatabaseAgent.size(),
|
|
|
|
exeDatabaseAgent.size(),
|
2019-08-02 08:00:13 +08:00
|
|
|
(const char*)exeDatabaseAgent.begin()) == 0)) {
|
2020-11-15 14:02:46 +08:00
|
|
|
enProgramExe = ProgramExe::DR_AGENT;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if db backup
|
2019-08-02 08:00:13 +08:00
|
|
|
else if ((programExe.length() >= exeDatabaseBackup.size()) &&
|
2021-03-11 02:06:03 +08:00
|
|
|
(programExe.compare(programExe.length() - exeDatabaseBackup.size(),
|
|
|
|
exeDatabaseBackup.size(),
|
2019-08-02 08:00:13 +08:00
|
|
|
(const char*)exeDatabaseBackup.begin()) == 0)) {
|
2020-11-15 14:02:46 +08:00
|
|
|
enProgramExe = ProgramExe::DB_BACKUP;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return enProgramExe;
|
|
|
|
}
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
BackupType getBackupType(std::string backupType) {
|
2021-01-31 05:30:43 +08:00
|
|
|
BackupType enBackupType = BackupType::UNDEFINED;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// lowercase the string
|
|
|
|
std::transform(backupType.begin(), backupType.end(), backupType.begin(), ::tolower);
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
static std::map<std::string, BackupType> values;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (values.empty()) {
|
2021-01-31 05:30:43 +08:00
|
|
|
values["start"] = BackupType::START;
|
|
|
|
values["status"] = BackupType::STATUS;
|
|
|
|
values["abort"] = BackupType::ABORT;
|
|
|
|
values["cleanup"] = BackupType::CLEANUP;
|
|
|
|
values["wait"] = BackupType::WAIT;
|
|
|
|
values["discontinue"] = BackupType::DISCONTINUE;
|
|
|
|
values["pause"] = BackupType::PAUSE;
|
|
|
|
values["resume"] = BackupType::RESUME;
|
|
|
|
values["expire"] = BackupType::EXPIRE;
|
|
|
|
values["delete"] = BackupType::DELETE_BACKUP;
|
|
|
|
values["describe"] = BackupType::DESCRIBE;
|
|
|
|
values["list"] = BackupType::LIST;
|
|
|
|
values["query"] = BackupType::QUERY;
|
|
|
|
values["dump"] = BackupType::DUMP;
|
|
|
|
values["modify"] = BackupType::MODIFY;
|
2022-01-18 15:41:29 +08:00
|
|
|
values["tags"] = BackupType::TAGS;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto i = values.find(backupType);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (i != values.end())
|
2017-05-26 04:48:44 +08:00
|
|
|
enBackupType = i->second;
|
|
|
|
|
|
|
|
return enBackupType;
|
|
|
|
}
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
RestoreType getRestoreType(std::string name) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (name == "start")
|
|
|
|
return RestoreType::START;
|
|
|
|
if (name == "abort")
|
|
|
|
return RestoreType::ABORT;
|
|
|
|
if (name == "status")
|
|
|
|
return RestoreType::STATUS;
|
|
|
|
if (name == "wait")
|
|
|
|
return RestoreType::WAIT;
|
2020-11-15 14:02:46 +08:00
|
|
|
return RestoreType::UNKNOWN;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
DBType getDBType(std::string dbType) {
|
|
|
|
DBType enBackupType = DBType::UNDEFINED;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// lowercase the string
|
|
|
|
std::transform(dbType.begin(), dbType.end(), dbType.begin(), ::tolower);
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
static std::map<std::string, DBType> values;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (values.empty()) {
|
2020-11-15 14:02:46 +08:00
|
|
|
values["start"] = DBType::START;
|
|
|
|
values["status"] = DBType::STATUS;
|
|
|
|
values["switch"] = DBType::SWITCH;
|
|
|
|
values["abort"] = DBType::ABORT;
|
|
|
|
values["pause"] = DBType::PAUSE;
|
|
|
|
values["resume"] = DBType::RESUME;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto i = values.find(dbType);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (i != values.end())
|
2017-05-26 04:48:44 +08:00
|
|
|
enBackupType = i->second;
|
|
|
|
|
|
|
|
return enBackupType;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<std::string> getLayerStatus(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
std::string name,
|
|
|
|
std::string id,
|
|
|
|
ProgramExe exe,
|
|
|
|
Database dest,
|
2021-07-17 15:11:40 +08:00
|
|
|
Snapshot snapshot = Snapshot::False) {
|
2017-05-26 04:48:44 +08:00
|
|
|
// This process will write a document that looks like this:
|
|
|
|
// { backup : { $expires : {<subdoc>}, version: <version from approximately 30 seconds from now> }
|
|
|
|
// so that the value under 'backup' will eventually expire to null and thus be ignored by
|
|
|
|
// readers of status. This is because if all agents die then they can no longer clean up old
|
|
|
|
// status docs from other dead agents.
|
|
|
|
|
|
|
|
state Version readVer = wait(tr->getReadVersion());
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
state json_spirit::mValue layersRootValue; // Will contain stuff that goes into the doc at the layers status root
|
|
|
|
JSONDoc layersRoot(layersRootValue); // Convenient mutator / accessor for the layers root
|
|
|
|
JSONDoc op = layersRoot.subDoc(name); // Operator object for the $expires operation
|
2017-05-26 04:48:44 +08:00
|
|
|
// Create the $expires key which is where the rest of the status output will go
|
|
|
|
|
|
|
|
state JSONDoc layerRoot = op.subDoc("$expires");
|
|
|
|
// Set the version argument in the $expires operator object.
|
|
|
|
op.create("version") = readVer + 120 * CLIENT_KNOBS->CORE_VERSIONSPERSECOND;
|
|
|
|
|
|
|
|
layerRoot.create("instances_running.$sum") = 1;
|
|
|
|
layerRoot.create("last_updated.$max") = now();
|
|
|
|
|
|
|
|
state JSONDoc o = layerRoot.subDoc("instances." + id);
|
|
|
|
|
|
|
|
o.create("version") = FDB_VT_VERSION;
|
2021-03-11 02:06:03 +08:00
|
|
|
o.create("id") = id;
|
2017-05-26 04:48:44 +08:00
|
|
|
o.create("last_updated") = now();
|
2021-03-11 02:06:03 +08:00
|
|
|
o.create("memory_usage") = (int64_t)getMemoryUsage();
|
2017-05-26 04:48:44 +08:00
|
|
|
o.create("resident_size") = (int64_t)getResidentMemoryUsage();
|
|
|
|
o.create("main_thread_cpu_seconds") = getProcessorTimeThread();
|
2021-03-11 02:06:03 +08:00
|
|
|
o.create("process_cpu_seconds") = getProcessorTimeProcess();
|
2017-10-31 03:35:00 +08:00
|
|
|
o.create("configured_workers") = CLIENT_KNOBS->BACKUP_TASKS_PER_AGENT;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
if (exe == ProgramExe::AGENT) {
|
2020-10-30 11:42:23 +08:00
|
|
|
static S3BlobStoreEndpoint::Stats last_stats;
|
2017-05-26 04:48:44 +08:00
|
|
|
static double last_ts = 0;
|
2020-10-30 11:42:23 +08:00
|
|
|
S3BlobStoreEndpoint::Stats current_stats = S3BlobStoreEndpoint::s_stats;
|
2017-05-26 04:48:44 +08:00
|
|
|
JSONDoc blobstats = o.create("blob_stats");
|
|
|
|
blobstats.create("total") = current_stats.getJSON();
|
2020-10-30 11:42:23 +08:00
|
|
|
S3BlobStoreEndpoint::Stats diff = current_stats - last_stats;
|
2017-05-26 04:48:44 +08:00
|
|
|
json_spirit::mObject diffObj = diff.getJSON();
|
2021-03-11 02:06:03 +08:00
|
|
|
if (last_ts > 0)
|
2017-05-26 04:48:44 +08:00
|
|
|
diffObj["bytes_per_second"] = double(current_stats.bytes_sent - last_stats.bytes_sent) / (now() - last_ts);
|
|
|
|
blobstats.create("recent") = diffObj;
|
|
|
|
last_stats = current_stats;
|
|
|
|
last_ts = now();
|
|
|
|
|
|
|
|
JSONDoc totalBlobStats = layerRoot.subDoc("blob_recent_io");
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& p : diffObj)
|
2017-05-26 04:48:44 +08:00
|
|
|
totalBlobStats.create(p.first + ".$sum") = p.second;
|
|
|
|
|
|
|
|
state FileBackupAgent fba;
|
2019-12-19 16:29:35 +08:00
|
|
|
state std::vector<KeyBackedTag> backupTags = wait(getAllBackupTags(tr, snapshot));
|
2021-03-09 07:48:46 +08:00
|
|
|
state std::vector<Future<Optional<Version>>> tagLastRestorableVersions;
|
2017-10-31 03:35:00 +08:00
|
|
|
state std::vector<Future<EBackupState>> tagStates;
|
2017-12-15 05:54:01 +08:00
|
|
|
state std::vector<Future<Reference<IBackupContainer>>> tagContainers;
|
2017-05-26 04:48:44 +08:00
|
|
|
state std::vector<Future<int64_t>> tagRangeBytes;
|
|
|
|
state std::vector<Future<int64_t>> tagLogBytes;
|
2019-12-19 16:29:35 +08:00
|
|
|
state Future<Optional<Value>> fBackupPaused = tr->get(fba.taskBucket->getPauseKey(), snapshot);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-09-07 11:06:32 +08:00
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
2017-10-14 08:40:00 +08:00
|
|
|
state std::vector<KeyBackedTag>::iterator tag;
|
2017-11-04 05:02:03 +08:00
|
|
|
state std::vector<UID> backupTagUids;
|
2017-10-14 08:40:00 +08:00
|
|
|
for (tag = backupTags.begin(); tag != backupTags.end(); tag++) {
|
2019-12-19 16:29:35 +08:00
|
|
|
UidAndAbortedFlagT uidAndAbortedFlag = wait(tag->getOrThrow(tr, snapshot));
|
2017-10-31 03:35:00 +08:00
|
|
|
BackupConfig config(uidAndAbortedFlag.first);
|
2017-11-04 05:02:03 +08:00
|
|
|
backupTagUids.push_back(config.getUid());
|
2017-09-07 11:06:32 +08:00
|
|
|
|
2019-12-19 16:29:35 +08:00
|
|
|
tagStates.push_back(config.stateEnum().getOrThrow(tr, snapshot));
|
|
|
|
tagRangeBytes.push_back(config.rangeBytesWritten().getD(tr, snapshot, 0));
|
|
|
|
tagLogBytes.push_back(config.logBytesWritten().getD(tr, snapshot, 0));
|
|
|
|
tagContainers.push_back(config.backupContainer().getOrThrow(tr, snapshot));
|
|
|
|
tagLastRestorableVersions.push_back(fba.getLastRestorable(tr, StringRef(tag->tagName), snapshot));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(waitForAll(tagLastRestorableVersions) && waitForAll(tagStates) && waitForAll(tagContainers) &&
|
|
|
|
waitForAll(tagRangeBytes) && waitForAll(tagLogBytes) && success(fBackupPaused));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
JSONDoc tagsRoot = layerRoot.subDoc("tags.$latest");
|
|
|
|
layerRoot.create("tags.timestamp") = now();
|
2021-03-11 02:06:03 +08:00
|
|
|
layerRoot.create("total_workers.$sum") =
|
|
|
|
fBackupPaused.get().present() ? 0 : CLIENT_KNOBS->BACKUP_TASKS_PER_AGENT;
|
2017-12-15 05:54:01 +08:00
|
|
|
layerRoot.create("paused.$latest") = fBackupPaused.get().present();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-09-07 11:06:32 +08:00
|
|
|
int j = 0;
|
|
|
|
for (KeyBackedTag eachTag : backupTags) {
|
2020-09-24 05:50:34 +08:00
|
|
|
EBackupState status = tagStates[j].get();
|
2021-03-11 02:06:03 +08:00
|
|
|
const char* statusText = fba.getStateText(status);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// The object for this backup tag inside this instance's subdocument
|
2017-09-07 11:06:32 +08:00
|
|
|
JSONDoc tagRoot = tagsRoot.subDoc(eachTag.tagName);
|
2017-12-15 05:54:01 +08:00
|
|
|
tagRoot.create("current_container") = tagContainers[j].get()->getURL();
|
2017-05-26 04:48:44 +08:00
|
|
|
tagRoot.create("current_status") = statusText;
|
2021-03-09 07:48:46 +08:00
|
|
|
if (tagLastRestorableVersions[j].get().present()) {
|
|
|
|
Version last_restorable_version = tagLastRestorableVersions[j].get().get();
|
|
|
|
double last_restorable_seconds_behind =
|
|
|
|
((double)readVer - last_restorable_version) / CLIENT_KNOBS->CORE_VERSIONSPERSECOND;
|
|
|
|
tagRoot.create("last_restorable_version") = last_restorable_version;
|
|
|
|
tagRoot.create("last_restorable_seconds_behind") = last_restorable_seconds_behind;
|
|
|
|
}
|
2020-09-24 05:50:34 +08:00
|
|
|
tagRoot.create("running_backup") =
|
|
|
|
(status == EBackupState::STATE_RUNNING_DIFFERENTIAL || status == EBackupState::STATE_RUNNING);
|
|
|
|
tagRoot.create("running_backup_is_restorable") = (status == EBackupState::STATE_RUNNING_DIFFERENTIAL);
|
2017-05-26 04:48:44 +08:00
|
|
|
tagRoot.create("range_bytes_written") = tagRangeBytes[j].get();
|
|
|
|
tagRoot.create("mutation_log_bytes_written") = tagLogBytes[j].get();
|
2017-11-04 05:02:03 +08:00
|
|
|
tagRoot.create("mutation_stream_id") = backupTagUids[j].toString();
|
2017-09-07 11:06:32 +08:00
|
|
|
|
|
|
|
j++;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2020-11-15 14:02:46 +08:00
|
|
|
} else if (exe == ProgramExe::DR_AGENT) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state DatabaseBackupAgent dba;
|
|
|
|
state Reference<ReadYourWritesTransaction> tr2(new ReadYourWritesTransaction(dest));
|
|
|
|
tr2->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr2->setOption(FDBTransactionOptions::LOCK_AWARE);
|
2021-05-04 04:14:16 +08:00
|
|
|
state RangeResult tagNames = wait(tr2->getRange(dba.tagNames.range(), 10000, snapshot));
|
2017-05-26 04:48:44 +08:00
|
|
|
state std::vector<Future<Optional<Key>>> backupVersion;
|
2020-09-24 05:50:34 +08:00
|
|
|
state std::vector<Future<EBackupState>> backupStatus;
|
2017-05-26 04:48:44 +08:00
|
|
|
state std::vector<Future<int64_t>> tagRangeBytesDR;
|
|
|
|
state std::vector<Future<int64_t>> tagLogBytesDR;
|
2019-12-19 16:29:35 +08:00
|
|
|
state Future<Optional<Value>> fDRPaused = tr->get(dba.taskBucket->getPauseKey(), snapshot);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-11-04 05:02:03 +08:00
|
|
|
state std::vector<UID> drTagUids;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < tagNames.size(); i++) {
|
2019-12-19 16:29:35 +08:00
|
|
|
backupVersion.push_back(tr2->get(tagNames[i].value.withPrefix(applyMutationsBeginRange.begin), snapshot));
|
2017-05-26 04:48:44 +08:00
|
|
|
UID tagUID = BinaryReader::fromStringRef<UID>(tagNames[i].value, Unversioned());
|
2017-11-04 05:02:03 +08:00
|
|
|
drTagUids.push_back(tagUID);
|
2019-12-19 16:29:35 +08:00
|
|
|
backupStatus.push_back(dba.getStateValue(tr2, tagUID, snapshot));
|
|
|
|
tagRangeBytesDR.push_back(dba.getRangeBytesWritten(tr2, tagUID, snapshot));
|
|
|
|
tagLogBytesDR.push_back(dba.getLogBytesWritten(tr2, tagUID, snapshot));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(waitForAll(backupStatus) && waitForAll(backupVersion) && waitForAll(tagRangeBytesDR) &&
|
|
|
|
waitForAll(tagLogBytesDR) && success(fDRPaused));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
JSONDoc tagsRoot = layerRoot.subDoc("tags.$latest");
|
|
|
|
layerRoot.create("tags.timestamp") = now();
|
2017-12-15 05:54:01 +08:00
|
|
|
layerRoot.create("total_workers.$sum") = fDRPaused.get().present() ? 0 : CLIENT_KNOBS->BACKUP_TASKS_PER_AGENT;
|
|
|
|
layerRoot.create("paused.$latest") = fDRPaused.get().present();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < tagNames.size(); i++) {
|
|
|
|
std::string tagName = dba.sourceTagNames.unpack(tagNames[i].key).getString(0).toString();
|
|
|
|
|
2020-09-24 05:50:34 +08:00
|
|
|
auto status = backupStatus[i].get();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
JSONDoc tagRoot = tagsRoot.create(tagName);
|
2020-09-24 05:50:34 +08:00
|
|
|
tagRoot.create("running_backup") =
|
|
|
|
(status == EBackupState::STATE_RUNNING_DIFFERENTIAL || status == EBackupState::STATE_RUNNING);
|
|
|
|
tagRoot.create("running_backup_is_restorable") = (status == EBackupState::STATE_RUNNING_DIFFERENTIAL);
|
2017-05-26 04:48:44 +08:00
|
|
|
tagRoot.create("range_bytes_written") = tagRangeBytesDR[i].get();
|
|
|
|
tagRoot.create("mutation_log_bytes_written") = tagLogBytesDR[i].get();
|
2017-11-04 05:02:03 +08:00
|
|
|
tagRoot.create("mutation_stream_id") = drTagUids[i].toString();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
if (backupVersion[i].get().present()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
double seconds_behind = ((double)readVer - BinaryReader::fromStringRef<Version>(
|
|
|
|
backupVersion[i].get().get(), Unversioned())) /
|
|
|
|
CLIENT_KNOBS->CORE_VERSIONSPERSECOND;
|
2017-05-26 04:48:44 +08:00
|
|
|
tagRoot.create("seconds_behind") = seconds_behind;
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("BackupMetrics").detail("SecondsBehind", seconds_behind);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tagRoot.create("backup_state") = BackupAgentBase::getStateText(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string json = json_spirit::write_string(layersRootValue);
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
2022-03-13 21:02:11 +08:00
|
|
|
// Check for unparsable or expired statuses and delete them.
|
2017-05-26 04:48:44 +08:00
|
|
|
// First checks the first doc in the key range, and if it is valid, alive and not "me" then
|
|
|
|
// returns. Otherwise, checks the rest of the range as well.
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> cleanupStatus(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
std::string rootKey,
|
|
|
|
std::string name,
|
|
|
|
std::string id,
|
|
|
|
int limit = 1) {
|
2021-07-17 15:11:40 +08:00
|
|
|
state RangeResult docs = wait(tr->getRange(KeyRangeRef(rootKey, strinc(rootKey)), limit, Snapshot::True));
|
2017-05-26 04:48:44 +08:00
|
|
|
state bool readMore = false;
|
|
|
|
state int i;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (i = 0; i < docs.size(); ++i) {
|
2017-05-26 04:48:44 +08:00
|
|
|
json_spirit::mValue docValue;
|
|
|
|
try {
|
|
|
|
json_spirit::read_string(docs[i].value.toString(), docValue);
|
|
|
|
JSONDoc doc(docValue);
|
|
|
|
// Update the reference version for $expires
|
|
|
|
JSONDoc::expires_reference_version = tr->getReadVersion().get();
|
|
|
|
// Evaluate the operators in the document, which will reduce to nothing if it is expired.
|
|
|
|
doc.cleanOps();
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!doc.has(name + ".last_updated"))
|
2017-05-26 04:48:44 +08:00
|
|
|
throw Error();
|
|
|
|
|
|
|
|
// Alive and valid.
|
|
|
|
// If limit == 1 and id is present then read more
|
2021-03-11 02:06:03 +08:00
|
|
|
if (limit == 1 && doc.has(name + ".instances." + id))
|
2017-05-26 04:48:44 +08:00
|
|
|
readMore = true;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2017-05-26 04:48:44 +08:00
|
|
|
// If doc can't be parsed or isn't alive, delete it.
|
2022-02-25 04:25:52 +08:00
|
|
|
TraceEvent(SevWarn, "RemovedDeadBackupLayerStatus").errorUnsuppressed(e).detail("Key", docs[i].key);
|
2017-05-26 04:48:44 +08:00
|
|
|
tr->clear(docs[i].key);
|
|
|
|
// If limit is 1 then read more.
|
2021-03-11 02:06:03 +08:00
|
|
|
if (limit == 1)
|
2017-05-26 04:48:44 +08:00
|
|
|
readMore = true;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
if (readMore) {
|
2017-05-26 04:48:44 +08:00
|
|
|
limit = 10000;
|
2021-07-17 15:11:40 +08:00
|
|
|
RangeResult docs2 = wait(tr->getRange(KeyRangeRef(rootKey, strinc(rootKey)), limit, Snapshot::True));
|
2017-05-26 04:48:44 +08:00
|
|
|
docs = std::move(docs2);
|
|
|
|
readMore = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get layer status document for just this layer
|
|
|
|
ACTOR Future<json_spirit::mObject> getLayerStatus(Database src, std::string rootKey) {
|
|
|
|
state Transaction tr(src);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
2021-05-04 04:14:16 +08:00
|
|
|
state RangeResult kvPairs =
|
2020-07-05 03:03:47 +08:00
|
|
|
wait(tr.getRange(KeyRangeRef(rootKey, strinc(rootKey)), GetRangeLimits::ROW_LIMIT_UNLIMITED));
|
2017-05-26 04:48:44 +08:00
|
|
|
json_spirit::mObject statusDoc;
|
|
|
|
JSONDoc modifier(statusDoc);
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& kv : kvPairs) {
|
2017-05-26 04:48:44 +08:00
|
|
|
json_spirit::mValue docValue;
|
|
|
|
json_spirit::read_string(kv.value.toString(), docValue);
|
|
|
|
modifier.absorb(docValue);
|
|
|
|
}
|
|
|
|
JSONDoc::expires_reference_version = (uint64_t)tr.getReadVersion().get();
|
|
|
|
modifier.cleanOps();
|
|
|
|
return statusDoc;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Read layer status for this layer and get the total count of agent processes (instances) then adjust the poll delay
|
|
|
|
// based on that and BACKUP_AGGREGATE_POLL_RATE
|
2021-07-06 04:20:43 +08:00
|
|
|
ACTOR Future<Void> updateAgentPollRate(Database src,
|
|
|
|
std::string rootKey,
|
|
|
|
std::string name,
|
|
|
|
std::shared_ptr<double> pollDelay) {
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
json_spirit::mObject status = wait(getLayerStatus(src, rootKey));
|
|
|
|
int64_t processes = 0;
|
|
|
|
// If instances count is present and greater than 0 then update pollDelay
|
2021-03-11 02:06:03 +08:00
|
|
|
if (JSONDoc(status).tryGet<int64_t>(name + ".instances_running", processes) && processes > 0) {
|
2017-05-26 04:48:44 +08:00
|
|
|
// The aggregate poll rate is the target poll rate for all agent processes in the cluster
|
2021-03-11 02:06:03 +08:00
|
|
|
// The poll rate (polls/sec) for a single processes is aggregate poll rate / processes, and pollDelay is
|
|
|
|
// the inverse of that
|
2017-05-26 04:48:44 +08:00
|
|
|
*pollDelay = (double)processes / CLIENT_KNOBS->BACKUP_AGGREGATE_POLL_RATE;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2017-05-26 04:48:44 +08:00
|
|
|
TraceEvent(SevWarn, "BackupAgentPollRateUpdateError").error(e);
|
|
|
|
}
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(CLIENT_KNOBS->BACKUP_AGGREGATE_POLL_RATE_UPDATE_INTERVAL));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> statusUpdateActor(Database statusUpdateDest,
|
|
|
|
std::string name,
|
|
|
|
ProgramExe exe,
|
2021-07-06 04:20:43 +08:00
|
|
|
std::shared_ptr<double> pollDelay,
|
2020-11-15 14:02:46 +08:00
|
|
|
Database taskDest = Database(),
|
|
|
|
std::string id = nondeterministicRandom()->randomUniqueID().toString()) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state std::string metaKey = layerStatusMetaPrefixRange.begin.toString() + "json/" + name;
|
|
|
|
state std::string rootKey = backupStatusPrefixRange.begin.toString() + name + "/json";
|
|
|
|
state std::string instanceKey = rootKey + "/" + "agent-" + id;
|
|
|
|
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(statusUpdateDest));
|
|
|
|
state Future<Void> pollRateUpdater;
|
|
|
|
|
|
|
|
// Register the existence of this layer in the meta key space
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
tr->set(metaKey, rootKey);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr->commit());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr->onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write status periodically
|
|
|
|
loop {
|
|
|
|
tr->reset();
|
|
|
|
try {
|
2021-03-11 02:06:03 +08:00
|
|
|
loop {
|
2017-05-26 04:48:44 +08:00
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
2021-07-03 12:41:50 +08:00
|
|
|
state Future<std::string> futureStatusDoc =
|
2021-07-17 15:11:40 +08:00
|
|
|
getLayerStatus(tr, name, id, exe, taskDest, Snapshot::True);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(cleanupStatus(tr, rootKey, name, id));
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string statusdoc = wait(futureStatusDoc);
|
|
|
|
tr->set(instanceKey, statusdoc);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr->commit());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr->onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(delay(CLIENT_KNOBS->BACKUP_STATUS_DELAY *
|
|
|
|
((1.0 - CLIENT_KNOBS->BACKUP_STATUS_JITTER) +
|
|
|
|
2 * deterministicRandom()->random01() * CLIENT_KNOBS->BACKUP_STATUS_JITTER)));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Now that status was written at least once by this process (and hopefully others), start the poll rate
|
|
|
|
// control updater if it wasn't started yet
|
2021-07-06 04:20:43 +08:00
|
|
|
if (!pollRateUpdater.isValid())
|
2017-05-26 04:48:44 +08:00
|
|
|
pollRateUpdater = updateAgentPollRate(statusUpdateDest, rootKey, name, pollDelay);
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2017-05-26 04:48:44 +08:00
|
|
|
TraceEvent(SevWarnAlways, "UnableToWriteStatus").error(e);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(10.0));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> runDBAgent(Database src, Database dest) {
|
2021-07-06 04:20:43 +08:00
|
|
|
state std::shared_ptr<double> pollDelay = std::make_shared<double>(1.0 / CLIENT_KNOBS->BACKUP_AGGREGATE_POLL_RATE);
|
2019-05-11 05:01:52 +08:00
|
|
|
std::string id = nondeterministicRandom()->randomUniqueID().toString();
|
2021-07-06 04:20:43 +08:00
|
|
|
state Future<Void> status = statusUpdateActor(src, "dr_backup", ProgramExe::DR_AGENT, pollDelay, dest, id);
|
2020-11-15 14:02:46 +08:00
|
|
|
state Future<Void> status_other =
|
2021-07-06 04:20:43 +08:00
|
|
|
statusUpdateActor(dest, "dr_backup_dest", ProgramExe::DR_AGENT, pollDelay, dest, id);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
state DatabaseBackupAgent backupAgent(src);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
try {
|
2021-07-06 04:20:43 +08:00
|
|
|
wait(backupAgent.run(dest, pollDelay, CLIENT_KNOBS->BACKUP_TASKS_PER_AGENT));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2017-05-26 04:48:44 +08:00
|
|
|
if (e.code() == error_code_operation_cancelled)
|
|
|
|
throw;
|
|
|
|
|
|
|
|
TraceEvent(SevError, "DA_runAgent").error(e);
|
|
|
|
fprintf(stderr, "ERROR: DR agent encountered fatal error `%s'\n", e.what());
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(delay(FLOW_KNOBS->PREVENT_FAST_SPIN_DELAY));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> runAgent(Database db) {
|
2021-07-06 04:20:43 +08:00
|
|
|
state std::shared_ptr<double> pollDelay = std::make_shared<double>(1.0 / CLIENT_KNOBS->BACKUP_AGGREGATE_POLL_RATE);
|
|
|
|
state Future<Void> status = statusUpdateActor(db, "backup", ProgramExe::AGENT, pollDelay);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
try {
|
2021-07-06 04:20:43 +08:00
|
|
|
wait(backupAgent.run(db, pollDelay, CLIENT_KNOBS->BACKUP_TASKS_PER_AGENT));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2017-05-26 04:48:44 +08:00
|
|
|
if (e.code() == error_code_operation_cancelled)
|
|
|
|
throw;
|
|
|
|
|
|
|
|
TraceEvent(SevError, "BA_runAgent").error(e);
|
|
|
|
fprintf(stderr, "ERROR: backup agent encountered fatal error `%s'\n", e.what());
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(delay(FLOW_KNOBS->PREVENT_FAST_SPIN_DELAY));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> submitDBBackup(Database src,
|
|
|
|
Database dest,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
|
|
|
std::string tagName) {
|
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state DatabaseBackupAgent backupAgent(src);
|
|
|
|
|
|
|
|
// Backup everything, if no ranges were specified
|
|
|
|
if (backupRanges.size() == 0) {
|
|
|
|
backupRanges.push_back_deep(backupRanges.arena(), normalKeys);
|
|
|
|
}
|
|
|
|
|
2021-07-05 07:27:26 +08:00
|
|
|
wait(backupAgent.submitBackup(
|
2021-07-17 15:11:40 +08:00
|
|
|
dest, KeyRef(tagName), backupRanges, StopWhenDone::False, StringRef(), StringRef(), LockDB::True));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Check if a backup agent is running
|
|
|
|
bool agentRunning = wait(backupAgent.checkActive(dest));
|
|
|
|
|
|
|
|
if (!agentRunning) {
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("The DR on tag `%s' was successfully submitted but no DR agents are responding.\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Throw an error that will not display any additional information
|
|
|
|
throw actor_cancelled();
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("The DR on tag `%s' was successfully submitted.\n", printable(StringRef(tagName)).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Error& e) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (e.code()) {
|
|
|
|
case error_code_backup_error:
|
|
|
|
fprintf(stderr, "ERROR: An error was encountered during submission\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case error_code_backup_duplicate:
|
|
|
|
fprintf(stderr, "ERROR: A DR is already running on tag `%s'\n", printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> submitBackup(Database db,
|
|
|
|
std::string url,
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy,
|
2021-04-14 10:22:13 +08:00
|
|
|
int initialSnapshotIntervalSeconds,
|
2021-03-11 02:06:03 +08:00
|
|
|
int snapshotIntervalSeconds,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
|
|
|
std::string tagName,
|
|
|
|
bool dryRun,
|
2021-07-05 07:27:26 +08:00
|
|
|
WaitForComplete waitForCompletion,
|
|
|
|
StopWhenDone stopWhenDone,
|
2021-07-05 09:30:55 +08:00
|
|
|
UsePartitionedLog usePartitionedLog,
|
|
|
|
IncrementalBackupOnly incrementalBackupOnly) {
|
2020-04-01 05:54:32 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
|
|
|
|
// Backup everything, if no ranges were specified
|
|
|
|
if (backupRanges.size() == 0) {
|
|
|
|
backupRanges.push_back_deep(backupRanges.arena(), normalKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dryRun) {
|
2017-09-08 00:04:10 +08:00
|
|
|
state KeyBackedTag tag = makeBackupTag(tagName);
|
|
|
|
Optional<UidAndAbortedFlagT> uidFlag = wait(tag.get(db));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-09-08 00:04:10 +08:00
|
|
|
if (uidFlag.present()) {
|
|
|
|
BackupConfig config(uidFlag.get().first);
|
|
|
|
EBackupState backupStatus = wait(config.stateEnum().getOrThrow(db));
|
|
|
|
|
|
|
|
// Throw error if a backup is currently running until we support parallel backups
|
2020-09-24 05:50:34 +08:00
|
|
|
if (BackupAgentBase::isRunnable(backupStatus)) {
|
2017-09-08 00:04:10 +08:00
|
|
|
throw backup_duplicate();
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (waitForCompletion) {
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("Submitted and now waiting for the backup on tag `%s' to complete. (DRY RUN)\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
// Check if a backup agent is running
|
|
|
|
bool agentRunning = wait(backupAgent.checkActive(db));
|
|
|
|
|
|
|
|
if (!agentRunning) {
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("The backup on tag `%s' was successfully submitted but no backup agents are responding. "
|
|
|
|
"(DRY RUN)\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Throw an error that will not display any additional information
|
|
|
|
throw actor_cancelled();
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
|
|
|
printf("The backup on tag `%s' was successfully submitted. (DRY RUN)\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(backupAgent.submitBackup(db,
|
|
|
|
KeyRef(url),
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-04-14 10:22:13 +08:00
|
|
|
initialSnapshotIntervalSeconds,
|
2021-03-11 02:06:03 +08:00
|
|
|
snapshotIntervalSeconds,
|
|
|
|
tagName,
|
|
|
|
backupRanges,
|
|
|
|
stopWhenDone,
|
|
|
|
usePartitionedLog,
|
|
|
|
incrementalBackupOnly));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Wait for the backup to complete, if requested
|
|
|
|
if (waitForCompletion) {
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("Submitted and now waiting for the backup on tag `%s' to complete.\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2019-02-13 08:07:17 +08:00
|
|
|
wait(success(backupAgent.waitBackup(db, tagName)));
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2017-05-26 04:48:44 +08:00
|
|
|
// Check if a backup agent is running
|
|
|
|
bool agentRunning = wait(backupAgent.checkActive(db));
|
|
|
|
|
|
|
|
if (!agentRunning) {
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("The backup on tag `%s' was successfully submitted but no backup agents are responding.\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Throw an error that will not display any additional information
|
|
|
|
throw actor_cancelled();
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
|
|
|
printf("The backup on tag `%s' was successfully submitted.\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-01 05:54:32 +08:00
|
|
|
} catch (Error& e) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (e.code()) {
|
|
|
|
case error_code_backup_error:
|
|
|
|
fprintf(stderr, "ERROR: An error was encountered during submission\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case error_code_backup_duplicate:
|
|
|
|
fprintf(stderr, "ERROR: A backup is already running on tag `%s'\n", printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> switchDBBackup(Database src,
|
|
|
|
Database dest,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
|
|
|
std::string tagName,
|
2021-07-05 07:27:26 +08:00
|
|
|
ForceAction forceAction) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state DatabaseBackupAgent backupAgent(src);
|
|
|
|
|
|
|
|
// Backup everything, if no ranges were specified
|
|
|
|
if (backupRanges.size() == 0) {
|
|
|
|
backupRanges.push_back_deep(backupRanges.arena(), normalKeys);
|
|
|
|
}
|
|
|
|
|
2019-03-05 07:58:36 +08:00
|
|
|
wait(backupAgent.atomicSwitchover(dest, KeyRef(tagName), backupRanges, StringRef(), StringRef(), forceAction));
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("The DR on tag `%s' was successfully switched.\n", printable(StringRef(tagName)).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Error& e) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (e.code()) {
|
|
|
|
case error_code_backup_error:
|
|
|
|
fprintf(stderr, "ERROR: An error was encountered during submission\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case error_code_backup_duplicate:
|
|
|
|
fprintf(stderr, "ERROR: A DR is already running on tag `%s'\n", printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> statusDBBackup(Database src, Database dest, std::string tagName, int errorLimit) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state DatabaseBackupAgent backupAgent(src);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
std::string statusText = wait(backupAgent.getStatus(dest, errorLimit, StringRef(tagName)));
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("%s\n", statusText.c_str());
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-05 09:30:55 +08:00
|
|
|
ACTOR Future<Void> statusBackup(Database db, std::string tagName, ShowErrors showErrors, bool json) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
std::string statusText =
|
|
|
|
wait(json ? backupAgent.getStatusJSON(db, tagName) : backupAgent.getStatus(db, showErrors, tagName));
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("%s\n", statusText.c_str());
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-05 09:30:55 +08:00
|
|
|
ACTOR Future<Void> abortDBBackup(Database src,
|
|
|
|
Database dest,
|
|
|
|
std::string tagName,
|
|
|
|
PartialBackup partial,
|
|
|
|
DstOnly dstOnly) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state DatabaseBackupAgent backupAgent(src);
|
|
|
|
|
2021-07-17 15:11:40 +08:00
|
|
|
wait(backupAgent.abortBackup(dest, Key(tagName), partial, AbortOldBackup::False, dstOnly));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent.unlockBackup(dest, Key(tagName)));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
printf("The DR on tag `%s' was successfully aborted.\n", printable(StringRef(tagName)).c_str());
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (e.code()) {
|
|
|
|
case error_code_backup_error:
|
|
|
|
fprintf(stderr, "ERROR: An error was encountered during submission\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case error_code_backup_unneeded:
|
|
|
|
fprintf(stderr, "ERROR: A DR was not running on tag `%s'\n", printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> abortBackup(Database db, std::string tagName) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent.abortBackup(db, tagName));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
printf("The backup on tag `%s' was successfully aborted.\n", printable(StringRef(tagName)).c_str());
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (e.code()) {
|
|
|
|
case error_code_backup_error:
|
|
|
|
fprintf(stderr, "ERROR: An error was encountered during submission\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case error_code_backup_unneeded:
|
|
|
|
fprintf(stderr, "ERROR: A backup was not running on tag `%s'\n", printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-05 09:30:55 +08:00
|
|
|
ACTOR Future<Void> cleanupMutations(Database db, DeleteData deleteData) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2019-09-28 09:32:27 +08:00
|
|
|
wait(cleanupBackup(db, deleteData));
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2019-09-28 09:32:27 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-05 07:27:26 +08:00
|
|
|
ACTOR Future<Void> waitBackup(Database db, std::string tagName, StopWhenDone stopWhenDone) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
|
2020-09-24 05:50:34 +08:00
|
|
|
EBackupState status = wait(backupAgent.waitBackup(db, tagName, stopWhenDone));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("The backup on tag `%s' %s.\n",
|
|
|
|
printable(StringRef(tagName)).c_str(),
|
2020-09-24 05:50:34 +08:00
|
|
|
BackupAgentBase::getStateText(status));
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-05 07:27:26 +08:00
|
|
|
ACTOR Future<Void> discontinueBackup(Database db, std::string tagName, WaitForComplete waitForCompletion) {
|
2021-03-11 02:06:03 +08:00
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent.discontinueBackup(db, StringRef(tagName)));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Wait for the backup to complete, if requested
|
|
|
|
if (waitForCompletion) {
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("Discontinued and now waiting for the backup on tag `%s' to complete.\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2019-02-13 08:07:17 +08:00
|
|
|
wait(success(backupAgent.waitBackup(db, tagName)));
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2017-05-26 04:48:44 +08:00
|
|
|
printf("The backup on tag `%s' was successfully discontinued.\n", printable(StringRef(tagName)).c_str());
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (e.code()) {
|
|
|
|
case error_code_backup_error:
|
|
|
|
fprintf(stderr, "ERROR: An encounter was error during submission\n");
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case error_code_backup_unneeded:
|
|
|
|
fprintf(stderr, "ERROR: A backup in not running on tag `%s'\n", printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case error_code_backup_duplicate:
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: The backup on tag `%s' is already discontinued\n",
|
|
|
|
printable(StringRef(tagName)).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
ACTOR Future<Void> changeBackupResumed(Database db, bool pause) {
|
2017-10-31 03:35:00 +08:00
|
|
|
try {
|
2020-04-03 06:28:51 +08:00
|
|
|
FileBackupAgent backupAgent;
|
|
|
|
wait(backupAgent.changePause(db, pause));
|
2017-12-15 05:54:01 +08:00
|
|
|
printf("All backup agents have been %s.\n", pause ? "paused" : "resumed");
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-10-31 03:35:00 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
ACTOR Future<Void> changeDBBackupResumed(Database src, Database dest, bool pause) {
|
2017-10-31 03:35:00 +08:00
|
|
|
try {
|
|
|
|
state DatabaseBackupAgent backupAgent(src);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent.taskBucket->changePause(dest, pause));
|
2017-12-15 05:54:01 +08:00
|
|
|
printf("All DR agents have been %s.\n", pause ? "paused" : "resumed");
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-10-31 03:35:00 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-06-26 06:11:03 +08:00
|
|
|
Reference<IBackupContainer> openBackupContainer(const char* name,
|
2022-03-29 08:10:49 +08:00
|
|
|
const std::string& destinationContainer,
|
|
|
|
const Optional<std::string>& proxy,
|
|
|
|
const Optional<std::string>& encryptionKeyFile) {
|
2019-03-06 04:28:05 +08:00
|
|
|
// Error, if no dest container was specified
|
|
|
|
if (destinationContainer.empty()) {
|
|
|
|
fprintf(stderr, "ERROR: No backup destination was specified.\n");
|
|
|
|
printHelpTeaser(name);
|
|
|
|
throw backup_error();
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-03-06 04:28:05 +08:00
|
|
|
Reference<IBackupContainer> c;
|
|
|
|
try {
|
2022-03-29 08:10:49 +08:00
|
|
|
c = IBackupContainer::openContainer(destinationContainer, proxy, encryptionKeyFile);
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2019-03-06 04:28:05 +08:00
|
|
|
std::string msg = format("ERROR: '%s' on URL '%s'", e.what(), destinationContainer.c_str());
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_backup_invalid_url && !IBackupContainer::lastOpenError.empty()) {
|
2019-03-06 04:28:05 +08:00
|
|
|
msg += format(": %s", IBackupContainer::lastOpenError.c_str());
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s\n", msg.c_str());
|
|
|
|
printHelpTeaser(name);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2021-03-30 01:09:07 +08:00
|
|
|
// Submit the restore request to the database if "performRestore" is true. Otherwise,
|
|
|
|
// check if the restore can be performed.
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> runRestore(Database db,
|
|
|
|
std::string originalClusterFile,
|
|
|
|
std::string tagName,
|
|
|
|
std::string container,
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> ranges,
|
|
|
|
Version beginVersion,
|
|
|
|
Version targetVersion,
|
|
|
|
std::string targetTimestamp,
|
|
|
|
bool performRestore,
|
2021-07-05 07:27:26 +08:00
|
|
|
Verbose verbose,
|
|
|
|
WaitForComplete waitForDone,
|
2021-03-11 02:06:03 +08:00
|
|
|
std::string addPrefix,
|
|
|
|
std::string removePrefix,
|
2021-07-05 09:30:55 +08:00
|
|
|
OnlyApplyMutationLogs onlyApplyMutationLogs,
|
2021-07-08 07:50:51 +08:00
|
|
|
InconsistentSnapshotOnly inconsistentSnapshotOnly,
|
2021-06-26 06:11:03 +08:00
|
|
|
Optional<std::string> encryptionKeyFile) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (ranges.empty()) {
|
2019-03-06 17:57:03 +08:00
|
|
|
ranges.push_back_deep(ranges.arena(), normalKeys);
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (targetVersion != invalidVersion && !targetTimestamp.empty()) {
|
2019-03-06 04:28:05 +08:00
|
|
|
fprintf(stderr, "Restore target version and target timestamp cannot both be specified\n");
|
|
|
|
throw restore_error();
|
|
|
|
}
|
|
|
|
|
2019-03-06 18:45:55 +08:00
|
|
|
state Optional<Database> origDb;
|
|
|
|
|
2019-03-06 04:28:05 +08:00
|
|
|
// Resolve targetTimestamp if given
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!targetTimestamp.empty()) {
|
|
|
|
if (originalClusterFile.empty()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"An original cluster file must be given in order to resolve restore target timestamp '%s'\n",
|
|
|
|
targetTimestamp.c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
throw restore_error();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!fileExists(originalClusterFile)) {
|
|
|
|
fprintf(
|
|
|
|
stderr, "Original source database cluster file '%s' does not exist.\n", originalClusterFile.c_str());
|
2019-03-06 18:45:55 +08:00
|
|
|
throw restore_error();
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-03-06 18:45:55 +08:00
|
|
|
origDb = Database::createDatabase(originalClusterFile, Database::API_VERSION_LATEST);
|
|
|
|
Version v = wait(timeKeeperVersionFromDatetime(targetTimestamp, origDb.get()));
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("Timestamp '{0}' resolves to version {1}\n", targetTimestamp, v);
|
2019-03-06 04:28:05 +08:00
|
|
|
targetVersion = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2017-05-26 04:48:44 +08:00
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
|
2021-06-26 06:11:03 +08:00
|
|
|
state Reference<IBackupContainer> bc =
|
2022-03-29 08:10:49 +08:00
|
|
|
openBackupContainer(exeRestore.toString().c_str(), container, proxy, encryptionKeyFile);
|
2018-01-20 04:19:32 +08:00
|
|
|
|
2019-01-09 11:00:58 +08:00
|
|
|
// If targetVersion is unset then use the maximum restorable version from the backup description
|
2021-03-11 02:06:03 +08:00
|
|
|
if (targetVersion == invalidVersion) {
|
|
|
|
if (verbose)
|
|
|
|
printf(
|
|
|
|
"No restore target version given, will use maximum restorable version from backup description.\n");
|
2018-01-20 04:19:32 +08:00
|
|
|
|
2019-01-09 11:00:58 +08:00
|
|
|
BackupDescription desc = wait(bc->describeBackup());
|
2018-01-20 04:19:32 +08:00
|
|
|
|
2021-07-05 09:30:55 +08:00
|
|
|
if (onlyApplyMutationLogs && desc.contiguousLogEnd.present()) {
|
2020-08-29 00:46:34 +08:00
|
|
|
targetVersion = desc.contiguousLogEnd.get() - 1;
|
2020-08-05 03:48:43 +08:00
|
|
|
} else if (desc.maxRestorableVersion.present()) {
|
|
|
|
targetVersion = desc.maxRestorableVersion.get();
|
|
|
|
} else {
|
2019-01-09 11:00:58 +08:00
|
|
|
fprintf(stderr, "The specified backup is not restorable to any version.\n");
|
|
|
|
throw restore_error();
|
2018-01-20 04:19:32 +08:00
|
|
|
}
|
2019-01-10 08:14:46 +08:00
|
|
|
|
2021-12-01 12:14:35 +08:00
|
|
|
if (verbose) {
|
|
|
|
fmt::print("Ussing target restore version {}\n", targetVersion);
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2019-01-09 11:00:58 +08:00
|
|
|
if (performRestore) {
|
2021-03-11 02:06:03 +08:00
|
|
|
Version restoredVersion = wait(backupAgent.restore(db,
|
|
|
|
origDb,
|
|
|
|
KeyRef(tagName),
|
|
|
|
KeyRef(container),
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
ranges,
|
|
|
|
waitForDone,
|
|
|
|
targetVersion,
|
|
|
|
verbose,
|
|
|
|
KeyRef(addPrefix),
|
|
|
|
KeyRef(removePrefix),
|
2021-07-17 15:11:40 +08:00
|
|
|
LockDB::True,
|
2021-07-05 09:30:55 +08:00
|
|
|
onlyApplyMutationLogs,
|
2021-04-23 04:53:37 +08:00
|
|
|
inconsistentSnapshotOnly,
|
2021-06-26 06:11:03 +08:00
|
|
|
beginVersion,
|
|
|
|
encryptionKeyFile));
|
2021-03-11 02:06:03 +08:00
|
|
|
|
|
|
|
if (waitForDone && verbose) {
|
2019-01-09 11:00:58 +08:00
|
|
|
// If restore is now complete then report version restored
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("Restored to version {}\n", restoredVersion);
|
2018-01-17 20:09:43 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2021-03-25 06:54:06 +08:00
|
|
|
state Optional<RestorableFileSet> rset = wait(bc->getRestoreSet(targetVersion, ranges));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!rset.present()) {
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print(stderr,
|
|
|
|
"Insufficient data to restore to version {}. Describe backup for more information.\n",
|
|
|
|
targetVersion);
|
2018-01-17 20:09:43 +08:00
|
|
|
throw restore_invalid_version();
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("Backup can be used to restore to version {}\n", targetVersion);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2019-01-25 08:26:57 +08:00
|
|
|
// Fast restore agent that kicks off the restore: send restore requests to restore workers.
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> runFastRestoreTool(Database db,
|
|
|
|
std::string tagName,
|
|
|
|
std::string container,
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> ranges,
|
|
|
|
Version dbVersion,
|
|
|
|
bool performRestore,
|
2021-07-05 07:27:26 +08:00
|
|
|
Verbose verbose,
|
|
|
|
WaitForComplete waitForDone) {
|
2019-08-02 08:00:13 +08:00
|
|
|
try {
|
2019-01-25 08:26:57 +08:00
|
|
|
state FileBackupAgent backupAgent;
|
2019-10-03 06:25:14 +08:00
|
|
|
state Version restoreVersion = invalidVersion;
|
2019-01-25 08:26:57 +08:00
|
|
|
|
2019-08-02 08:00:13 +08:00
|
|
|
if (ranges.size() > 1) {
|
2020-05-01 07:20:20 +08:00
|
|
|
fprintf(stdout, "[WARNING] Currently only a single restore range is tested!\n");
|
2019-01-25 08:26:57 +08:00
|
|
|
}
|
|
|
|
|
2020-05-01 07:20:20 +08:00
|
|
|
if (ranges.size() == 0) {
|
2020-05-01 09:30:15 +08:00
|
|
|
ranges.push_back(ranges.arena(), normalKeys);
|
2020-05-01 07:20:20 +08:00
|
|
|
}
|
2019-01-25 08:26:57 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("[INFO] runFastRestoreTool: restore_ranges:%d first range:%s\n",
|
|
|
|
ranges.size(),
|
2020-05-01 07:20:20 +08:00
|
|
|
ranges.front().toString().c_str());
|
2020-07-28 12:40:20 +08:00
|
|
|
TraceEvent ev("FastRestoreTool");
|
|
|
|
ev.detail("RestoreRanges", ranges.size());
|
|
|
|
for (int i = 0; i < ranges.size(); ++i) {
|
|
|
|
ev.detail(format("Range%d", i), ranges[i]);
|
|
|
|
}
|
2019-01-25 08:26:57 +08:00
|
|
|
|
|
|
|
if (performRestore) {
|
2019-08-02 08:00:13 +08:00
|
|
|
if (dbVersion == invalidVersion) {
|
2020-07-02 23:16:39 +08:00
|
|
|
TraceEvent("FastRestoreTool").detail("TargetRestoreVersion", "Largest restorable version");
|
2022-03-29 08:10:49 +08:00
|
|
|
BackupDescription desc = wait(IBackupContainer::openContainer(container, proxy, {})->describeBackup());
|
2019-08-02 08:00:13 +08:00
|
|
|
if (!desc.maxRestorableVersion.present()) {
|
2019-01-25 08:26:57 +08:00
|
|
|
fprintf(stderr, "The specified backup is not restorable to any version.\n");
|
|
|
|
throw restore_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
dbVersion = desc.maxRestorableVersion.get();
|
2020-07-02 23:16:39 +08:00
|
|
|
TraceEvent("FastRestoreTool").detail("TargetRestoreVersion", dbVersion);
|
2019-01-25 08:26:57 +08:00
|
|
|
}
|
2020-04-28 13:07:45 +08:00
|
|
|
state UID randomUID = deterministicRandom()->randomUniqueID();
|
2020-07-02 23:16:39 +08:00
|
|
|
TraceEvent("FastRestoreTool")
|
2020-04-28 13:07:45 +08:00
|
|
|
.detail("SubmitRestoreRequests", ranges.size())
|
|
|
|
.detail("RestoreUID", randomUID);
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(backupAgent.submitParallelRestore(db,
|
|
|
|
KeyRef(tagName),
|
|
|
|
ranges,
|
|
|
|
KeyRef(container),
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
dbVersion,
|
2021-07-17 15:11:40 +08:00
|
|
|
LockDB::True,
|
2021-03-11 02:06:03 +08:00
|
|
|
randomUID,
|
|
|
|
LiteralStringRef(""),
|
|
|
|
LiteralStringRef("")));
|
2020-06-25 12:25:30 +08:00
|
|
|
// TODO: Support addPrefix and removePrefix
|
2020-04-28 13:07:45 +08:00
|
|
|
if (waitForDone) {
|
|
|
|
// Wait for parallel restore to finish and unlock DB after that
|
2020-07-02 23:16:39 +08:00
|
|
|
TraceEvent("FastRestoreTool").detail("BackupAndParallelRestore", "WaitForRestoreToFinish");
|
2020-04-28 13:07:45 +08:00
|
|
|
wait(backupAgent.parallelRestoreFinish(db, randomUID));
|
2020-07-02 23:16:39 +08:00
|
|
|
TraceEvent("FastRestoreTool").detail("BackupAndParallelRestore", "RestoreFinished");
|
2020-04-28 13:07:45 +08:00
|
|
|
} else {
|
2020-07-02 23:16:39 +08:00
|
|
|
TraceEvent("FastRestoreTool")
|
2020-04-28 13:07:45 +08:00
|
|
|
.detail("RestoreUID", randomUID)
|
|
|
|
.detail("OperationGuide", "Manually unlock DB when restore finishes");
|
|
|
|
printf("WARNING: DB will be in locked state after restore. Need UID:%s to unlock DB\n",
|
2020-04-29 10:12:27 +08:00
|
|
|
randomUID.toString().c_str());
|
2020-04-28 13:07:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
restoreVersion = dbVersion;
|
2019-08-02 08:00:13 +08:00
|
|
|
} else {
|
2022-03-29 08:10:49 +08:00
|
|
|
state Reference<IBackupContainer> bc = IBackupContainer::openContainer(container, proxy, {});
|
2019-01-25 08:26:57 +08:00
|
|
|
state BackupDescription description = wait(bc->describeBackup());
|
|
|
|
|
2019-08-02 08:00:13 +08:00
|
|
|
if (dbVersion <= 0) {
|
2019-01-25 08:26:57 +08:00
|
|
|
wait(description.resolveVersionTimes(db));
|
2019-08-02 08:00:13 +08:00
|
|
|
if (description.maxRestorableVersion.present())
|
2019-01-25 08:26:57 +08:00
|
|
|
restoreVersion = description.maxRestorableVersion.get();
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "Backup is not restorable\n");
|
|
|
|
throw restore_invalid_version();
|
|
|
|
}
|
2019-09-04 06:50:21 +08:00
|
|
|
} else {
|
2019-01-25 08:26:57 +08:00
|
|
|
restoreVersion = dbVersion;
|
2019-09-04 06:50:21 +08:00
|
|
|
}
|
2019-01-25 08:26:57 +08:00
|
|
|
|
|
|
|
state Optional<RestorableFileSet> rset = wait(bc->getRestoreSet(restoreVersion));
|
2019-08-02 08:00:13 +08:00
|
|
|
if (!rset.present()) {
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print(stderr, "Insufficient data to restore to version {}\n", restoreVersion);
|
2019-01-25 08:26:57 +08:00
|
|
|
throw restore_invalid_version();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the restore information, if requested
|
|
|
|
if (verbose) {
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("[DRY RUN] Restoring backup to version: {}\n", restoreVersion);
|
|
|
|
fmt::print("{}\n", description.toString());
|
2019-01-25 08:26:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-02 08:00:13 +08:00
|
|
|
if (waitForDone && verbose) {
|
2019-01-25 08:26:57 +08:00
|
|
|
// If restore completed then report version restored
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("Restored to version {0}{1}\n", restoreVersion, (performRestore) ? "" : " (DRY RUN)");
|
2019-01-25 08:26:57 +08:00
|
|
|
}
|
2019-08-02 08:00:13 +08:00
|
|
|
} catch (Error& e) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_actor_cancelled)
|
|
|
|
throw;
|
2019-01-25 08:26:57 +08:00
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> dumpBackupData(const char* name,
|
|
|
|
std::string destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
Version beginVersion,
|
|
|
|
Version endVersion) {
|
2022-03-29 08:10:49 +08:00
|
|
|
state Reference<IBackupContainer> c = openBackupContainer(name, destinationContainer, proxy, {});
|
2019-01-03 18:35:31 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (beginVersion < 0 || endVersion < 0) {
|
2019-01-03 18:35:31 +08:00
|
|
|
BackupDescription desc = wait(c->describeBackup());
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!desc.maxLogEnd.present()) {
|
2019-01-03 18:35:31 +08:00
|
|
|
fprintf(stderr, "ERROR: Backup must have log data in order to use relative begin/end versions.\n");
|
|
|
|
throw backup_invalid_info();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (beginVersion < 0) {
|
2019-01-03 18:35:31 +08:00
|
|
|
beginVersion += desc.maxLogEnd.get();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (endVersion < 0) {
|
2019-01-03 18:35:31 +08:00
|
|
|
endVersion += desc.maxLogEnd.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("Scanning version range {0} to {1}\n", beginVersion, endVersion);
|
2019-01-03 18:35:31 +08:00
|
|
|
BackupFileList files = wait(c->dumpFileList(beginVersion, endVersion));
|
|
|
|
files.toStream(stdout);
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> expireBackupData(const char* name,
|
|
|
|
std::string destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
Version endVersion,
|
|
|
|
std::string endDatetime,
|
|
|
|
Database db,
|
|
|
|
bool force,
|
|
|
|
Version restorableAfterVersion,
|
2021-06-26 06:11:03 +08:00
|
|
|
std::string restorableAfterDatetime,
|
|
|
|
Optional<std::string> encryptionKeyFile) {
|
2018-01-17 20:09:43 +08:00
|
|
|
if (!endDatetime.empty()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
Version v = wait(timeKeeperVersionFromDatetime(endDatetime, db));
|
2017-12-15 05:54:01 +08:00
|
|
|
endVersion = v;
|
|
|
|
}
|
|
|
|
|
2018-01-17 20:09:43 +08:00
|
|
|
if (!restorableAfterDatetime.empty()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
Version v = wait(timeKeeperVersionFromDatetime(restorableAfterDatetime, db));
|
2018-01-17 20:09:43 +08:00
|
|
|
restorableAfterVersion = v;
|
|
|
|
}
|
|
|
|
|
2018-01-23 16:19:51 +08:00
|
|
|
if (endVersion == invalidVersion) {
|
2017-12-15 05:54:01 +08:00
|
|
|
fprintf(stderr, "ERROR: No version or date/time is specified.\n");
|
|
|
|
printHelpTeaser(name);
|
2021-03-11 02:06:03 +08:00
|
|
|
throw backup_error();
|
|
|
|
;
|
2017-12-15 05:54:01 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
try {
|
2022-03-29 08:10:49 +08:00
|
|
|
Reference<IBackupContainer> c = openBackupContainer(name, destinationContainer, proxy, encryptionKeyFile);
|
2018-12-20 16:23:26 +08:00
|
|
|
|
|
|
|
state IBackupContainer::ExpireProgress progress;
|
|
|
|
state std::string lastProgress;
|
|
|
|
state Future<Void> expire = c->expireData(endVersion, force, &progress, restorableAfterVersion);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
choose {
|
2019-01-10 08:14:46 +08:00
|
|
|
when(wait(delay(5))) {
|
2018-12-20 16:23:26 +08:00
|
|
|
std::string p = progress.toString();
|
2021-03-11 02:06:03 +08:00
|
|
|
if (p != lastProgress) {
|
2018-12-20 16:23:26 +08:00
|
|
|
int spaces = lastProgress.size() - p.size();
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("\r%s%s", p.c_str(), (spaces > 0 ? std::string(spaces, ' ').c_str() : ""));
|
2018-12-20 16:23:26 +08:00
|
|
|
lastProgress = p;
|
|
|
|
}
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
when(wait(expire)) { break; }
|
2018-12-20 16:23:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string p = progress.toString();
|
|
|
|
int spaces = lastProgress.size() - p.size();
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("\r%s%s\n", p.c_str(), (spaces > 0 ? std::string(spaces, ' ').c_str() : ""));
|
2018-12-20 16:23:26 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (endVersion < 0)
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("All data before {0} versions ({1}"
|
|
|
|
" days) prior to latest backup log has been deleted.\n",
|
|
|
|
-endVersion,
|
|
|
|
-endVersion / ((int64_t)24 * 3600 * CLIENT_KNOBS->CORE_VERSIONSPERSECOND));
|
2018-12-19 10:55:44 +08:00
|
|
|
else
|
2021-12-01 12:14:35 +08:00
|
|
|
fmt::print("All data before version {} has been deleted.\n", endVersion);
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-12-15 05:54:01 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_backup_cannot_expire)
|
|
|
|
fprintf(stderr,
|
2021-03-06 08:13:38 +08:00
|
|
|
"ERROR: Requested expiration would be unsafe. Backup would not meet minimum restorability. Use "
|
|
|
|
"--force to delete data anyway.\n");
|
2018-01-17 20:09:43 +08:00
|
|
|
else
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-12-15 05:54:01 +08:00
|
|
|
throw;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
return Void();
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-03-29 08:10:49 +08:00
|
|
|
ACTOR Future<Void> deleteBackupContainer(const char* name,
|
|
|
|
std::string destinationContainer,
|
|
|
|
Optional<std::string> proxy) {
|
2017-05-26 04:48:44 +08:00
|
|
|
try {
|
2022-03-29 08:10:49 +08:00
|
|
|
state Reference<IBackupContainer> c = openBackupContainer(name, destinationContainer, proxy, {});
|
2018-01-06 15:06:39 +08:00
|
|
|
state int numDeleted = 0;
|
|
|
|
state Future<Void> done = c->deleteContainer(&numDeleted);
|
2017-12-15 05:54:01 +08:00
|
|
|
|
2018-12-20 16:23:26 +08:00
|
|
|
state int lastUpdate = -1;
|
2018-12-21 10:05:23 +08:00
|
|
|
printf("Deleting %s...\n", destinationContainer.c_str());
|
2018-12-20 16:23:26 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
choose {
|
2021-03-11 02:06:03 +08:00
|
|
|
when(wait(done)) { break; }
|
|
|
|
when(wait(delay(5))) {
|
|
|
|
if (numDeleted != lastUpdate) {
|
2018-12-20 16:23:26 +08:00
|
|
|
printf("\r%d...", numDeleted);
|
|
|
|
lastUpdate = numDeleted;
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-20 17:24:31 +08:00
|
|
|
printf("\r%d objects deleted\n", numDeleted);
|
2018-12-21 10:05:23 +08:00
|
|
|
printf("The entire container has been deleted.\n");
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-12-15 05:54:01 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
return Void();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> describeBackup(const char* name,
|
|
|
|
std::string destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
bool deep,
|
|
|
|
Optional<Database> cx,
|
2021-06-26 06:11:03 +08:00
|
|
|
bool json,
|
|
|
|
Optional<std::string> encryptionKeyFile) {
|
2017-05-26 04:48:44 +08:00
|
|
|
try {
|
2022-03-29 08:10:49 +08:00
|
|
|
Reference<IBackupContainer> c = openBackupContainer(name, destinationContainer, proxy, encryptionKeyFile);
|
2018-01-17 20:09:43 +08:00
|
|
|
state BackupDescription desc = wait(c->describeBackup(deep));
|
2021-03-11 02:06:03 +08:00
|
|
|
if (cx.present())
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(desc.resolveVersionTimes(cx.get()));
|
2019-03-07 06:14:06 +08:00
|
|
|
printf("%s\n", (json ? desc.toJSON() : desc.toString()).c_str());
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2017-12-15 05:54:01 +08:00
|
|
|
throw;
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
|
|
|
throw;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 05:54:01 +08:00
|
|
|
return Void();
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-09-06 09:55:09 +08:00
|
|
|
static void reportBackupQueryError(UID operationId, JsonBuilderObject& result, std::string errorMessage) {
|
|
|
|
result["error"] = errorMessage;
|
|
|
|
printf("%s\n", result.getJson().c_str());
|
|
|
|
TraceEvent("BackupQueryFailure").detail("OperationId", operationId).detail("Reason", errorMessage);
|
|
|
|
}
|
|
|
|
|
2020-08-30 10:53:04 +08:00
|
|
|
// If restoreVersion is invalidVersion or latestVersion, use the maximum or minimum restorable version respectively for
|
|
|
|
// selected key ranges. If restoreTimestamp is specified, any specified restoreVersion will be overriden to the version
|
|
|
|
// resolved to that timestamp.
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> queryBackup(const char* name,
|
|
|
|
std::string destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> keyRangesFilter,
|
|
|
|
Version restoreVersion,
|
|
|
|
std::string originalClusterFile,
|
|
|
|
std::string restoreTimestamp,
|
2021-07-05 07:27:26 +08:00
|
|
|
Verbose verbose) {
|
2020-09-06 09:55:09 +08:00
|
|
|
state UID operationId = deterministicRandom()->randomUniqueID();
|
|
|
|
state JsonBuilderObject result;
|
|
|
|
state std::string errorMessage;
|
|
|
|
result["key_ranges_filter"] = printable(keyRangesFilter);
|
|
|
|
result["destination_container"] = destinationContainer;
|
|
|
|
|
|
|
|
TraceEvent("BackupQueryStart")
|
|
|
|
.detail("OperationId", operationId)
|
|
|
|
.detail("DestinationContainer", destinationContainer)
|
|
|
|
.detail("KeyRangesFilter", printable(keyRangesFilter))
|
|
|
|
.detail("SpecifiedRestoreVersion", restoreVersion)
|
|
|
|
.detail("RestoreTimestamp", restoreTimestamp)
|
|
|
|
.detail("BackupClusterFile", originalClusterFile);
|
|
|
|
|
2020-08-30 10:53:04 +08:00
|
|
|
// Resolve restoreTimestamp if given
|
|
|
|
if (!restoreTimestamp.empty()) {
|
|
|
|
if (originalClusterFile.empty()) {
|
2020-09-06 09:55:09 +08:00
|
|
|
reportBackupQueryError(
|
2021-03-11 02:06:03 +08:00
|
|
|
operationId,
|
|
|
|
result,
|
2020-09-06 09:55:09 +08:00
|
|
|
format("an original cluster file must be given in order to resolve restore target timestamp '%s'",
|
|
|
|
restoreTimestamp.c_str()));
|
2020-08-30 10:53:04 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fileExists(originalClusterFile)) {
|
2021-03-11 02:06:03 +08:00
|
|
|
reportBackupQueryError(operationId,
|
|
|
|
result,
|
2020-09-06 09:55:09 +08:00
|
|
|
format("The specified original source database cluster file '%s' does not exist\n",
|
|
|
|
originalClusterFile.c_str()));
|
2020-08-30 10:53:04 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Database origDb = Database::createDatabase(originalClusterFile, Database::API_VERSION_LATEST);
|
|
|
|
Version v = wait(timeKeeperVersionFromDatetime(restoreTimestamp, origDb));
|
2020-09-06 09:55:09 +08:00
|
|
|
result["restore_timestamp"] = restoreTimestamp;
|
|
|
|
result["restore_timestamp_resolved_version"] = v;
|
2020-08-30 10:53:04 +08:00
|
|
|
restoreVersion = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-03-29 08:10:49 +08:00
|
|
|
state Reference<IBackupContainer> bc = openBackupContainer(name, destinationContainer, proxy, {});
|
2020-08-30 10:53:04 +08:00
|
|
|
if (restoreVersion == invalidVersion) {
|
|
|
|
BackupDescription desc = wait(bc->describeBackup());
|
2020-09-18 08:58:58 +08:00
|
|
|
if (desc.maxRestorableVersion.present()) {
|
|
|
|
restoreVersion = desc.maxRestorableVersion.get();
|
|
|
|
// Use continuous log end version for the maximum restorable version for the key ranges.
|
|
|
|
} else if (keyRangesFilter.size() && desc.contiguousLogEnd.present()) {
|
|
|
|
restoreVersion = desc.contiguousLogEnd.get();
|
|
|
|
} else {
|
|
|
|
reportBackupQueryError(
|
2021-03-11 02:06:03 +08:00
|
|
|
operationId,
|
|
|
|
result,
|
2020-09-18 08:58:58 +08:00
|
|
|
errorMessage = format("the backup for the specified key ranges is not restorable to any version"));
|
2020-08-30 10:53:04 +08:00
|
|
|
}
|
2020-09-18 08:58:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (restoreVersion < 0 && restoreVersion != latestVersion) {
|
2021-03-11 02:06:03 +08:00
|
|
|
reportBackupQueryError(operationId,
|
|
|
|
result,
|
2020-09-06 09:55:09 +08:00
|
|
|
errorMessage =
|
2022-02-26 05:28:29 +08:00
|
|
|
format("the specified restorable version %lld is not valid", restoreVersion));
|
2020-08-30 11:10:45 +08:00
|
|
|
return Void();
|
2020-08-30 10:53:04 +08:00
|
|
|
}
|
|
|
|
Optional<RestorableFileSet> fileSet = wait(bc->getRestoreSet(restoreVersion, keyRangesFilter));
|
|
|
|
if (fileSet.present()) {
|
2020-09-06 09:55:09 +08:00
|
|
|
int64_t totalRangeFilesSize = 0, totalLogFilesSize = 0;
|
|
|
|
result["restore_version"] = fileSet.get().targetVersion;
|
|
|
|
JsonBuilderArray rangeFilesJson;
|
|
|
|
JsonBuilderArray logFilesJson;
|
2020-08-30 10:53:04 +08:00
|
|
|
for (const auto& rangeFile : fileSet.get().ranges) {
|
2020-09-06 09:55:09 +08:00
|
|
|
JsonBuilderObject object;
|
|
|
|
object["file_name"] = rangeFile.fileName;
|
|
|
|
object["file_size"] = rangeFile.fileSize;
|
|
|
|
object["version"] = rangeFile.version;
|
|
|
|
object["key_range"] = fileSet.get().keyRanges.count(rangeFile.fileName) == 0
|
|
|
|
? "none"
|
|
|
|
: fileSet.get().keyRanges.at(rangeFile.fileName).toString();
|
|
|
|
rangeFilesJson.push_back(object);
|
|
|
|
totalRangeFilesSize += rangeFile.fileSize;
|
2020-08-30 10:53:04 +08:00
|
|
|
}
|
|
|
|
for (const auto& log : fileSet.get().logs) {
|
2020-09-06 09:55:09 +08:00
|
|
|
JsonBuilderObject object;
|
|
|
|
object["file_name"] = log.fileName;
|
|
|
|
object["file_size"] = log.fileSize;
|
|
|
|
object["begin_version"] = log.beginVersion;
|
|
|
|
object["end_version"] = log.endVersion;
|
|
|
|
logFilesJson.push_back(object);
|
|
|
|
totalLogFilesSize += log.fileSize;
|
2020-08-30 10:53:04 +08:00
|
|
|
}
|
2020-09-06 09:55:09 +08:00
|
|
|
|
|
|
|
result["total_range_files_size"] = totalRangeFilesSize;
|
|
|
|
result["total_log_files_size"] = totalLogFilesSize;
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
result["ranges"] = rangeFilesJson;
|
|
|
|
result["logs"] = logFilesJson;
|
|
|
|
}
|
|
|
|
|
|
|
|
TraceEvent("BackupQueryReceivedRestorableFilesSet")
|
|
|
|
.detail("DestinationContainer", destinationContainer)
|
|
|
|
.detail("KeyRangesFilter", printable(keyRangesFilter))
|
|
|
|
.detail("ActualRestoreVersion", fileSet.get().targetVersion)
|
|
|
|
.detail("NumRangeFiles", fileSet.get().ranges.size())
|
|
|
|
.detail("NumLogFiles", fileSet.get().logs.size())
|
|
|
|
.detail("RangeFilesBytes", totalRangeFilesSize)
|
|
|
|
.detail("LogFilesBytes", totalLogFilesSize);
|
2020-08-30 10:53:04 +08:00
|
|
|
} else {
|
2020-09-06 09:55:09 +08:00
|
|
|
reportBackupQueryError(operationId, result, "no restorable files set found for specified key ranges");
|
|
|
|
return Void();
|
2020-08-30 10:53:04 +08:00
|
|
|
}
|
2020-09-06 09:55:09 +08:00
|
|
|
|
2020-08-30 10:53:04 +08:00
|
|
|
} catch (Error& e) {
|
2020-09-06 09:55:09 +08:00
|
|
|
reportBackupQueryError(operationId, result, e.what());
|
|
|
|
return Void();
|
2020-08-30 10:53:04 +08:00
|
|
|
}
|
|
|
|
|
2020-09-06 09:55:09 +08:00
|
|
|
printf("%s\n", result.getJson().c_str());
|
2020-08-30 10:53:04 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2022-03-29 08:10:49 +08:00
|
|
|
ACTOR Future<Void> listBackup(std::string baseUrl, Optional<std::string> proxy) {
|
2017-05-26 04:48:44 +08:00
|
|
|
try {
|
2022-03-29 08:10:49 +08:00
|
|
|
std::vector<std::string> containers = wait(IBackupContainer::listContainers(baseUrl, proxy));
|
2017-12-15 05:54:01 +08:00
|
|
|
for (std::string container : containers) {
|
|
|
|
printf("%s\n", container.c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2019-03-05 20:00:11 +08:00
|
|
|
std::string msg = format("ERROR: %s", e.what());
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_backup_invalid_url && !IBackupContainer::lastOpenError.empty()) {
|
2019-03-05 20:00:11 +08:00
|
|
|
msg += format(": %s", IBackupContainer::lastOpenError.c_str());
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s\n", msg.c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
|
|
|
}
|
2017-12-15 05:54:01 +08:00
|
|
|
|
|
|
|
return Void();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-01-18 15:41:29 +08:00
|
|
|
ACTOR Future<Void> listBackupTags(Database cx) {
|
|
|
|
state Reference<ReadYourWritesTransaction> tr = makeReference<ReadYourWritesTransaction>(cx);
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
std::vector<KeyBackedTag> tags = wait(getAllBackupTags(tr));
|
|
|
|
for (const auto& tag : tags) {
|
|
|
|
printf("%s\n", tag.tagName.c_str());
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr->onError(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:00:11 +08:00
|
|
|
struct BackupModifyOptions {
|
|
|
|
Optional<std::string> verifyUID;
|
|
|
|
Optional<std::string> destURL;
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy;
|
2019-03-06 10:05:52 +08:00
|
|
|
Optional<int> snapshotIntervalSeconds;
|
|
|
|
Optional<int> activeSnapshotIntervalSeconds;
|
|
|
|
bool hasChanges() const {
|
|
|
|
return destURL.present() || snapshotIntervalSeconds.present() || activeSnapshotIntervalSeconds.present();
|
|
|
|
}
|
2019-03-05 20:00:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
ACTOR Future<Void> modifyBackup(Database db, std::string tagName, BackupModifyOptions options) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!options.hasChanges()) {
|
2019-03-06 10:05:52 +08:00
|
|
|
fprintf(stderr, "No changes were specified, nothing to do!\n");
|
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:00:11 +08:00
|
|
|
state KeyBackedTag tag = makeBackupTag(tagName);
|
|
|
|
|
2019-03-06 10:05:52 +08:00
|
|
|
state Reference<IBackupContainer> bc;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (options.destURL.present()) {
|
2022-03-29 08:10:49 +08:00
|
|
|
bc = openBackupContainer(exeBackup.toString().c_str(), options.destURL.get(), options.proxy, {});
|
2019-03-06 10:05:52 +08:00
|
|
|
try {
|
2019-03-12 19:49:12 +08:00
|
|
|
wait(timeoutError(bc->create(), 30));
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled)
|
2019-03-06 10:05:52 +08:00
|
|
|
throw;
|
2021-03-11 02:06:03 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: Could not create backup container at '%s': %s\n",
|
|
|
|
options.destURL.get().c_str(),
|
|
|
|
e.what());
|
2019-03-06 10:05:52 +08:00
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
}
|
2020-07-02 23:16:39 +08:00
|
|
|
|
2019-03-06 10:05:52 +08:00
|
|
|
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(db));
|
2019-03-05 20:00:11 +08:00
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
|
|
|
|
state Optional<UidAndAbortedFlagT> uidFlag = wait(tag.get(db));
|
2019-03-06 14:17:37 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!uidFlag.present()) {
|
2019-03-06 14:17:37 +08:00
|
|
|
fprintf(stderr, "No backup exists on tag '%s'\n", tagName.c_str());
|
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (uidFlag.get().second) {
|
2019-03-05 20:00:11 +08:00
|
|
|
fprintf(stderr, "Cannot modify aborted backup on tag '%s'\n", tagName.c_str());
|
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
state BackupConfig config(uidFlag.get().first);
|
2021-07-17 15:11:40 +08:00
|
|
|
EBackupState s = wait(config.stateEnum().getOrThrow(tr, Snapshot::False, backup_invalid_info()));
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!FileBackupAgent::isRunnable(s)) {
|
2019-03-05 20:00:11 +08:00
|
|
|
fprintf(stderr, "Backup on tag '%s' is not runnable.\n", tagName.c_str());
|
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (options.verifyUID.present() && options.verifyUID.get() != uidFlag.get().first.toString()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"UID verification failed, backup on tag '%s' is '%s' but '%s' was specified.\n",
|
|
|
|
tagName.c_str(),
|
|
|
|
uidFlag.get().first.toString().c_str(),
|
|
|
|
options.verifyUID.get().c_str());
|
2019-03-05 20:00:11 +08:00
|
|
|
throw backup_error();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (options.snapshotIntervalSeconds.present()) {
|
2019-03-06 10:05:52 +08:00
|
|
|
config.snapshotIntervalSeconds().set(tr, options.snapshotIntervalSeconds.get());
|
2019-03-05 20:00:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (options.activeSnapshotIntervalSeconds.present()) {
|
2021-07-17 15:11:40 +08:00
|
|
|
Version begin = wait(config.snapshotBeginVersion().getOrThrow(tr, Snapshot::False, backup_error()));
|
2021-03-11 02:06:03 +08:00
|
|
|
config.snapshotTargetEndVersion().set(tr,
|
|
|
|
begin + ((int64_t)options.activeSnapshotIntervalSeconds.get() *
|
|
|
|
CLIENT_KNOBS->CORE_VERSIONSPERSECOND));
|
2019-03-05 20:00:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (options.destURL.present()) {
|
2019-03-05 20:00:11 +08:00
|
|
|
config.backupContainer().set(tr, bc);
|
|
|
|
}
|
|
|
|
|
2019-03-12 19:49:12 +08:00
|
|
|
wait(tr->commit());
|
2019-03-05 20:00:11 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2019-03-12 19:49:12 +08:00
|
|
|
wait(tr->onError(e));
|
2019-03-05 20:00:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
static std::vector<std::vector<StringRef>> parseLine(std::string& line, bool& err, bool& partial) {
|
2017-05-26 04:48:44 +08:00
|
|
|
err = false;
|
|
|
|
partial = false;
|
|
|
|
|
|
|
|
bool quoted = false;
|
|
|
|
std::vector<StringRef> buf;
|
|
|
|
std::vector<std::vector<StringRef>> ret;
|
|
|
|
|
|
|
|
size_t i = line.find_first_not_of(' ');
|
|
|
|
size_t offset = i;
|
|
|
|
|
|
|
|
bool forcetoken = false;
|
|
|
|
|
|
|
|
while (i <= line.length()) {
|
|
|
|
switch (line[i]) {
|
|
|
|
case ';':
|
|
|
|
if (!quoted) {
|
|
|
|
if (i > offset)
|
|
|
|
buf.push_back(StringRef((uint8_t*)(line.data() + offset), i - offset));
|
|
|
|
ret.push_back(std::move(buf));
|
|
|
|
offset = i = line.find_first_not_of(' ', i + 1);
|
2021-03-11 02:06:03 +08:00
|
|
|
} else
|
2017-05-26 04:48:44 +08:00
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
quoted = !quoted;
|
|
|
|
line.erase(i, 1);
|
|
|
|
if (quoted)
|
|
|
|
forcetoken = true;
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
if (!quoted) {
|
2021-03-11 02:06:03 +08:00
|
|
|
buf.push_back(StringRef((uint8_t*)(line.data() + offset), i - offset));
|
2017-05-26 04:48:44 +08:00
|
|
|
offset = i = line.find_first_not_of(' ', i);
|
|
|
|
forcetoken = false;
|
2021-03-11 02:06:03 +08:00
|
|
|
} else
|
2017-05-26 04:48:44 +08:00
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
if (i + 2 > line.length()) {
|
|
|
|
err = true;
|
|
|
|
ret.push_back(std::move(buf));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
switch (line[i + 1]) {
|
|
|
|
char ent, save;
|
|
|
|
case '"':
|
|
|
|
case '\\':
|
|
|
|
case ' ':
|
|
|
|
case ';':
|
|
|
|
line.erase(i, 1);
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
if (i + 4 > line.length()) {
|
|
|
|
err = true;
|
|
|
|
ret.push_back(std::move(buf));
|
|
|
|
return ret;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
char* pEnd;
|
2017-05-26 04:48:44 +08:00
|
|
|
save = line[i + 4];
|
|
|
|
line[i + 4] = 0;
|
|
|
|
ent = char(strtoul(line.data() + i + 2, &pEnd, 16));
|
|
|
|
if (*pEnd) {
|
|
|
|
err = true;
|
|
|
|
ret.push_back(std::move(buf));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
line[i + 4] = save;
|
|
|
|
line.replace(i, 4, 1, ent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = true;
|
|
|
|
ret.push_back(std::move(buf));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i -= 1;
|
|
|
|
if (i > offset || forcetoken)
|
|
|
|
buf.push_back(StringRef((uint8_t*)(line.data() + offset), i - offset));
|
|
|
|
|
|
|
|
ret.push_back(std::move(buf));
|
|
|
|
|
|
|
|
if (quoted)
|
|
|
|
partial = true;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
static void addKeyRange(std::string optionValue, Standalone<VectorRef<KeyRangeRef>>& keyRanges) {
|
|
|
|
bool err = false, partial = false;
|
2021-12-02 10:13:17 +08:00
|
|
|
int tokenArray = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
auto parsed = parseLine(optionValue, err, partial);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto tokens : parsed) {
|
2017-05-26 04:48:44 +08:00
|
|
|
tokenArray++;
|
|
|
|
|
|
|
|
/*
|
2021-12-02 10:13:17 +08:00
|
|
|
int tokenIndex = 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
for (auto token : tokens)
|
|
|
|
{
|
2021-03-11 02:06:03 +08:00
|
|
|
tokenIndex++;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("%4d token #%2d: %s\n", tokenArray, tokenIndex, printable(token).c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Process the keys
|
|
|
|
// <begin> [end]
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (tokens.size()) {
|
2017-05-26 04:48:44 +08:00
|
|
|
// empty
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// single key range
|
|
|
|
case 1:
|
2021-03-11 02:06:03 +08:00
|
|
|
keyRanges.push_back_deep(keyRanges.arena(), KeyRangeRef(tokens.at(0), strinc(tokens.at(0))));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// full key range
|
|
|
|
case 2:
|
|
|
|
try {
|
|
|
|
keyRanges.push_back_deep(keyRanges.arena(), KeyRangeRef(tokens.at(0), tokens.at(1)));
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: Invalid key range `%s %s' reported error %s\n",
|
|
|
|
tokens.at(0).toString().c_str(),
|
|
|
|
tokens.at(1).toString().c_str(),
|
|
|
|
e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
throw invalid_option_value();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Too many keys
|
|
|
|
default:
|
2022-02-26 07:49:23 +08:00
|
|
|
fmt::print(stderr, "ERROR: Invalid key range identified with {} keys", tokens.size());
|
2017-05-26 04:48:44 +08:00
|
|
|
throw invalid_option_value();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Version parseVersion(const char* str) {
|
|
|
|
StringRef s((const uint8_t*)str, strlen(str));
|
2019-01-03 18:35:31 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (s.endsWith(LiteralStringRef("days")) || s.endsWith(LiteralStringRef("d"))) {
|
2019-01-03 18:35:31 +08:00
|
|
|
float days;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (sscanf(str, "%f", &days) != 1) {
|
2019-01-03 18:35:31 +08:00
|
|
|
fprintf(stderr, "Could not parse version: %s\n", str);
|
|
|
|
flushAndExit(FDB_EXIT_ERROR);
|
|
|
|
}
|
|
|
|
return (double)CLIENT_KNOBS->CORE_VERSIONSPERSECOND * 24 * 3600 * -days;
|
|
|
|
}
|
|
|
|
|
|
|
|
Version ver;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (sscanf(str, "%" SCNd64, &ver) != 1) {
|
2019-01-03 18:35:31 +08:00
|
|
|
fprintf(stderr, "Could not parse version: %s\n", str);
|
|
|
|
flushAndExit(FDB_EXIT_ERROR);
|
|
|
|
}
|
|
|
|
return ver;
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
#ifdef ALLOC_INSTRUMENTATION
|
2021-03-11 02:06:03 +08:00
|
|
|
extern uint8_t* g_extra_memory;
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
|
|
|
|
2021-08-21 03:55:13 +08:00
|
|
|
// Creates a connection to a cluster. Optionally prints an error if the connection fails.
|
|
|
|
Optional<Database> connectToCluster(std::string const& clusterFile,
|
|
|
|
LocalityData const& localities,
|
|
|
|
bool quiet = false) {
|
|
|
|
auto resolvedClusterFile = ClusterConnectionFile::lookupClusterFileName(clusterFile);
|
|
|
|
Reference<ClusterConnectionFile> ccf;
|
|
|
|
|
|
|
|
Optional<Database> db;
|
|
|
|
|
|
|
|
try {
|
|
|
|
ccf = makeReference<ClusterConnectionFile>(resolvedClusterFile.first);
|
|
|
|
} catch (Error& e) {
|
|
|
|
if (!quiet)
|
|
|
|
fprintf(stderr, "%s\n", ClusterConnectionFile::getErrorString(resolvedClusterFile, e).c_str());
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db = Database::createDatabase(ccf, -1, IsInternal::True, localities);
|
|
|
|
} catch (Error& e) {
|
|
|
|
if (!quiet) {
|
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2021-10-11 11:44:56 +08:00
|
|
|
fprintf(stderr, "ERROR: Unable to connect to cluster from `%s'\n", ccf->getLocation().c_str());
|
2021-08-21 03:55:13 +08:00
|
|
|
}
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
|
|
|
|
return db;
|
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
platformInit();
|
|
|
|
|
2020-05-21 00:38:33 +08:00
|
|
|
int status = FDB_EXIT_SUCCESS;
|
|
|
|
|
|
|
|
std::string commandLine;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int a = 0; a < argc; a++) {
|
|
|
|
if (a)
|
|
|
|
commandLine += ' ';
|
2020-05-21 00:38:33 +08:00
|
|
|
commandLine += argv[a];
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
#ifdef ALLOC_INSTRUMENTATION
|
|
|
|
g_extra_memory = new uint8_t[1000000];
|
|
|
|
#endif
|
|
|
|
registerCrashHandler();
|
|
|
|
|
|
|
|
// Set default of line buffering standard out and error
|
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
setvbuf(stderr, NULL, _IONBF, 0);
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
ProgramExe programExe = getProgramType(argv[0]);
|
2021-01-31 05:30:43 +08:00
|
|
|
BackupType backupType = BackupType::UNDEFINED;
|
2020-11-15 14:02:46 +08:00
|
|
|
RestoreType restoreType = RestoreType::UNKNOWN;
|
|
|
|
DBType dbType = DBType::UNDEFINED;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-11-27 15:24:22 +08:00
|
|
|
std::unique_ptr<CSimpleOpt> args;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (programExe) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::AGENT:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(argc, argv, g_rgAgentOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DR_AGENT:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(argc, argv, g_rgDBAgentOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::BACKUP:
|
2017-05-26 04:48:44 +08:00
|
|
|
// Display backup help, if no arguments
|
|
|
|
if (argc < 2) {
|
|
|
|
printBackupUsage(false);
|
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2017-05-26 04:48:44 +08:00
|
|
|
// Get the backup type
|
|
|
|
backupType = getBackupType(argv[1]);
|
|
|
|
|
|
|
|
// Create the appropriate simple opt
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (backupType) {
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::START:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupStartOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::STATUS:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupStatusOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::ABORT:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupAbortOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::CLEANUP:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupCleanupOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2019-09-28 09:32:27 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::WAIT:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupWaitOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DISCONTINUE:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupDiscontinueOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::PAUSE:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupPauseOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::RESUME:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupPauseOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-12-15 05:54:01 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::EXPIRE:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupExpireOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-12-15 05:54:01 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DELETE_BACKUP:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupDeleteOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-12-15 05:54:01 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DESCRIBE:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupDescribeOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-12-15 05:54:01 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DUMP:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupDumpOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2019-01-03 18:35:31 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::LIST:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupListOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::QUERY:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupQueryOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2020-08-30 10:53:04 +08:00
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::MODIFY:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupModifyOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2019-03-05 20:00:11 +08:00
|
|
|
break;
|
2022-01-18 15:41:29 +08:00
|
|
|
case BackupType::TAGS:
|
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgBackupTagsOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
|
|
|
break;
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
2021-12-15 00:44:39 +08:00
|
|
|
args =
|
|
|
|
std::make_unique<CSimpleOpt>(argc, argv, g_rgOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DB_BACKUP:
|
2017-05-26 04:48:44 +08:00
|
|
|
// Display backup help, if no arguments
|
|
|
|
if (argc < 2) {
|
|
|
|
printDBBackupUsage(false);
|
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2017-05-26 04:48:44 +08:00
|
|
|
// Get the backup type
|
|
|
|
dbType = getDBType(argv[1]);
|
|
|
|
|
|
|
|
// Create the appropriate simple opt
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (dbType) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::START:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgDBStartOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::STATUS:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgDBStatusOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::SWITCH:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgDBSwitchOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::ABORT:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgDBAbortOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::PAUSE:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgDBPauseOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::RESUME:
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, &argv[1], g_rgDBPauseOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
2021-12-15 00:44:39 +08:00
|
|
|
args =
|
|
|
|
std::make_unique<CSimpleOpt>(argc, argv, g_rgOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::RESTORE:
|
2017-05-26 04:48:44 +08:00
|
|
|
if (argc < 2) {
|
|
|
|
printRestoreUsage(false);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
// Get the restore operation type
|
|
|
|
restoreType = getRestoreType(argv[1]);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (restoreType == RestoreType::UNKNOWN) {
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(argc, argv, g_rgOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2020-09-11 05:51:52 +08:00
|
|
|
} else {
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, argv + 1, g_rgRestoreOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::FASTRESTORE_TOOL:
|
2019-01-25 08:26:57 +08:00
|
|
|
if (argc < 2) {
|
|
|
|
printFastRestoreUsage(false);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
// Get the restore operation type
|
|
|
|
restoreType = getRestoreType(argv[1]);
|
2020-11-15 14:02:46 +08:00
|
|
|
if (restoreType == RestoreType::UNKNOWN) {
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(argc, argv, g_rgOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2020-09-11 05:51:52 +08:00
|
|
|
} else {
|
2021-12-15 00:44:39 +08:00
|
|
|
args = std::make_unique<CSimpleOpt>(
|
|
|
|
argc - 1, argv + 1, g_rgRestoreOptions, SO_O_EXACT | SO_O_HYPHEN_TO_UNDERSCORE);
|
2019-01-25 08:26:57 +08:00
|
|
|
}
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "FoundationDB " FDB_VT_PACKAGE_NAME " (v" FDB_VT_VERSION ")\n");
|
|
|
|
fprintf(stderr, "ERROR: Unable to determine program type based on executable `%s'\n", argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-03-29 08:10:49 +08:00
|
|
|
Optional<std::string> proxy;
|
2022-05-03 08:34:22 +08:00
|
|
|
std::string p;
|
|
|
|
if (platform::getEnvironmentVar("HTTP_PROXY", p) || platform::getEnvironmentVar("HTTPS_PROXY", p)) {
|
|
|
|
proxy = p;
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string destinationContainer;
|
2018-01-17 20:09:43 +08:00
|
|
|
bool describeDeep = false;
|
2018-01-23 07:50:28 +08:00
|
|
|
bool describeTimestamps = false;
|
2021-04-15 01:41:41 +08:00
|
|
|
int initialSnapshotIntervalSeconds =
|
|
|
|
0; // The initial snapshot has a desired duration of 0, meaning go as fast as possible.
|
2017-12-20 16:49:08 +08:00
|
|
|
int snapshotIntervalSeconds = CLIENT_KNOBS->BACKUP_DEFAULT_SNAPSHOT_INTERVAL_SEC;
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string clusterFile;
|
|
|
|
std::string sourceClusterFile;
|
2017-12-15 05:54:01 +08:00
|
|
|
std::string baseUrl;
|
2018-01-17 20:09:43 +08:00
|
|
|
std::string expireDatetime;
|
2018-01-23 16:19:51 +08:00
|
|
|
Version expireVersion = invalidVersion;
|
2018-01-17 20:09:43 +08:00
|
|
|
std::string expireRestorableAfterDatetime;
|
|
|
|
Version expireRestorableAfterVersion = std::numeric_limits<Version>::max();
|
2017-05-26 04:48:44 +08:00
|
|
|
std::vector<std::pair<std::string, std::string>> knobs;
|
|
|
|
std::string tagName = BackupAgentBase::getDefaultTag().toString();
|
|
|
|
bool tagProvided = false;
|
|
|
|
std::string restoreContainer;
|
|
|
|
std::string addPrefix;
|
|
|
|
std::string removePrefix;
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupKeys;
|
2020-09-06 09:55:09 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupKeysFilter;
|
2017-05-26 04:48:44 +08:00
|
|
|
int maxErrors = 20;
|
2020-08-29 02:29:22 +08:00
|
|
|
Version beginVersion = invalidVersion;
|
2019-03-06 04:28:05 +08:00
|
|
|
Version restoreVersion = invalidVersion;
|
|
|
|
std::string restoreTimestamp;
|
2021-07-05 07:27:26 +08:00
|
|
|
WaitForComplete waitForDone{ false };
|
|
|
|
StopWhenDone stopWhenDone{ true };
|
2021-07-05 09:30:55 +08:00
|
|
|
UsePartitionedLog usePartitionedLog{ false }; // Set to true to use new backup system
|
|
|
|
IncrementalBackupOnly incrementalBackupOnly{ false };
|
|
|
|
OnlyApplyMutationLogs onlyApplyMutationLogs{ false };
|
|
|
|
InconsistentSnapshotOnly inconsistentSnapshotOnly{ false };
|
2021-07-05 07:27:26 +08:00
|
|
|
ForceAction forceAction{ false };
|
2017-05-26 04:48:44 +08:00
|
|
|
bool trace = false;
|
|
|
|
bool quietDisplay = false;
|
|
|
|
bool dryRun = false;
|
|
|
|
std::string traceDir = "";
|
2019-03-23 01:39:13 +08:00
|
|
|
std::string traceFormat = "";
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string traceLogGroup;
|
2018-02-08 14:36:01 +08:00
|
|
|
uint64_t traceRollSize = TRACE_DEFAULT_ROLL_SIZE;
|
|
|
|
uint64_t traceMaxLogsSize = TRACE_DEFAULT_MAX_LOGS_SIZE;
|
2021-03-11 02:06:03 +08:00
|
|
|
ESOError lastError;
|
2021-07-05 09:30:55 +08:00
|
|
|
PartialBackup partial{ true };
|
|
|
|
DstOnly dstOnly{ false };
|
2017-09-27 01:19:26 +08:00
|
|
|
LocalityData localities;
|
2017-09-30 01:35:40 +08:00
|
|
|
uint64_t memLimit = 8LL << 30;
|
2022-04-07 11:06:24 +08:00
|
|
|
uint64_t virtualMemLimit = 0; // unlimited
|
2017-09-30 01:35:40 +08:00
|
|
|
Optional<uint64_t> ti;
|
2021-04-06 03:21:32 +08:00
|
|
|
BackupTLSConfig tlsConfig;
|
2019-01-03 18:35:31 +08:00
|
|
|
Version dumpBegin = 0;
|
|
|
|
Version dumpEnd = std::numeric_limits<Version>::max();
|
2019-03-06 04:28:05 +08:00
|
|
|
std::string restoreClusterFileDest;
|
|
|
|
std::string restoreClusterFileOrig;
|
2019-03-07 06:14:06 +08:00
|
|
|
bool jsonOutput = false;
|
2021-07-05 09:30:55 +08:00
|
|
|
DeleteData deleteData{ false };
|
2021-06-26 06:11:03 +08:00
|
|
|
Optional<std::string> encryptionKeyFile;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-03-05 20:00:11 +08:00
|
|
|
BackupModifyOptions modifyOptions;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (argc == 1) {
|
2017-05-26 04:48:44 +08:00
|
|
|
printUsage(programExe, false);
|
2019-01-10 08:14:46 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
#ifdef _WIN32
|
2017-05-26 04:48:44 +08:00
|
|
|
// Windows needs a gentle nudge to format floats correctly
|
|
|
|
//_set_output_format(_TWO_DIGIT_EXPONENT);
|
2021-03-11 02:06:03 +08:00
|
|
|
#endif
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
while (args->Next()) {
|
|
|
|
lastError = args->LastError();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (lastError) {
|
2017-05-26 04:48:44 +08:00
|
|
|
case SO_SUCCESS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_ARG_INVALID_DATA:
|
|
|
|
fprintf(stderr, "ERROR: invalid argument to option `%s'\n", args->OptionText());
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_ARG_INVALID:
|
|
|
|
fprintf(stderr, "ERROR: argument given for option `%s'\n", args->OptionText());
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_ARG_MISSING:
|
|
|
|
fprintf(stderr, "ERROR: missing argument for option `%s'\n", args->OptionText());
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
|
|
|
|
case SO_OPT_INVALID:
|
|
|
|
fprintf(stderr, "ERROR: unknown option `%s'\n", args->OptionText());
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: argument given for option `%s'\n", args->OptionText());
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-17 20:09:43 +08:00
|
|
|
int optId = args->OptionId();
|
|
|
|
switch (optId) {
|
2021-03-11 02:06:03 +08:00
|
|
|
case OPT_HELP:
|
|
|
|
printUsage(programExe, false);
|
|
|
|
return FDB_EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
case OPT_DEVHELP:
|
|
|
|
printUsage(programExe, true);
|
|
|
|
return FDB_EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
case OPT_VERSION:
|
|
|
|
printVersion();
|
|
|
|
return FDB_EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
case OPT_BUILD_FLAGS:
|
|
|
|
printBuildInformation();
|
|
|
|
return FDB_EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
case OPT_NOBUFSTDOUT:
|
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
setvbuf(stderr, NULL, _IONBF, 0);
|
|
|
|
break;
|
|
|
|
case OPT_BUFSTDOUTERR:
|
|
|
|
setvbuf(stdout, NULL, _IOFBF, BUFSIZ);
|
|
|
|
setvbuf(stderr, NULL, _IOFBF, BUFSIZ);
|
|
|
|
break;
|
|
|
|
case OPT_QUIET:
|
|
|
|
quietDisplay = true;
|
|
|
|
break;
|
|
|
|
case OPT_DRYRUN:
|
|
|
|
dryRun = true;
|
|
|
|
break;
|
|
|
|
case OPT_DELETE_DATA:
|
2021-07-05 09:30:55 +08:00
|
|
|
deleteData.set(true);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_MIN_CLEANUP_SECONDS:
|
2021-05-11 07:32:02 +08:00
|
|
|
knobs.emplace_back("min_cleanup_seconds", args->OptionArg());
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_FORCE:
|
2021-07-05 07:27:26 +08:00
|
|
|
forceAction.set(true);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_TRACE:
|
|
|
|
trace = true;
|
|
|
|
break;
|
|
|
|
case OPT_TRACE_DIR:
|
|
|
|
trace = true;
|
|
|
|
traceDir = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_TRACE_FORMAT:
|
|
|
|
if (!validateTraceFormat(args->OptionArg())) {
|
|
|
|
fprintf(stderr, "WARNING: Unrecognized trace format `%s'\n", args->OptionArg());
|
|
|
|
}
|
|
|
|
traceFormat = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_TRACE_LOG_GROUP:
|
|
|
|
traceLogGroup = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_LOCALITY: {
|
2021-12-15 04:01:44 +08:00
|
|
|
Optional<std::string> localityKey = extractPrefixedArgument("--locality", args->OptionSyntax());
|
|
|
|
if (!localityKey.present()) {
|
|
|
|
fprintf(stderr, "ERROR: unable to parse locality key '%s'\n", args->OptionSyntax());
|
2021-03-11 02:06:03 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
2021-12-15 04:01:44 +08:00
|
|
|
Standalone<StringRef> key = StringRef(localityKey.get());
|
|
|
|
std::transform(key.begin(), key.end(), mutateString(key), ::tolower);
|
|
|
|
localities.set(key, Standalone<StringRef>(std::string(args->OptionArg())));
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPT_EXPIRE_BEFORE_DATETIME:
|
|
|
|
expireDatetime = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_EXPIRE_RESTORABLE_AFTER_DATETIME:
|
|
|
|
expireRestorableAfterDatetime = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_EXPIRE_BEFORE_VERSION:
|
|
|
|
case OPT_EXPIRE_RESTORABLE_AFTER_VERSION:
|
|
|
|
case OPT_EXPIRE_MIN_RESTORABLE_DAYS:
|
|
|
|
case OPT_EXPIRE_DELETE_BEFORE_DAYS: {
|
|
|
|
const char* a = args->OptionArg();
|
|
|
|
long long ver = 0;
|
|
|
|
if (!sscanf(a, "%lld", &ver)) {
|
|
|
|
fprintf(stderr, "ERROR: Could not parse expiration version `%s'\n", a);
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
2018-12-19 10:55:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Interpret the value as days worth of versions relative to now (negative)
|
|
|
|
if (optId == OPT_EXPIRE_MIN_RESTORABLE_DAYS || optId == OPT_EXPIRE_DELETE_BEFORE_DAYS) {
|
|
|
|
ver = -ver * 24 * 60 * 60 * CLIENT_KNOBS->CORE_VERSIONSPERSECOND;
|
|
|
|
}
|
2018-12-19 10:55:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (optId == OPT_EXPIRE_BEFORE_VERSION || optId == OPT_EXPIRE_DELETE_BEFORE_DAYS)
|
|
|
|
expireVersion = ver;
|
|
|
|
else
|
|
|
|
expireRestorableAfterVersion = ver;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPT_RESTORE_TIMESTAMP:
|
|
|
|
restoreTimestamp = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_BASEURL:
|
|
|
|
baseUrl = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_RESTORE_CLUSTERFILE_DEST:
|
|
|
|
restoreClusterFileDest = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_RESTORE_CLUSTERFILE_ORIG:
|
|
|
|
restoreClusterFileOrig = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_CLUSTERFILE:
|
|
|
|
clusterFile = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_DEST_CLUSTER:
|
|
|
|
clusterFile = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_SOURCE_CLUSTER:
|
|
|
|
sourceClusterFile = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_CLEANUP:
|
2021-07-05 09:30:55 +08:00
|
|
|
partial.set(false);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_DSTONLY:
|
2021-07-05 09:30:55 +08:00
|
|
|
dstOnly.set(true);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_KNOB: {
|
2021-12-15 04:01:44 +08:00
|
|
|
Optional<std::string> knobName = extractPrefixedArgument("--knob", args->OptionSyntax());
|
|
|
|
if (!knobName.present()) {
|
|
|
|
fprintf(stderr, "ERROR: unable to parse knob option '%s'\n", args->OptionSyntax());
|
2021-03-11 02:06:03 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2017-12-15 05:54:01 +08:00
|
|
|
}
|
2021-12-15 04:01:44 +08:00
|
|
|
knobs.emplace_back(knobName.get(), args->OptionArg());
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPT_BACKUPKEYS:
|
|
|
|
try {
|
|
|
|
addKeyRange(args->OptionArg(), backupKeys);
|
|
|
|
} catch (Error&) {
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
2017-12-20 16:49:08 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_BACKUPKEYS_FILTER:
|
|
|
|
try {
|
|
|
|
addKeyRange(args->OptionArg(), backupKeysFilter);
|
|
|
|
} catch (Error&) {
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
2022-03-29 08:10:49 +08:00
|
|
|
case OPT_PROXY:
|
|
|
|
proxy = args->OptionArg();
|
2022-03-29 13:15:24 +08:00
|
|
|
if (!Hostname::isHostname(proxy.get()) && !NetworkAddress::parseOptional(proxy.get()).present()) {
|
|
|
|
fprintf(stderr, "ERROR: Proxy format should be either IP:port or host:port\n");
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
2022-03-29 08:10:49 +08:00
|
|
|
modifyOptions.proxy = proxy;
|
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case OPT_DESTCONTAINER:
|
|
|
|
destinationContainer = args->OptionArg();
|
|
|
|
// If the url starts with '/' then prepend "file://" for backwards compatibility
|
|
|
|
if (StringRef(destinationContainer).startsWith(LiteralStringRef("/")))
|
|
|
|
destinationContainer = std::string("file://") + destinationContainer;
|
|
|
|
modifyOptions.destURL = destinationContainer;
|
|
|
|
break;
|
|
|
|
case OPT_SNAPSHOTINTERVAL:
|
2021-04-16 06:24:24 +08:00
|
|
|
case OPT_INITIAL_SNAPSHOT_INTERVAL:
|
2021-03-11 02:06:03 +08:00
|
|
|
case OPT_MOD_ACTIVE_INTERVAL: {
|
|
|
|
const char* a = args->OptionArg();
|
|
|
|
int seconds;
|
|
|
|
if (!sscanf(a, "%d", &seconds)) {
|
|
|
|
fprintf(stderr, "ERROR: Could not parse snapshot interval `%s'\n", a);
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
2020-08-29 02:29:22 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
if (optId == OPT_SNAPSHOTINTERVAL) {
|
|
|
|
snapshotIntervalSeconds = seconds;
|
|
|
|
modifyOptions.snapshotIntervalSeconds = seconds;
|
2021-04-16 06:24:24 +08:00
|
|
|
} else if (optId == OPT_INITIAL_SNAPSHOT_INTERVAL) {
|
2021-04-14 10:22:13 +08:00
|
|
|
initialSnapshotIntervalSeconds = seconds;
|
2021-03-11 02:06:03 +08:00
|
|
|
} else if (optId == OPT_MOD_ACTIVE_INTERVAL) {
|
|
|
|
modifyOptions.activeSnapshotIntervalSeconds = seconds;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPT_MOD_VERIFY_UID:
|
|
|
|
modifyOptions.verifyUID = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_WAITFORDONE:
|
2021-07-05 07:27:26 +08:00
|
|
|
waitForDone.set(true);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_NOSTOPWHENDONE:
|
2021-07-05 07:27:26 +08:00
|
|
|
stopWhenDone.set(false);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_USE_PARTITIONED_LOG:
|
2021-07-05 09:30:55 +08:00
|
|
|
usePartitionedLog.set(true);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_INCREMENTALONLY:
|
2021-07-05 09:30:55 +08:00
|
|
|
incrementalBackupOnly.set(true);
|
|
|
|
onlyApplyMutationLogs.set(true);
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
2021-06-26 06:11:03 +08:00
|
|
|
case OPT_ENCRYPTION_KEY_FILE:
|
|
|
|
encryptionKeyFile = args->OptionArg();
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_RESTORECONTAINER:
|
|
|
|
restoreContainer = args->OptionArg();
|
|
|
|
// If the url starts with '/' then prepend "file://" for backwards compatibility
|
|
|
|
if (StringRef(restoreContainer).startsWith(LiteralStringRef("/")))
|
|
|
|
restoreContainer = std::string("file://") + restoreContainer;
|
|
|
|
break;
|
|
|
|
case OPT_DESCRIBE_DEEP:
|
|
|
|
describeDeep = true;
|
|
|
|
break;
|
|
|
|
case OPT_DESCRIBE_TIMESTAMPS:
|
|
|
|
describeTimestamps = true;
|
|
|
|
break;
|
|
|
|
case OPT_PREFIX_ADD:
|
|
|
|
addPrefix = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_PREFIX_REMOVE:
|
|
|
|
removePrefix = args->OptionArg();
|
|
|
|
break;
|
|
|
|
case OPT_ERRORLIMIT: {
|
|
|
|
const char* a = args->OptionArg();
|
|
|
|
if (!sscanf(a, "%d", &maxErrors)) {
|
|
|
|
fprintf(stderr, "ERROR: Could not parse max number of errors `%s'\n", a);
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPT_RESTORE_BEGIN_VERSION: {
|
|
|
|
const char* a = args->OptionArg();
|
|
|
|
long long ver = 0;
|
|
|
|
if (!sscanf(a, "%lld", &ver)) {
|
|
|
|
fprintf(stderr, "ERROR: Could not parse database beginVersion `%s'\n", a);
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
beginVersion = ver;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OPT_RESTORE_VERSION: {
|
|
|
|
const char* a = args->OptionArg();
|
|
|
|
long long ver = 0;
|
|
|
|
if (!sscanf(a, "%lld", &ver)) {
|
|
|
|
fprintf(stderr, "ERROR: Could not parse database version `%s'\n", a);
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
restoreVersion = ver;
|
|
|
|
break;
|
|
|
|
}
|
2021-04-23 04:53:37 +08:00
|
|
|
case OPT_RESTORE_INCONSISTENT_SNAPSHOT_ONLY: {
|
2021-07-05 09:30:55 +08:00
|
|
|
inconsistentSnapshotOnly.set(true);
|
2021-04-23 04:53:37 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
case OPT_PARENTPID: {
|
|
|
|
auto pid_str = args->OptionArg();
|
|
|
|
int parent_pid = atoi(pid_str);
|
|
|
|
auto pHandle = OpenProcess(SYNCHRONIZE, FALSE, parent_pid);
|
|
|
|
if (!pHandle) {
|
|
|
|
TraceEvent("ParentProcessOpenError").GetLastError();
|
|
|
|
fprintf(stderr, "Could not open parent process at pid %d (error %d)", parent_pid, GetLastError());
|
|
|
|
throw platform_error();
|
|
|
|
}
|
|
|
|
startThread(&parentWatcher, pHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case OPT_TAGNAME:
|
|
|
|
tagName = args->OptionArg();
|
|
|
|
tagProvided = true;
|
|
|
|
break;
|
|
|
|
case OPT_CRASHONERROR:
|
|
|
|
g_crashOnError = true;
|
|
|
|
break;
|
|
|
|
case OPT_MEMLIMIT:
|
|
|
|
ti = parse_with_suffix(args->OptionArg(), "MiB");
|
|
|
|
if (!ti.present()) {
|
|
|
|
fprintf(stderr, "ERROR: Could not parse memory limit from `%s'\n", args->OptionArg());
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
flushAndExit(FDB_EXIT_ERROR);
|
|
|
|
}
|
|
|
|
memLimit = ti.get();
|
|
|
|
break;
|
2022-04-07 11:06:24 +08:00
|
|
|
case OPT_VMEMLIMIT:
|
|
|
|
ti = parse_with_suffix(args->OptionArg(), "MiB");
|
|
|
|
if (!ti.present()) {
|
|
|
|
fprintf(stderr, "ERROR: Could not parse virtual memory limit from `%s'\n", args->OptionArg());
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
flushAndExit(FDB_EXIT_ERROR);
|
|
|
|
}
|
|
|
|
virtualMemLimit = ti.get();
|
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
case OPT_BLOB_CREDENTIALS:
|
2021-04-06 03:21:32 +08:00
|
|
|
tlsConfig.blobCredentials.push_back(args->OptionArg());
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case TLSConfig::OPT_TLS_PLUGIN:
|
|
|
|
args->OptionArg();
|
|
|
|
break;
|
|
|
|
case TLSConfig::OPT_TLS_CERTIFICATES:
|
2021-04-06 03:21:32 +08:00
|
|
|
tlsConfig.tlsCertPath = args->OptionArg();
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case TLSConfig::OPT_TLS_PASSWORD:
|
2021-04-06 03:21:32 +08:00
|
|
|
tlsConfig.tlsPassword = args->OptionArg();
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case TLSConfig::OPT_TLS_CA_FILE:
|
2021-04-06 03:21:32 +08:00
|
|
|
tlsConfig.tlsCAPath = args->OptionArg();
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case TLSConfig::OPT_TLS_KEY:
|
2021-04-06 03:21:32 +08:00
|
|
|
tlsConfig.tlsKeyPath = args->OptionArg();
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case TLSConfig::OPT_TLS_VERIFY_PEERS:
|
2021-04-06 03:21:32 +08:00
|
|
|
tlsConfig.tlsVerifyPeers = args->OptionArg();
|
2021-03-11 02:06:03 +08:00
|
|
|
break;
|
|
|
|
case OPT_DUMP_BEGIN:
|
|
|
|
dumpBegin = parseVersion(args->OptionArg());
|
|
|
|
break;
|
|
|
|
case OPT_DUMP_END:
|
|
|
|
dumpEnd = parseVersion(args->OptionArg());
|
|
|
|
break;
|
|
|
|
case OPT_JSON:
|
|
|
|
jsonOutput = true;
|
|
|
|
break;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the extra arguments
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int argLoop = 0; argLoop < args->FileCount(); argLoop++) {
|
|
|
|
switch (programExe) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::AGENT:
|
2017-05-26 04:48:44 +08:00
|
|
|
fprintf(stderr, "ERROR: Backup Agent does not support argument value `%s'\n", args->File(argLoop));
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Add the backup key range
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::BACKUP:
|
2017-05-26 04:48:44 +08:00
|
|
|
// Error, if the keys option was not specified
|
|
|
|
if (backupKeys.size() == 0) {
|
|
|
|
fprintf(stderr, "ERROR: Unknown backup option value `%s'\n", args->File(argLoop));
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
// Otherwise, assume the item is a key range
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
addKeyRange(args->File(argLoop), backupKeys);
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error&) {
|
2017-05-26 04:48:44 +08:00
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::RESTORE:
|
2017-05-26 04:48:44 +08:00
|
|
|
fprintf(stderr, "ERROR: FDB Restore does not support argument value `%s'\n", args->File(argLoop));
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::FASTRESTORE_TOOL:
|
2021-03-11 02:06:03 +08:00
|
|
|
fprintf(
|
|
|
|
stderr, "ERROR: FDB Fast Restore Tool does not support argument value `%s'\n", args->File(argLoop));
|
2019-01-25 08:26:57 +08:00
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DR_AGENT:
|
2017-05-26 04:48:44 +08:00
|
|
|
fprintf(stderr, "ERROR: DR Agent does not support argument value `%s'\n", args->File(argLoop));
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DB_BACKUP:
|
2017-05-26 04:48:44 +08:00
|
|
|
// Error, if the keys option was not specified
|
|
|
|
if (backupKeys.size() == 0) {
|
|
|
|
fprintf(stderr, "ERROR: Unknown DR option value `%s'\n", args->File(argLoop));
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
// Otherwise, assume the item is a key range
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
addKeyRange(args->File(argLoop), backupKeys);
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error&) {
|
2017-05-26 04:48:44 +08:00
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trace) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!traceLogGroup.empty())
|
2017-05-26 04:48:44 +08:00
|
|
|
setNetworkOption(FDBNetworkOptions::TRACE_LOG_GROUP, StringRef(traceLogGroup));
|
|
|
|
|
|
|
|
if (traceDir.empty())
|
|
|
|
setNetworkOption(FDBNetworkOptions::TRACE_ENABLE);
|
|
|
|
else
|
|
|
|
setNetworkOption(FDBNetworkOptions::TRACE_ENABLE, StringRef(traceDir));
|
2019-03-23 01:39:13 +08:00
|
|
|
if (!traceFormat.empty()) {
|
|
|
|
setNetworkOption(FDBNetworkOptions::TRACE_FORMAT, StringRef(traceFormat));
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
setNetworkOption(FDBNetworkOptions::ENABLE_SLOW_TASK_PROFILING);
|
|
|
|
}
|
|
|
|
setNetworkOption(FDBNetworkOptions::DISABLE_CLIENT_STATISTICS_LOGGING);
|
2019-01-31 09:36:51 +08:00
|
|
|
|
|
|
|
// deferred TLS options
|
2021-04-06 03:21:32 +08:00
|
|
|
if (!tlsConfig.setupTLS()) {
|
|
|
|
return 1;
|
2019-01-31 09:36:51 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
Error::init();
|
2021-03-11 02:06:03 +08:00
|
|
|
std::set_new_handler(&platform::outOfMemory);
|
2022-04-07 11:06:24 +08:00
|
|
|
setMemoryQuota(virtualMemLimit);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
Database db;
|
2018-09-22 06:58:14 +08:00
|
|
|
Database sourceDb;
|
2017-05-26 04:48:44 +08:00
|
|
|
FileBackupAgent ba;
|
|
|
|
Key tag;
|
|
|
|
Future<Optional<Void>> f;
|
|
|
|
Future<Optional<int>> fstatus;
|
2017-12-15 05:54:01 +08:00
|
|
|
Reference<IBackupContainer> c;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
try {
|
2021-07-17 15:11:40 +08:00
|
|
|
setupNetwork(0, UseMetrics::True);
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2017-05-26 04:48:44 +08:00
|
|
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-04-07 11:06:24 +08:00
|
|
|
Future<Void> memoryUsageMonitor = startMemoryUsageMonitor(memLimit);
|
|
|
|
|
2022-03-25 06:17:02 +08:00
|
|
|
IKnobCollection::setupKnobs(knobs);
|
2021-11-16 16:41:34 +08:00
|
|
|
// Reinitialize knobs in order to update knobs that are dependent on explicitly set knobs
|
2022-03-25 06:17:02 +08:00
|
|
|
IKnobCollection::getMutableGlobalKnobCollection().initialize(Randomize::False, IsSimulated::False);
|
2021-11-16 16:41:34 +08:00
|
|
|
|
2018-09-22 06:58:14 +08:00
|
|
|
TraceEvent("ProgramStart")
|
2021-03-11 02:06:03 +08:00
|
|
|
.setMaxEventLength(12000)
|
|
|
|
.detail("SourceVersion", getSourceVersion())
|
|
|
|
.detail("Version", FDB_VT_VERSION)
|
|
|
|
.detail("PackageName", FDB_VT_PACKAGE_NAME)
|
|
|
|
.detailf("ActualTime", "%lld", DEBUG_DETERMINISM ? 0 : time(NULL))
|
|
|
|
.setMaxFieldLength(10000)
|
|
|
|
.detail("CommandLine", commandLine)
|
|
|
|
.setMaxFieldLength(0)
|
|
|
|
.detail("MemoryLimit", memLimit)
|
|
|
|
.trackLatest("ProgramStart");
|
|
|
|
|
|
|
|
// Ordinarily, this is done when the network is run. However, network thread should be set before TraceEvents
|
|
|
|
// are logged. This thread will eventually run the network, so call it now.
|
2019-01-10 08:14:46 +08:00
|
|
|
TraceEvent::setNetworkThread();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-04-06 03:21:32 +08:00
|
|
|
// Sets up blob credentials, including one from the environment FDB_BLOB_CREDENTIALS.
|
|
|
|
tlsConfig.setupBlobCredentials();
|
2017-12-15 05:54:01 +08:00
|
|
|
|
2018-02-08 14:36:01 +08:00
|
|
|
// Opens a trace file if trace is set (and if a trace file isn't already open)
|
|
|
|
// For most modes, initCluster() will open a trace file, but some fdbbackup operations do not require
|
|
|
|
// a cluster so they should use this instead.
|
|
|
|
auto initTraceFile = [&]() {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (trace)
|
2018-02-08 14:36:01 +08:00
|
|
|
openTraceFile(NetworkAddress(), traceRollSize, traceMaxLogsSize, traceDir, "trace", traceLogGroup);
|
|
|
|
};
|
|
|
|
|
2018-01-17 20:09:43 +08:00
|
|
|
auto initCluster = [&](bool quiet = false) {
|
2021-08-21 03:55:13 +08:00
|
|
|
Optional<Database> result = connectToCluster(clusterFile, localities, quiet);
|
|
|
|
if (result.present()) {
|
|
|
|
db = result.get();
|
2017-12-21 17:58:15 +08:00
|
|
|
}
|
|
|
|
|
2021-08-21 03:55:13 +08:00
|
|
|
return result.present();
|
2017-12-21 17:58:15 +08:00
|
|
|
};
|
|
|
|
|
2021-08-21 03:55:13 +08:00
|
|
|
auto initSourceCluster = [&](bool required, bool quiet = false) {
|
|
|
|
if (!sourceClusterFile.size() && required) {
|
|
|
|
if (!quiet) {
|
|
|
|
fprintf(stderr, "ERROR: source cluster file is required\n");
|
|
|
|
}
|
|
|
|
return false;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-08-21 03:55:13 +08:00
|
|
|
Optional<Database> result = connectToCluster(sourceClusterFile, localities, quiet);
|
|
|
|
if (result.present()) {
|
|
|
|
sourceDb = result.get();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-08-21 03:55:13 +08:00
|
|
|
|
|
|
|
return result.present();
|
|
|
|
};
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (programExe) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::AGENT:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2017-05-26 04:48:44 +08:00
|
|
|
f = stopAfter(runAgent(db));
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::BACKUP:
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (backupType) {
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::START: {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2017-05-26 04:48:44 +08:00
|
|
|
// Test out the backup url to make sure it parses. Doesn't test to make sure it's actually writeable.
|
2022-03-29 08:10:49 +08:00
|
|
|
openBackupContainer(argv[0], destinationContainer, proxy, encryptionKeyFile);
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(submitBackup(db,
|
|
|
|
destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-04-14 10:22:13 +08:00
|
|
|
initialSnapshotIntervalSeconds,
|
2021-03-11 02:06:03 +08:00
|
|
|
snapshotIntervalSeconds,
|
|
|
|
backupKeys,
|
|
|
|
tagName,
|
|
|
|
dryRun,
|
|
|
|
waitForDone,
|
|
|
|
stopWhenDone,
|
|
|
|
usePartitionedLog,
|
2020-07-22 04:07:16 +08:00
|
|
|
incrementalBackupOnly));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::MODIFY: {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2019-03-05 20:00:11 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(modifyBackup(db, tagName, modifyOptions));
|
2019-03-05 20:00:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::STATUS:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-07-17 15:11:40 +08:00
|
|
|
f = stopAfter(statusBackup(db, tagName, ShowErrors::True, jsonOutput));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::ABORT:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(abortBackup(db, tagName));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::CLEANUP:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2019-09-28 09:32:27 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(cleanupMutations(db, deleteData));
|
2019-09-28 09:32:27 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::WAIT:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(waitBackup(db, tagName, stopWhenDone));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DISCONTINUE:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(discontinueBackup(db, tagName, waitForDone));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::PAUSE:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(changeBackupResumed(db, true));
|
2017-12-15 05:54:01 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::RESUME:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(changeBackupResumed(db, false));
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::EXPIRE:
|
2018-02-08 14:36:01 +08:00
|
|
|
initTraceFile();
|
2018-01-20 04:19:32 +08:00
|
|
|
// Must have a usable cluster if either expire DateTime options were used
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!expireDatetime.empty() || !expireRestorableAfterDatetime.empty()) {
|
|
|
|
if (!initCluster())
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2018-01-23 07:50:28 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(expireBackupData(argv[0],
|
|
|
|
destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
expireVersion,
|
|
|
|
expireDatetime,
|
|
|
|
db,
|
|
|
|
forceAction,
|
|
|
|
expireRestorableAfterVersion,
|
2021-06-26 06:11:03 +08:00
|
|
|
expireRestorableAfterDatetime,
|
|
|
|
encryptionKeyFile));
|
2017-12-15 05:54:01 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DELETE_BACKUP:
|
2018-02-08 14:36:01 +08:00
|
|
|
initTraceFile();
|
2022-03-29 08:10:49 +08:00
|
|
|
f = stopAfter(deleteBackupContainer(argv[0], destinationContainer, proxy));
|
2017-12-15 05:54:01 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DESCRIBE:
|
2018-02-08 14:36:01 +08:00
|
|
|
initTraceFile();
|
2018-01-23 07:50:28 +08:00
|
|
|
// If timestamp lookups are desired, require a cluster file
|
2021-03-11 02:06:03 +08:00
|
|
|
if (describeTimestamps && !initCluster())
|
2018-01-23 07:50:28 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2017-12-15 05:54:01 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Only pass database optionDatabase Describe will lookup version timestamps if a cluster file was
|
|
|
|
// given, but quietly skip them if not.
|
|
|
|
f = stopAfter(describeBackup(argv[0],
|
|
|
|
destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
describeDeep,
|
|
|
|
describeTimestamps ? Optional<Database>(db) : Optional<Database>(),
|
2021-06-26 06:11:03 +08:00
|
|
|
jsonOutput,
|
|
|
|
encryptionKeyFile));
|
2018-01-23 07:50:28 +08:00
|
|
|
break;
|
2019-01-03 18:35:31 +08:00
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::LIST:
|
2018-02-08 14:36:01 +08:00
|
|
|
initTraceFile();
|
2022-03-29 08:10:49 +08:00
|
|
|
f = stopAfter(listBackup(baseUrl, proxy));
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
|
|
|
|
2022-01-18 15:41:29 +08:00
|
|
|
case BackupType::TAGS:
|
|
|
|
if (!initCluster())
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
f = stopAfter(listBackupTags(db));
|
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::QUERY:
|
2020-08-30 10:53:04 +08:00
|
|
|
initTraceFile();
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(queryBackup(argv[0],
|
|
|
|
destinationContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
backupKeysFilter,
|
|
|
|
restoreVersion,
|
|
|
|
restoreClusterFileOrig,
|
|
|
|
restoreTimestamp,
|
2021-07-05 07:27:26 +08:00
|
|
|
Verbose{ !quietDisplay }));
|
2020-08-30 10:53:04 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::DUMP:
|
2019-01-03 18:35:31 +08:00
|
|
|
initTraceFile();
|
2022-03-29 08:10:49 +08:00
|
|
|
f = stopAfter(dumpBackupData(argv[0], destinationContainer, proxy, dumpBegin, dumpEnd));
|
2019-01-03 18:35:31 +08:00
|
|
|
break;
|
|
|
|
|
2021-01-31 05:30:43 +08:00
|
|
|
case BackupType::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: Unsupported backup action %s\n", argv[1]);
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::RESTORE:
|
2021-03-11 02:06:03 +08:00
|
|
|
if (dryRun) {
|
2020-11-15 14:02:46 +08:00
|
|
|
if (restoreType != RestoreType::START) {
|
2019-07-30 07:21:12 +08:00
|
|
|
fprintf(stderr, "Restore dry run only works for 'start' command\n");
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
2019-01-09 19:54:13 +08:00
|
|
|
|
2019-07-30 07:21:12 +08:00
|
|
|
// Must explicitly call trace file options handling if not calling Database::createDatabase()
|
|
|
|
initTraceFile();
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
|
|
|
if (restoreClusterFileDest.empty()) {
|
2019-07-30 07:21:12 +08:00
|
|
|
fprintf(stderr, "Restore destination cluster file must be specified explicitly.\n");
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
2019-06-14 08:42:11 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!fileExists(restoreClusterFileDest)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Restore destination cluster file '%s' does not exist.\n",
|
|
|
|
restoreClusterFileDest.c_str());
|
2019-07-30 07:21:12 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
2019-06-14 08:42:11 +08:00
|
|
|
|
2019-07-30 07:21:12 +08:00
|
|
|
try {
|
|
|
|
db = Database::createDatabase(restoreClusterFileDest, Database::API_VERSION_LATEST);
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Restore destination cluster file '%s' invalid: %s\n",
|
|
|
|
restoreClusterFileDest.c_str(),
|
|
|
|
e.what());
|
2019-07-30 07:21:12 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
2019-06-14 08:42:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (restoreType) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case RestoreType::START:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(runRestore(db,
|
|
|
|
restoreClusterFileOrig,
|
|
|
|
tagName,
|
|
|
|
restoreContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-03-11 02:06:03 +08:00
|
|
|
backupKeys,
|
|
|
|
beginVersion,
|
|
|
|
restoreVersion,
|
|
|
|
restoreTimestamp,
|
|
|
|
!dryRun,
|
2021-07-05 07:27:26 +08:00
|
|
|
Verbose{ !quietDisplay },
|
2021-03-11 02:06:03 +08:00
|
|
|
waitForDone,
|
|
|
|
addPrefix,
|
|
|
|
removePrefix,
|
2021-07-05 09:30:55 +08:00
|
|
|
onlyApplyMutationLogs,
|
2021-06-26 06:11:03 +08:00
|
|
|
inconsistentSnapshotOnly,
|
|
|
|
encryptionKeyFile));
|
2020-11-15 14:02:46 +08:00
|
|
|
break;
|
|
|
|
case RestoreType::WAIT:
|
2021-07-17 15:11:40 +08:00
|
|
|
f = stopAfter(success(ba.waitRestore(db, KeyRef(tagName), Verbose::True)));
|
2020-11-15 14:02:46 +08:00
|
|
|
break;
|
|
|
|
case RestoreType::ABORT:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(
|
|
|
|
map(ba.abortRestore(db, KeyRef(tagName)), [tagName](FileBackupAgent::ERestoreState s) -> Void {
|
|
|
|
printf("RESTORE_ABORT Tag: %s State: %s\n",
|
|
|
|
tagName.c_str(),
|
|
|
|
FileBackupAgent::restoreStateText(s).toString().c_str());
|
|
|
|
return Void();
|
|
|
|
}));
|
2020-11-15 14:02:46 +08:00
|
|
|
break;
|
|
|
|
case RestoreType::STATUS:
|
|
|
|
// If no tag is specifically provided then print all tag status, don't just use "default"
|
2021-03-11 02:06:03 +08:00
|
|
|
if (tagProvided)
|
|
|
|
tag = tagName;
|
2020-11-15 14:02:46 +08:00
|
|
|
f = stopAfter(map(ba.restoreStatus(db, KeyRef(tag)), [](std::string s) -> Void {
|
|
|
|
printf("%s\n", s.c_str());
|
|
|
|
return Void();
|
|
|
|
}));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw restore_error();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::FASTRESTORE_TOOL:
|
2021-12-15 01:59:14 +08:00
|
|
|
// Support --dest-cluster-file option as fdbrestore does
|
2020-07-28 13:16:35 +08:00
|
|
|
if (dryRun) {
|
2020-11-15 14:02:46 +08:00
|
|
|
if (restoreType != RestoreType::START) {
|
2020-07-28 13:16:35 +08:00
|
|
|
fprintf(stderr, "Restore dry run only works for 'start' command\n");
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must explicitly call trace file options handling if not calling Database::createDatabase()
|
|
|
|
initTraceFile();
|
|
|
|
} else {
|
|
|
|
if (restoreClusterFileDest.empty()) {
|
|
|
|
fprintf(stderr, "Restore destination cluster file must be specified explicitly.\n");
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fileExists(restoreClusterFileDest)) {
|
2021-03-11 02:06:03 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
"Restore destination cluster file '%s' does not exist.\n",
|
2020-07-28 13:16:35 +08:00
|
|
|
restoreClusterFileDest.c_str());
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db = Database::createDatabase(restoreClusterFileDest, Database::API_VERSION_LATEST);
|
|
|
|
} catch (Error& e) {
|
2021-03-11 02:06:03 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
"Restore destination cluster file '%s' invalid: %s\n",
|
|
|
|
restoreClusterFileDest.c_str(),
|
|
|
|
e.what());
|
2020-07-28 13:16:35 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2020-07-28 12:40:20 +08:00
|
|
|
// TODO: We have not implemented the code commented out in this case
|
2019-08-02 08:00:13 +08:00
|
|
|
switch (restoreType) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case RestoreType::START:
|
2021-07-05 07:27:26 +08:00
|
|
|
f = stopAfter(runFastRestoreTool(db,
|
|
|
|
tagName,
|
|
|
|
restoreContainer,
|
2022-03-29 08:10:49 +08:00
|
|
|
proxy,
|
2021-07-05 07:27:26 +08:00
|
|
|
backupKeys,
|
|
|
|
restoreVersion,
|
|
|
|
!dryRun,
|
|
|
|
Verbose{ !quietDisplay },
|
|
|
|
waitForDone));
|
2019-08-02 08:00:13 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case RestoreType::WAIT:
|
2019-08-02 08:00:13 +08:00
|
|
|
printf("[TODO][ERROR] FastRestore does not support RESTORE_WAIT yet!\n");
|
|
|
|
throw restore_error();
|
|
|
|
// f = stopAfter( success(ba.waitRestore(db, KeyRef(tagName), true)) );
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case RestoreType::ABORT:
|
2019-08-02 08:00:13 +08:00
|
|
|
printf("[TODO][ERROR] FastRestore does not support RESTORE_ABORT yet!\n");
|
|
|
|
throw restore_error();
|
|
|
|
// f = stopAfter( map(ba.abortRestore(db, KeyRef(tagName)),
|
2021-03-11 02:06:03 +08:00
|
|
|
//[tagName](FileBackupAgent::ERestoreState s) -> Void { printf("Tag: %s State:
|
|
|
|
//%s\n", tagName.c_str(),
|
2020-07-28 13:16:35 +08:00
|
|
|
// FileBackupAgent::restoreStateText(s).toString().c_str()); return Void();
|
2019-08-02 08:00:13 +08:00
|
|
|
// }) );
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case RestoreType::STATUS:
|
2019-08-02 08:00:13 +08:00
|
|
|
printf("[TODO][ERROR] FastRestore does not support RESTORE_STATUS yet!\n");
|
|
|
|
throw restore_error();
|
|
|
|
// If no tag is specifically provided then print all tag status, don't just use "default"
|
2021-03-11 02:06:03 +08:00
|
|
|
if (tagProvided)
|
|
|
|
tag = tagName;
|
2019-08-02 08:00:13 +08:00
|
|
|
// f = stopAfter( map(ba.restoreStatus(db, KeyRef(tag)), [](std::string s) -> Void {
|
|
|
|
// printf("%s\n", s.c_str());
|
|
|
|
// return Void();
|
|
|
|
// }) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw restore_error();
|
2019-01-25 08:26:57 +08:00
|
|
|
}
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DR_AGENT:
|
2021-08-21 03:55:13 +08:00
|
|
|
if (!initCluster() || !initSourceCluster(true)) {
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-08-21 03:55:13 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(runDBAgent(sourceDb, db));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::DB_BACKUP:
|
2021-08-21 03:55:13 +08:00
|
|
|
if (!initCluster() || !initSourceCluster(dbType != DBType::ABORT || !dstOnly)) {
|
2017-12-21 17:58:15 +08:00
|
|
|
return FDB_EXIT_ERROR;
|
2021-08-21 03:55:13 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (dbType) {
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::START:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(submitDBBackup(sourceDb, db, backupKeys, tagName));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::STATUS:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(statusDBBackup(sourceDb, db, tagName, maxErrors));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::SWITCH:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(switchDBBackup(sourceDb, db, backupKeys, tagName, forceAction));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::ABORT:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(abortDBBackup(sourceDb, db, tagName, partial, dstOnly));
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::PAUSE:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(changeDBBackupResumed(sourceDb, db, true));
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::RESUME:
|
2021-03-11 02:06:03 +08:00
|
|
|
f = stopAfter(changeDBBackupResumed(sourceDb, db, false));
|
2017-10-31 03:35:00 +08:00
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case DBType::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: Unsupported DR action %s\n", argv[1]);
|
|
|
|
printHelpTeaser(argv[0]);
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-11-15 14:02:46 +08:00
|
|
|
case ProgramExe::UNDEFINED:
|
2017-05-26 04:48:44 +08:00
|
|
|
default:
|
|
|
|
return FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
runNetwork();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (f.isValid() && f.isReady() && !f.isError() && !f.get().present()) {
|
2017-05-26 04:48:44 +08:00
|
|
|
status = FDB_EXIT_ERROR;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (fstatus.isValid() && fstatus.isReady() && !fstatus.isError() && fstatus.get().present()) {
|
2017-05-26 04:48:44 +08:00
|
|
|
status = fstatus.get().get();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
#ifdef ALLOC_INSTRUMENTATION
|
2017-05-26 04:48:44 +08:00
|
|
|
{
|
2021-09-17 08:42:34 +08:00
|
|
|
std::cout << "Page Counts: " << FastAllocator<16>::pageCount << " " << FastAllocator<32>::pageCount << " "
|
2021-09-14 07:57:27 +08:00
|
|
|
<< FastAllocator<64>::pageCount << " " << FastAllocator<128>::pageCount << " "
|
|
|
|
<< FastAllocator<256>::pageCount << " " << FastAllocator<512>::pageCount << " "
|
|
|
|
<< FastAllocator<1024>::pageCount << " " << FastAllocator<2048>::pageCount << " "
|
|
|
|
<< FastAllocator<4096>::pageCount << " " << FastAllocator<8192>::pageCount << " "
|
|
|
|
<< FastAllocator<16384>::pageCount << std::endl;
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<std::pair<std::string, const char*>> typeNames;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto i = allocInstr.begin(); i != allocInstr.end(); ++i) {
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string s;
|
|
|
|
|
|
|
|
#ifdef __linux__
|
2021-03-11 02:06:03 +08:00
|
|
|
char* demangled = abi::__cxa_demangle(i->first, NULL, NULL, NULL);
|
2017-05-26 04:48:44 +08:00
|
|
|
if (demangled) {
|
|
|
|
s = demangled;
|
|
|
|
if (StringRef(s).startsWith(LiteralStringRef("(anonymous namespace)::")))
|
|
|
|
s = s.substr(LiteralStringRef("(anonymous namespace)::").size());
|
|
|
|
free(demangled);
|
|
|
|
} else
|
|
|
|
s = i->first;
|
|
|
|
#else
|
|
|
|
s = i->first;
|
|
|
|
if (StringRef(s).startsWith(LiteralStringRef("class `anonymous namespace'::")))
|
|
|
|
s = s.substr(LiteralStringRef("class `anonymous namespace'::").size());
|
|
|
|
else if (StringRef(s).startsWith(LiteralStringRef("class ")))
|
|
|
|
s = s.substr(LiteralStringRef("class ").size());
|
|
|
|
else if (StringRef(s).startsWith(LiteralStringRef("struct ")))
|
|
|
|
s = s.substr(LiteralStringRef("struct ").size());
|
|
|
|
#endif
|
|
|
|
|
2021-05-11 07:32:02 +08:00
|
|
|
typeNames.emplace_back(s, i->first);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
std::sort(typeNames.begin(), typeNames.end());
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < typeNames.size(); i++) {
|
2017-05-26 04:48:44 +08:00
|
|
|
const char* n = typeNames[i].second;
|
|
|
|
auto& f = allocInstr[n];
|
2021-03-11 02:06:03 +08:00
|
|
|
printf("%+d\t%+d\t%d\t%d\t%s\n",
|
|
|
|
f.allocCount,
|
|
|
|
-f.deallocCount,
|
|
|
|
f.allocCount - f.deallocCount,
|
|
|
|
f.maxAllocated,
|
|
|
|
typeNames[i].first.c_str());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We're about to exit and clean up data structures, this will wreak havoc on allocation recording
|
|
|
|
memSample_entered = true;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
#endif
|
2017-05-26 04:48:44 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
TraceEvent(SevError, "MainError").error(e);
|
|
|
|
status = FDB_EXIT_MAIN_ERROR;
|
2020-02-21 08:53:01 +08:00
|
|
|
} catch (boost::system::system_error& e) {
|
|
|
|
if (g_network) {
|
|
|
|
TraceEvent(SevError, "MainError").error(unknown_error()).detail("RootException", e.what());
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "ERROR: %s (%d)\n", e.what(), e.code().value());
|
|
|
|
}
|
|
|
|
status = FDB_EXIT_MAIN_EXCEPTION;
|
2017-05-26 04:48:44 +08:00
|
|
|
} catch (std::exception& e) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "MainError").error(unknown_error()).detail("RootException", e.what());
|
2017-05-26 04:48:44 +08:00
|
|
|
status = FDB_EXIT_MAIN_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
2018-12-18 10:39:14 +08:00
|
|
|
flushAndExit(status);
|
2021-05-04 04:14:16 +08:00
|
|
|
}
|