#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/restricted_token.h"
+#include "fe_utils/recovery_gen.h"
#include "getopt_long.h"
#include "storage/bufpage.h"
static void sanityChecks(void);
static void findCommonAncestorTimeline(XLogRecPtr *recptr, int *tliIndex);
static void ensureCleanShutdown(const char *argv0);
+static void disconnect_atexit(void);
static ControlFileData ControlFile_target;
static ControlFileData ControlFile_source;
printf(_(" -D, --target-pgdata=DIRECTORY existing data directory to modify\n"));
printf(_(" --source-pgdata=DIRECTORY source data directory to synchronize with\n"));
printf(_(" --source-server=CONNSTR source server to synchronize with\n"));
+ printf(_(" -R, --write-recovery-conf write configuration for replication\n"
+ " (requires --source-server)\n"));
printf(_(" -n, --dry-run stop before modifying anything\n"));
printf(_(" -N, --no-sync do not wait for changes to be written\n"
" safely to disk\n"));
static struct option long_options[] = {
{"help", no_argument, NULL, '?'},
{"target-pgdata", required_argument, NULL, 'D'},
+ {"write-recovery-conf", no_argument, NULL, 'R'},
{"source-pgdata", required_argument, NULL, 1},
{"source-server", required_argument, NULL, 2},
{"no-ensure-shutdown", no_argument, NULL, 44},
XLogRecPtr endrec;
TimeLineID endtli;
ControlFileData ControlFile_new;
+ bool writerecoveryconf = false;
pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_rewind"));
}
}
- while ((c = getopt_long(argc, argv, "D:nNP", long_options, &option_index)) != -1)
+ while ((c = getopt_long(argc, argv, "D:nNPR", long_options, &option_index)) != -1)
{
switch (c)
{
do_sync = false;
break;
+ case 'R':
+ writerecoveryconf = true;
+ break;
+
case 3:
debug = true;
pg_logging_set_level(PG_LOG_DEBUG);
exit(1);
}
+ if (writerecoveryconf && connstr_source == NULL)
+ {
+ pg_log_error("no source server information (--source--server) specified for --write-recovery-conf");
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+ exit(1);
+ }
+
if (optind < argc)
{
pg_log_error("too many command-line arguments (first is \"%s\")",
umask(pg_mode_mask);
+ atexit(disconnect_atexit);
+
/* Connect to remote server */
if (connstr_source)
libpqConnect(connstr_source);
if (!rewind_needed)
{
pg_log_info("no rewind required");
+ if (writerecoveryconf)
+ WriteRecoveryConfig(conn, datadir_target,
+ GenerateRecoveryConfig(conn, NULL));
exit(0);
}
pg_log_info("syncing target data directory");
syncTargetDirectory();
+ if (writerecoveryconf)
+ WriteRecoveryConfig(conn, datadir_target,
+ GenerateRecoveryConfig(conn, NULL));
+
pg_log_info("Done!");
return 0;
pg_fatal("Command was: %s", cmd);
}
}
+
+static void
+disconnect_atexit(void)
+{
+ if (conn != NULL)
+ PQfinish(conn);
+}
#include "datapagemap.h"
#include "access/timeline.h"
+#include "common/logging.h"
+#include "libpq-fe.h"
#include "storage/block.h"
#include "storage/relfilenode.h"
-#include "common/logging.h"
/* Configuration options */
extern char *datadir_target;
extern TimeLineHistoryEntry *targetHistory;
extern int targetNentries;
+/* general state */
+extern PGconn *conn;
+
/* Progress counters */
extern uint64 fetch_size;
extern uint64 fetch_done;
/* in timeline.c */
extern TimeLineHistoryEntry *rewind_parseTimeLineHistory(char *buffer,
- TimeLineID targetTLI, int *nentries);
+ TimeLineID targetTLI,
+ int *nentries);
#endif /* PG_REWIND_H */