*** git/doc/src/sgml/ref/pg_basebackup.sgml Wed Apr 9 09:37:30 2014
--- Git_code/postgresql/doc/src/sgml/ref/pg_basebackup.sgml Wed Mar 26 11:36:16 2014
***************
*** 349,354 ****
--- 349,365 ----
+
+
+
+
+
+
+ Excludes the log files in the backup. This will exclude all the logs in pg_log directory and any other
+ log directory specified via postgresql.conf file settings.
+
+
+
*** git/src/backend/replication/basebackup.c Wed Apr 9 09:37:42 2014
--- Git_code/postgresql/src/backend/replication/basebackup.c Wed Apr 9 09:52:15 2014
***************
*** 36,42 ****
#include "utils/elog.h"
#include "utils/ps_status.h"
#include "utils/timestamp.h"
!
typedef struct
{
--- 36,42 ----
#include "utils/elog.h"
#include "utils/ps_status.h"
#include "utils/timestamp.h"
! extern PGDLLIMPORT char *Log_directory;
typedef struct
{
***************
*** 46,51 ****
--- 46,52 ----
bool nowait;
bool includewal;
uint32 maxrate;
+ bool skip_log_dir;
} basebackup_options;
***************
*** 70,75 ****
--- 71,77 ----
/* Relative path of temporary statistics directory */
static char *statrelpath = NULL;
+ static char *logrelpath = NULL;
/*
* Size of each block sent into the tar stream for larger files.
***************
*** 148,153 ****
--- 150,170 ----
else
statrelpath = pgstat_stat_directory;
+ if (opt->skip_log_dir)
+ {
+ if (is_absolute_path(Log_directory) &&
+ strncmp(Log_directory, DataDir, datadirpathlen) == 0)
+ {
+ logrelpath = psprintf("./%s", Log_directory + datadirpathlen + 1);
+ }
+ else if (strncmp(Log_directory, "./", 2) != 0)
+ {
+ logrelpath = psprintf("./%s", Log_directory);
+ }
+ else
+ logrelpath = Log_directory;
+ }
+
PG_ENSURE_ERROR_CLEANUP(base_backup_cleanup, (Datum) 0);
{
List *tablespaces = NIL;
***************
*** 548,553 ****
--- 565,571 ----
bool o_nowait = false;
bool o_wal = false;
bool o_maxrate = false;
+ bool o_skiplogdir = false;
MemSet(opt, 0, sizeof(*opt));
foreach(lopt, options)
***************
*** 618,623 ****
--- 636,650 ----
opt->maxrate = (uint32) maxrate;
o_maxrate = true;
}
+ else if (strcmp(defel->defname, "skip_log_dir") == 0)
+ {
+ if (o_skiplogdir)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("duplicate option \"%s\"", defel->defname)));
+ opt->skip_log_dir = true;
+ o_skiplogdir = true;
+ }
else
elog(ERROR, "option \"%s\" not recognized",
defel->defname);
***************
*** 984,989 ****
--- 1011,1040 ----
}
/*
+ * Skip log directory files only if skip_log_dir option specified in
+ * pg_basebackup. PG_LOG_DIRECTORY is also skipped. Create empty
+ * directory anyway.
+ */
+ if ((logrelpath != NULL) &&
+ ((strncmp(pathbuf, logrelpath, strlen(pathbuf)) == 0) || strncmp(de->d_name, PG_LOG_DIRECTORY, strlen(de->d_name)) == 0))
+ {
+ if (!sizeonly)
+ {
+ #ifndef WIN32
+ if (S_ISLNK(statbuf.st_mode))
+ #else
+ if (pgwin32_is_junction(pathbuf))
+ #endif
+ statbuf.st_mode = S_IFDIR | S_IRWXU;
+ _tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
+ }
+ size += 512;
+ continue;
+ }
+
+
+
+ /*
* Skip pg_replslot, not useful to copy. But include it as an empty
* directory anyway, so we get permissions right.
*/
*** git/src/backend/replication/repl_gram.y Wed Apr 9 09:37:42 2014
--- Git_code/postgresql/src/backend/replication/repl_gram.y Wed Mar 26 13:43:04 2014
***************
*** 75,80 ****
--- 75,81 ----
%token K_PHYSICAL
%token K_LOGICAL
%token K_SLOT
+ %token K_SKIP_LOG_DIR
%type command
%type base_backup start_replication start_logical_replication create_replication_slot drop_replication_slot identify_system timeline_history
***************
*** 168,173 ****
--- 169,179 ----
$$ = makeDefElem("max_rate",
(Node *)makeInteger($2));
}
+ | K_SKIP_LOG_DIR
+ {
+ $$ = makeDefElem("skip_log_dir",
+ (Node *)makeInteger(TRUE));
+ }
;
create_replication_slot:
*** git/src/backend/replication/repl_scanner.l Wed Apr 9 09:37:42 2014
--- Git_code/postgresql/src/backend/replication/repl_scanner.l Wed Mar 26 13:43:40 2014
***************
*** 87,92 ****
--- 87,93 ----
NOWAIT { return K_NOWAIT; }
PROGRESS { return K_PROGRESS; }
MAX_RATE { return K_MAX_RATE; }
+ SKIP_LOG_DIR { return K_SKIP_LOG_DIR; }
WAL { return K_WAL; }
TIMELINE { return K_TIMELINE; }
START_REPLICATION { return K_START_REPLICATION; }
*** git/src/backend/utils/misc/guc.c Wed Apr 9 09:37:59 2014
--- Git_code/postgresql/src/backend/utils/misc/guc.c Wed Mar 26 11:39:06 2014
***************
*** 61,66 ****
--- 61,67 ----
#include "replication/syncrep.h"
#include "replication/walreceiver.h"
#include "replication/walsender.h"
+ #include "replication/basebackup.h"
#include "storage/bufmgr.h"
#include "storage/dsm_impl.h"
#include "storage/standby.h"
***************
*** 2985,2991 ****
GUC_SUPERUSER_ONLY
},
&Log_directory,
! "pg_log",
check_canonical_path, NULL, NULL
},
{
--- 2986,2992 ----
GUC_SUPERUSER_ONLY
},
&Log_directory,
! PG_LOG_DIRECTORY,
check_canonical_path, NULL, NULL
},
{
*** git/src/bin/pg_basebackup/pg_basebackup.c Wed Apr 9 09:37:43 2014
--- Git_code/postgresql/src/bin/pg_basebackup/pg_basebackup.c Wed Apr 9 09:55:40 2014
***************
*** 66,72 ****
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static pg_time_t last_progress_report = 0;
static int32 maxrate = 0; /* no limit by default */
!
/* Progress counters */
static uint64 totalsize;
--- 66,72 ----
static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
static pg_time_t last_progress_report = 0;
static int32 maxrate = 0; /* no limit by default */
! static bool skip_log_dir = false;
/* Progress counters */
static uint64 totalsize;
***************
*** 239,244 ****
--- 239,245 ----
printf(_(" --xlogdir=XLOGDIR location for the transaction log directory\n"));
printf(_(" -z, --gzip compress tar output\n"));
printf(_(" -Z, --compress=0-9 compress tar output with given compression level\n"));
+ printf(_(" -S, --skip-log-dir avoid backup of log files\n"));
printf(_("\nGeneral options:\n"));
printf(_(" -c, --checkpoint=fast|spread\n"
" set fast or spread checkpointing\n"));
***************
*** 1659,1671 ****
maxrate_clause = psprintf("MAX_RATE %u", maxrate);
basebkp =
! psprintf("BASE_BACKUP LABEL '%s' %s %s %s %s %s",
escaped_label,
showprogress ? "PROGRESS" : "",
includewal && !streamwal ? "WAL" : "",
fastcheckpoint ? "FAST" : "",
includewal ? "NOWAIT" : "",
! maxrate_clause ? maxrate_clause : "");
if (PQsendQuery(conn, basebkp) == 0)
{
--- 1660,1673 ----
maxrate_clause = psprintf("MAX_RATE %u", maxrate);
basebkp =
! psprintf("BASE_BACKUP LABEL '%s' %s %s %s %s %s %s",
escaped_label,
showprogress ? "PROGRESS" : "",
includewal && !streamwal ? "WAL" : "",
fastcheckpoint ? "FAST" : "",
includewal ? "NOWAIT" : "",
! maxrate_clause ? maxrate_clause : "",
! skip_log_dir ? "SKIP_LOG_DIR" : "");
if (PQsendQuery(conn, basebkp) == 0)
{
***************
*** 1964,1969 ****
--- 1966,1972 ----
{"status-interval", required_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{"progress", no_argument, NULL, 'P'},
+ {"skip-log-dir", no_argument, NULL, 'S'},
{"xlogdir", required_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
***************
*** 1989,1995 ****
}
}
! while ((c = getopt_long(argc, argv, "D:F:r:RT:xX:l:zZ:d:c:h:p:U:s:wWvP",
long_options, &option_index)) != -1)
{
switch (c)
--- 1992,1998 ----
}
}
! while ((c = getopt_long(argc, argv, "D:F:r:RT:xX:l:zZ:d:c:h:p:U:s:wWvPS",
long_options, &option_index)) != -1)
{
switch (c)
***************
*** 2122,2127 ****
--- 2125,2133 ----
case 'P':
showprogress = true;
break;
+ case 'S':
+ skip_log_dir = true;
+ break;
default:
/*
*** git/src/include/replication/basebackup.h Wed Apr 9 09:37:47 2014
--- Git_code/postgresql/src/include/replication/basebackup.h Wed Mar 26 13:45:13 2014
***************
*** 21,26 ****
--- 21,27 ----
#define MAX_RATE_UPPER 1048576
+ #define PG_LOG_DIRECTORY "pg_log"
extern void SendBaseBackup(BaseBackupCmd *cmd);
#endif /* _BASEBACKUP_H */