@ -57,7 +57,7 @@ static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
const int compression , ArchiveMode mode , SetupWorkerPtr setupWorkerPtr ) ;
static void _getObjectDescription ( PQExpBuffer buf , TocEntry * te ,
ArchiveHandle * AH ) ;
static void _printTocEntry ( ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData , bool acl_pass ) ;
static void _printTocEntry ( ArchiveHandle * AH , TocEntry * te , bool isData , bool acl_pass ) ;
static char * replace_line_endings ( const char * str ) ;
static void _doSetFixedOutputState ( ArchiveHandle * AH ) ;
static void _doSetSessionAuth ( ArchiveHandle * AH , const char * user ) ;
@ -71,8 +71,8 @@ static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te);
static void processStdStringsEntry ( ArchiveHandle * AH , TocEntry * te ) ;
static teReqs _tocEntryRequired ( TocEntry * te , teSection curSection , RestoreOptions * ropt ) ;
static bool _tocEntryIsACL ( TocEntry * te ) ;
static void _disableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt ) ;
static void _enableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt ) ;
static void _disableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te ) ;
static void _enableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te ) ;
static void buildTocEntryArrays ( ArchiveHandle * AH ) ;
static void _moveBefore ( ArchiveHandle * AH , TocEntry * pos , TocEntry * te ) ;
static int _discoverArchiveFormat ( ArchiveHandle * AH ) ;
@ -84,8 +84,7 @@ static void SetOutput(ArchiveHandle *AH, const char *filename, int compression);
static OutputContext SaveOutput ( ArchiveHandle * AH ) ;
static void RestoreOutput ( ArchiveHandle * AH , OutputContext savedContext ) ;
static int restore_toc_entry ( ArchiveHandle * AH , TocEntry * te ,
RestoreOptions * ropt , bool is_parallel ) ;
static int restore_toc_entry ( ArchiveHandle * AH , TocEntry * te , bool is_parallel ) ;
static void restore_toc_entries_prefork ( ArchiveHandle * AH ) ;
static void restore_toc_entries_parallel ( ArchiveHandle * AH , ParallelState * pstate ,
TocEntry * pending_list ) ;
@ -184,7 +183,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
* setup doesn ' t need to know anything much , so it ' s defined here .
*/
static void
setupRestoreWorker ( Archive * AHX , DumpOptions * dopt , RestoreOptions * ropt )
setupRestoreWorker ( Archive * AHX )
{
ArchiveHandle * AH = ( ArchiveHandle * ) AHX ;
@ -216,12 +215,12 @@ OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
/* Public */
void
CloseArchive ( Archive * AHX , DumpOptions * dopt )
CloseArchive ( Archive * AHX )
{
int res = 0 ;
ArchiveHandle * AH = ( ArchiveHandle * ) AHX ;
( * AH - > ClosePtr ) ( AH , dopt ) ;
( * AH - > ClosePtr ) ( AH ) ;
/* Close the output */
if ( AH - > gzOut )
@ -236,14 +235,25 @@ CloseArchive(Archive *AHX, DumpOptions *dopt)
/* Public */
void
SetArchiveRestore Options ( Archive * AHX , RestoreOptions * ropt )
SetArchiveOptions ( Archive * AH , DumpOptions * dopt , RestoreOptions * ropt )
{
ArchiveHandle * AH = ( ArchiveHandle * ) AHX ;
TocEntry * te ;
teSection curSection ;
/* Caller can omit dump options, in which case we synthesize them */
if ( dopt = = NULL & & ropt ! = NULL )
dopt = dumpOptionsFromRestoreOptions ( ropt ) ;
/* Save options for later access */
AH - > dopt = dopt ;
AH - > ropt = ropt ;
}
/* Public */
void
ProcessArchiveRestoreOptions ( Archive * AHX )
{
ArchiveHandle * AH = ( ArchiveHandle * ) AHX ;
RestoreOptions * ropt = AH - > public . ropt ;
TocEntry * te ;
teSection curSection ;
/* Decide which TOC entries will be dumped/restored, and mark them */
curSection = SECTION_PRE_DATA ;
@ -298,7 +308,7 @@ void
RestoreArchive ( Archive * AHX )
{
ArchiveHandle * AH = ( ArchiveHandle * ) AHX ;
RestoreOptions * ropt = AH - > ropt ;
RestoreOptions * ropt = AH - > public . ropt ;
bool parallel_mode ;
TocEntry * te ;
OutputContext sav ;
@ -605,7 +615,7 @@ RestoreArchive(Archive *AHX)
Assert ( AH - > connection = = NULL ) ;
/* ParallelBackupStart() will actually fork the processes */
pstate = ParallelBackupStart ( AH , NULL , ropt ) ;
pstate = ParallelBackupStart ( AH ) ;
restore_toc_entries_parallel ( AH , pstate , & pending_list ) ;
ParallelBackupEnd ( AH , pstate ) ;
@ -616,7 +626,7 @@ RestoreArchive(Archive *AHX)
else
{
for ( te = AH - > toc - > next ; te ! = AH - > toc ; te = te - > next )
( void ) restore_toc_entry ( AH , te , ropt , false ) ;
( void ) restore_toc_entry ( AH , te , false ) ;
}
/*
@ -636,7 +646,7 @@ RestoreArchive(Archive *AHX)
else
ahlog ( AH , 1 , " setting owner and privileges for %s \" %s \" \n " ,
te - > desc , te - > tag ) ;
_printTocEntry ( AH , te , ropt , false , true ) ;
_printTocEntry ( AH , te , false , true ) ;
}
}
@ -673,9 +683,9 @@ RestoreArchive(Archive *AHX)
* the parallel parent has to make the corresponding status update .
*/
static int
restore_toc_entry ( ArchiveHandle * AH , TocEntry * te ,
RestoreOptions * ropt , bool is_parallel )
restore_toc_entry ( ArchiveHandle * AH , TocEntry * te , bool is_parallel )
{
RestoreOptions * ropt = AH - > public . ropt ;
int status = WORKER_OK ;
teReqs reqs ;
bool defnDumped ;
@ -717,7 +727,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
ahlog ( AH , 1 , " creating %s \" %s \" \n " , te - > desc , te - > tag ) ;
_printTocEntry ( AH , te , ropt , false , false ) ;
_printTocEntry ( AH , te , false , false ) ;
defnDumped = true ;
if ( strcmp ( te - > desc , " TABLE " ) = = 0 )
@ -782,7 +792,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
*/
if ( AH - > PrintTocDataPtr ! = NULL )
{
_printTocEntry ( AH , te , ropt , true , false ) ;
_printTocEntry ( AH , te , true , false ) ;
if ( strcmp ( te - > desc , " BLOBS " ) = = 0 | |
strcmp ( te - > desc , " BLOB COMMENTS " ) = = 0 )
@ -795,13 +805,13 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
if ( strcmp ( te - > desc , " BLOB COMMENTS " ) = = 0 )
AH - > outputKind = OUTPUT_OTHERDATA ;
( * AH - > PrintTocDataPtr ) ( AH , te , ropt ) ;
( * AH - > PrintTocDataPtr ) ( AH , te ) ;
AH - > outputKind = OUTPUT_SQLCMDS ;
}
else
{
_disableTriggersIfNecessary ( AH , te , ropt ) ;
_disableTriggersIfNecessary ( AH , te ) ;
/* Select owner and schema as necessary */
_becomeOwner ( AH , te ) ;
@ -848,7 +858,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
else
AH - > outputKind = OUTPUT_OTHERDATA ;
( * AH - > PrintTocDataPtr ) ( AH , te , ropt ) ;
( * AH - > PrintTocDataPtr ) ( AH , te ) ;
/*
* Terminate COPY if needed .
@ -862,7 +872,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
if ( is_parallel & & te - > created )
CommitTransaction ( & AH - > public ) ;
_enableTriggersIfNecessary ( AH , te , ropt ) ;
_enableTriggersIfNecessary ( AH , te ) ;
}
}
}
@ -870,7 +880,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
{
/* If we haven't already dumped the defn part, do so now */
ahlog ( AH , 1 , " executing %s %s \n " , te - > desc , te - > tag ) ;
_printTocEntry ( AH , te , ropt , false , false ) ;
_printTocEntry ( AH , te , false , false ) ;
}
}
@ -900,8 +910,10 @@ NewRestoreOptions(void)
}
static void
_disableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt )
_disableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te )
{
RestoreOptions * ropt = AH - > public . ropt ;
/* This hack is only needed in a data-only restore */
if ( ! ropt - > dataOnly | | ! ropt - > disable_triggers )
return ;
@ -926,8 +938,10 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
}
static void
_enableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt )
_enableTriggersIfNecessary ( ArchiveHandle * AH , TocEntry * te )
{
RestoreOptions * ropt = AH - > public . ropt ;
/* This hack is only needed in a data-only restore */
if ( ! ropt - > dataOnly | | ! ropt - > disable_triggers )
return ;
@ -1040,9 +1054,10 @@ ArchiveEntry(Archive *AHX,
/* Public */
void
PrintTOCSummary ( Archive * AHX , RestoreOptions * ropt )
PrintTOCSummary ( Archive * AHX )
{
ArchiveHandle * AH = ( ArchiveHandle * ) AHX ;
RestoreOptions * ropt = AH - > public . ropt ;
TocEntry * te ;
teSection curSection ;
OutputContext sav ;
@ -1159,7 +1174,9 @@ EndBlob(Archive *AHX, Oid oid)
void
StartRestoreBlobs ( ArchiveHandle * AH )
{
if ( ! AH - > ropt - > single_txn )
RestoreOptions * ropt = AH - > public . ropt ;
if ( ! ropt - > single_txn )
{
if ( AH - > connection )
StartTransaction ( & AH - > public ) ;
@ -1176,7 +1193,9 @@ StartRestoreBlobs(ArchiveHandle *AH)
void
EndRestoreBlobs ( ArchiveHandle * AH )
{
if ( ! AH - > ropt - > single_txn )
RestoreOptions * ropt = AH - > public . ropt ;
if ( ! ropt - > single_txn )
{
if ( AH - > connection )
CommitTransaction ( & AH - > public ) ;
@ -1265,9 +1284,10 @@ EndRestoreBlob(ArchiveHandle *AH, Oid oid)
* * * * * * * * * * */
void
SortTocFromFile ( Archive * AHX , RestoreOptions * ropt )
SortTocFromFile ( Archive * AHX )
{
ArchiveHandle * AH = ( ArchiveHandle * ) AHX ;
RestoreOptions * ropt = AH - > public . ropt ;
FILE * fh ;
char buf [ 100 ] ;
bool incomplete_line ;
@ -1550,7 +1570,9 @@ ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
static int
RestoringToDB ( ArchiveHandle * AH )
{
return ( AH - > ropt & & AH - > ropt - > useDB & & AH - > connection ) ;
RestoreOptions * ropt = AH - > public . ropt ;
return ( ropt & & ropt - > useDB & & AH - > connection ) ;
}
/*
@ -2303,7 +2325,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
}
void
WriteDataChunks ( ArchiveHandle * AH , DumpOptions * dopt , ParallelState * pstate )
WriteDataChunks ( ArchiveHandle * AH , ParallelState * pstate )
{
TocEntry * te ;
@ -2326,13 +2348,13 @@ WriteDataChunks(ArchiveHandle *AH, DumpOptions *dopt, ParallelState *pstate)
DispatchJobForTocEntry ( AH , pstate , te , ACT_DUMP ) ;
}
else
WriteDataChunksForTocEntry ( AH , dopt , te ) ;
WriteDataChunksForTocEntry ( AH , te ) ;
}
EnsureWorkersFinished ( AH , pstate ) ;
}
void
WriteDataChunksForTocEntry ( ArchiveHandle * AH , DumpOptions * dopt , TocEntry * te )
WriteDataChunksForTocEntry ( ArchiveHandle * AH , TocEntry * te )
{
StartDataPtr startPtr ;
EndDataPtr endPtr ;
@ -2356,7 +2378,7 @@ WriteDataChunksForTocEntry(ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te)
/*
* The user - provided DataDumper routine needs to call AH - > WriteData
*/
( * te - > dataDumper ) ( ( Archive * ) AH , dopt , te - > dataDumperArg ) ;
( * te - > dataDumper ) ( ( Archive * ) AH , te - > dataDumperArg ) ;
if ( endPtr ! = NULL )
( * endPtr ) ( AH , te ) ;
@ -2827,6 +2849,8 @@ _tocEntryIsACL(TocEntry *te)
static void
_doSetFixedOutputState ( ArchiveHandle * AH )
{
RestoreOptions * ropt = AH - > public . ropt ;
/* Disable statement_timeout since restore is probably slow */
ahprintf ( AH , " SET statement_timeout = 0; \n " ) ;
@ -2842,8 +2866,8 @@ _doSetFixedOutputState(ArchiveHandle *AH)
AH - > public . std_strings ? " on " : " off " ) ;
/* Select the role to be used during restore */
if ( AH - > ropt & & AH - > ropt - > use_role )
ahprintf ( AH , " SET ROLE %s; \n " , fmtId ( AH - > ropt - > use_role ) ) ;
if ( ropt & & ropt - > use_role )
ahprintf ( AH , " SET ROLE %s; \n " , fmtId ( ropt - > use_role ) ) ;
/* Make sure function checking is disabled */
ahprintf ( AH , " SET check_function_bodies = false; \n " ) ;
@ -2854,7 +2878,7 @@ _doSetFixedOutputState(ArchiveHandle *AH)
ahprintf ( AH , " SET escape_string_warning = off; \n " ) ;
/* Adjust row-security state */
if ( AH - > ropt & & AH - > ropt - > enable_row_security )
if ( ropt & & ropt - > enable_row_security )
ahprintf ( AH , " SET row_security = on; \n " ) ;
else
ahprintf ( AH , " SET row_security = off; \n " ) ;
@ -3012,7 +3036,9 @@ _becomeUser(ArchiveHandle *AH, const char *user)
static void
_becomeOwner ( ArchiveHandle * AH , TocEntry * te )
{
if ( AH - > ropt & & ( AH - > ropt - > noOwner | | ! AH - > ropt - > use_setsessauth ) )
RestoreOptions * ropt = AH - > public . ropt ;
if ( ropt & & ( ropt - > noOwner | | ! ropt - > use_setsessauth ) )
return ;
_becomeUser ( AH , te - > owner ) ;
@ -3083,12 +3109,13 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
static void
_selectTablespace ( ArchiveHandle * AH , const char * tablespace )
{
RestoreOptions * ropt = AH - > public . ropt ;
PQExpBuffer qry ;
const char * want ,
* have ;
/* do nothing in --no-tablespaces mode */
if ( AH - > ropt - > noTablespace )
if ( ropt - > noTablespace )
return ;
have = AH - > currTablespace ;
@ -3214,8 +3241,10 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH)
}
static void
_printTocEntry ( ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData , bool acl_pass )
_printTocEntry ( ArchiveHandle * AH , TocEntry * te , bool isData , bool acl_pass )
{
RestoreOptions * ropt = AH - > public . ropt ;
/* ACLs are dumped only during acl pass */
if ( acl_pass )
{
@ -3624,7 +3653,6 @@ dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim)
static void
restore_toc_entries_prefork ( ArchiveHandle * AH )
{
RestoreOptions * ropt = AH - > ropt ;
bool skipped_some ;
TocEntry * next_work_item ;
@ -3676,7 +3704,7 @@ restore_toc_entries_prefork(ArchiveHandle *AH)
next_work_item - > dumpId ,
next_work_item - > desc , next_work_item - > tag ) ;
( void ) restore_toc_entry ( AH , next_work_item , ropt , false ) ;
( void ) restore_toc_entry ( AH , next_work_item , false ) ;
/* there should be no touch of ready_list here, so pass NULL */
reduce_dependencies ( AH , next_work_item , NULL ) ;
@ -3857,7 +3885,7 @@ restore_toc_entries_parallel(ArchiveHandle *AH, ParallelState *pstate,
static void
restore_toc_entries_postfork ( ArchiveHandle * AH , TocEntry * pending_list )
{
RestoreOptions * ropt = AH - > ropt ;
RestoreOptions * ropt = AH - > public . ropt ;
TocEntry * te ;
ahlog ( AH , 2 , " entering restore_toc_entries_postfork \n " ) ;
@ -3880,7 +3908,7 @@ restore_toc_entries_postfork(ArchiveHandle *AH, TocEntry *pending_list)
{
ahlog ( AH , 1 , " processing missed item %d %s %s \n " ,
te - > dumpId , te - > desc , te - > tag ) ;
( void ) restore_toc_entry ( AH , te , ropt , false ) ;
( void ) restore_toc_entry ( AH , te , false ) ;
}
/* The ACLs will be handled back in RestoreArchive. */
@ -4045,7 +4073,6 @@ parallel_restore(ParallelArgs *args)
{
ArchiveHandle * AH = args - > AH ;
TocEntry * te = args - > te ;
RestoreOptions * ropt = AH - > ropt ;
int status ;
_doSetFixedOutputState ( AH ) ;
@ -4055,7 +4082,7 @@ parallel_restore(ParallelArgs *args)
AH - > public . n_errors = 0 ;
/* Restore the TOC item */
status = restore_toc_entry ( AH , te , ropt , true ) ;
status = restore_toc_entry ( AH , te , true ) ;
return status ;
}
@ -4417,7 +4444,7 @@ CloneArchive(ArchiveHandle *AH)
*/
if ( AH - > mode = = archModeRead )
{
RestoreOptions * ropt = AH - > ropt ;
RestoreOptions * ropt = AH - > public . ropt ;
Assert ( AH - > connection = = NULL ) ;
/* this also sets clone->connection */