@@ -385,15 +385,17 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
385
385
386
386
fprintf (out , "#Configuration\n" );
387
387
fprintf (out , "backup-mode = %s\n" , pgBackupGetBackupMode (backup ));
388
- fprintf (out , "stream = %s\n" , backup -> stream ?"true" :"false" );
389
- fprintf (out , "compress-alg = %s\n" , deparse_compress_alg (compress_alg ));
390
- fprintf (out , "compress-level = %d\n" , compress_level );
391
- fprintf (out , "from-replica = %s\n" , from_replica ?"true" :"false" );
388
+ fprintf (out , "stream = %s\n" , backup -> stream ? "true" : "false" );
389
+ fprintf (out , "compress-alg = %s\n" ,
390
+ deparse_compress_alg (backup -> compress_alg ));
391
+ fprintf (out , "compress-level = %d\n" , backup -> compress_level );
392
+ fprintf (out , "from-replica = %s\n" , backup -> from_replica ? "true" : "false" );
392
393
393
394
fprintf (out , "\n#Compatibility\n" );
394
395
fprintf (out , "block-size = %u\n" , backup -> block_size );
395
396
fprintf (out , "xlog-block-size = %u\n" , backup -> wal_block_size );
396
397
fprintf (out , "checksum-version = %u\n" , backup -> checksum_version );
398
+ fprintf (out , "program-version = %s\n" , PROGRAM_VERSION );
397
399
if (backup -> server_version [0 ] != '\0' )
398
400
fprintf (out , "server-version = %s\n" , backup -> server_version );
399
401
@@ -429,7 +431,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
429
431
if (backup -> data_bytes != BYTES_INVALID )
430
432
fprintf (out , "data-bytes = " INT64_FORMAT "\n" , backup -> data_bytes );
431
433
432
- if (backup -> data_bytes != BYTES_INVALID )
434
+ if (backup -> wal_bytes != BYTES_INVALID )
433
435
fprintf (out , "wal-bytes = " INT64_FORMAT "\n" , backup -> wal_bytes );
434
436
435
437
fprintf (out , "status = %s\n" , status2str (backup -> status ));
@@ -475,10 +477,9 @@ readBackupControlFile(const char *path)
475
477
char * stop_lsn = NULL ;
476
478
char * status = NULL ;
477
479
char * parent_backup = NULL ;
478
- char * compress_alg = NULL ;
480
+ char * program_version = NULL ;
479
481
char * server_version = NULL ;
480
- int * compress_level ;
481
- bool * from_replica ;
482
+ char * compress_alg = NULL ;
482
483
483
484
pgut_option options [] =
484
485
{
@@ -495,13 +496,14 @@ readBackupControlFile(const char *path)
495
496
{'u' , 0 , "block-size" , & backup -> block_size , SOURCE_FILE_STRICT },
496
497
{'u' , 0 , "xlog-block-size" , & backup -> wal_block_size , SOURCE_FILE_STRICT },
497
498
{'u' , 0 , "checksum-version" , & backup -> checksum_version , SOURCE_FILE_STRICT },
499
+ {'s' , 0 , "program-version" , & program_version , SOURCE_FILE_STRICT },
498
500
{'s' , 0 , "server-version" , & server_version , SOURCE_FILE_STRICT },
499
501
{'b' , 0 , "stream" , & backup -> stream , SOURCE_FILE_STRICT },
500
502
{'s' , 0 , "status" , & status , SOURCE_FILE_STRICT },
501
503
{'s' , 0 , "parent-backup-id" , & parent_backup , SOURCE_FILE_STRICT },
502
504
{'s' , 0 , "compress-alg" , & compress_alg , SOURCE_FILE_STRICT },
503
- {'u' , 0 , "compress-level" , & compress_level , SOURCE_FILE_STRICT },
504
- {'b' , 0 , "from-replica" , & from_replica , SOURCE_FILE_STRICT },
505
+ {'u' , 0 , "compress-level" , & backup -> compress_level , SOURCE_FILE_STRICT },
506
+ {'b' , 0 , "from-replica" , & backup -> from_replica , SOURCE_FILE_STRICT },
505
507
{'s' , 0 , "primary-conninfo" , & backup -> primary_conninfo , SOURCE_FILE_STRICT },
506
508
{0 }
507
509
};
@@ -571,13 +573,23 @@ readBackupControlFile(const char *path)
571
573
free (parent_backup );
572
574
}
573
575
576
+ if (program_version )
577
+ {
578
+ StrNCpy (backup -> program_version , program_version ,
579
+ sizeof (backup -> program_version ));
580
+ pfree (program_version );
581
+ }
582
+
574
583
if (server_version )
575
584
{
576
585
StrNCpy (backup -> server_version , server_version ,
577
586
sizeof (backup -> server_version ));
578
587
pfree (server_version );
579
588
}
580
589
590
+ if (compress_alg )
591
+ backup -> compress_alg = parse_compress_alg (compress_alg );
592
+
581
593
return backup ;
582
594
}
583
595
@@ -626,6 +638,48 @@ deparse_backup_mode(BackupMode mode)
626
638
return NULL ;
627
639
}
628
640
641
+ CompressAlg
642
+ parse_compress_alg (const char * arg )
643
+ {
644
+ size_t len ;
645
+
646
+ /* Skip all spaces detected */
647
+ while (isspace ((unsigned char )* arg ))
648
+ arg ++ ;
649
+ len = strlen (arg );
650
+
651
+ if (len == 0 )
652
+ elog (ERROR , "compress algrorithm is empty" );
653
+
654
+ if (pg_strncasecmp ("zlib" , arg , len ) == 0 )
655
+ return ZLIB_COMPRESS ;
656
+ else if (pg_strncasecmp ("pglz" , arg , len ) == 0 )
657
+ return PGLZ_COMPRESS ;
658
+ else if (pg_strncasecmp ("none" , arg , len ) == 0 )
659
+ return NONE_COMPRESS ;
660
+ else
661
+ elog (ERROR , "invalid compress algorithm value \"%s\"" , arg );
662
+
663
+ return NOT_DEFINED_COMPRESS ;
664
+ }
665
+
666
+ const char *
667
+ deparse_compress_alg (int alg )
668
+ {
669
+ switch (alg )
670
+ {
671
+ case NONE_COMPRESS :
672
+ case NOT_DEFINED_COMPRESS :
673
+ return "none" ;
674
+ case ZLIB_COMPRESS :
675
+ return "zlib" ;
676
+ case PGLZ_COMPRESS :
677
+ return "pglz" ;
678
+ }
679
+
680
+ return NULL ;
681
+ }
682
+
629
683
/* free pgBackup object */
630
684
void
631
685
pgBackupFree (void * backup )
0 commit comments