@@ -43,12 +43,11 @@ static void backup_files(const char *from_root, const char *to_root,
43
43
static parray * do_backup_database (parray * backup_list ,pgBackupOption bkupopt );
44
44
static parray * do_backup_arclog (parray * backup_list );
45
45
static parray * do_backup_srvlog (parray * backup_list );
46
- static void remove_stopinfo_from_backup_label (char * history_file ,char * bkup_label );
47
- static void make_backup_label (parray * backup_list );
48
46
static void confirm_block_size (const char * name ,int blcksz );
49
47
static void pg_start_backup (const char * label ,bool smooth ,pgBackup * backup );
50
48
static void pg_stop_backup (pgBackup * backup );
51
49
static void pg_switch_xlog (pgBackup * backup );
50
+ static bool pg_is_standby (void );
52
51
static void get_lsn (PGresult * res ,XLogRecPtr * lsn );
53
52
static void get_xid (PGresult * res ,uint32 * xid );
54
53
@@ -86,6 +85,10 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
86
85
if (current .backup_mode == BACKUP_MODE_ARCHIVE )
87
86
return NULL ;
88
87
88
+ /* Block backup operations on a standby */
89
+ if (pg_is_standby ())
90
+ elog (ERROR_SYSTEM ,_ ("Backup cannot run on a standby." ));
91
+
89
92
elog (INFO ,_ ("database backup start" ));
90
93
91
94
/* Initialize size summary */
@@ -125,12 +128,8 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
125
128
if (!fileExists (path ))
126
129
has_backup_label = false;
127
130
128
- snprintf (path ,lengthof (path ),"%s/recovery.conf" ,pgdata );
129
- make_native_path (path );
130
- if (fileExists (path ))
131
- current .is_from_standby = true;
132
-
133
- if (!has_backup_label && !current .is_from_standby )
131
+ /* Leave if no backup file */
132
+ if (!has_backup_label )
134
133
{
135
134
if (verbose )
136
135
printf (_ ("backup_label does not exist, stop backup\n" ));
@@ -386,11 +385,6 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
386
385
/* notify end of backup */
387
386
pg_stop_backup (& current );
388
387
389
- /* if backup is from standby, making backup_label from*/
390
- /* backup.history file.*/
391
- if (current .is_from_standby )
392
- make_backup_label (files );
393
-
394
388
/* create file list */
395
389
create_file_list (files ,pgdata ,NULL , false);
396
390
}
@@ -439,6 +433,10 @@ do_backup_arclog(parray *backup_list)
439
433
current .backup_mode == BACKUP_MODE_INCREMENTAL ||
440
434
current .backup_mode == BACKUP_MODE_FULL );
441
435
436
+ /* Block backup operations on a standby */
437
+ if (pg_is_standby ())
438
+ elog (ERROR_SYSTEM ,_ ("Backup cannot run on a standby." ));
439
+
442
440
if (verbose )
443
441
{
444
442
printf (_ ("========================================\n" ));
@@ -455,10 +453,6 @@ do_backup_arclog(parray *backup_list)
455
453
if ((uint32 )current .stop_lsn == 0 )
456
454
pg_switch_xlog (& current );
457
455
458
- /* Archive backup is not available for a standby */
459
- if (current .is_from_standby )
460
- elog (ERROR_SYSTEM ,_ ("Archive backup not allowed on a standby node" ));
461
-
462
456
/*
463
457
* Check if there is a full backup present on current timeline.
464
458
* For an incremental or full backup, we are sure that there is one
@@ -584,6 +578,10 @@ do_backup_srvlog(parray *backup_list)
584
578
if (!current .with_serverlog )
585
579
return NULL ;
586
580
581
+ /* Block backup operations on a standby */
582
+ if (pg_is_standby ())
583
+ elog (ERROR_SYSTEM ,_ ("Backup cannot run on a standby." ));
584
+
587
585
if (verbose )
588
586
{
589
587
printf (_ ("========================================\n" ));
@@ -739,7 +737,6 @@ do_backup(pgBackupOption bkupopt)
739
737
current .wal_block_size = XLOG_BLCKSZ ;
740
738
current .recovery_xid = 0 ;
741
739
current .recovery_time = (time_t )0 ;
742
- current .is_from_standby = false;
743
740
744
741
/* create backup directory and backup.ini */
745
742
if (!check )
@@ -843,80 +840,6 @@ do_backup(pgBackupOption bkupopt)
843
840
return 0 ;
844
841
}
845
842
846
- void
847
- remove_stopinfo_from_backup_label (char * history_file ,char * bkup_label )
848
- {
849
- FILE * read ;
850
- FILE * write ;
851
- char buf [MAXPGPATH * 2 ];
852
-
853
- if ((read = fopen (history_file ,"r" ))== NULL )
854
- elog (ERROR_SYSTEM ,
855
- _ ("can't open backup history file for standby backup." ));
856
- if ((write = fopen (bkup_label ,"w" ))== NULL )
857
- elog (ERROR_SYSTEM ,
858
- _ ("can't open backup_label file for standby backup." ));
859
- while (fgets (buf ,lengthof (buf ),read )!= NULL )
860
- {
861
- if (strstr (buf ,"STOP" )- buf == 0 )
862
- continue ;
863
- fputs (buf ,write );
864
- }
865
- fclose (write );
866
- fclose (read );
867
- }
868
-
869
- /*
870
- * creating backup_label from backup.history for standby backup.
871
- */
872
- void
873
- make_backup_label (parray * backup_list )
874
- {
875
- char dest_path [MAXPGPATH ];
876
- char src_bkup_history_file [MAXPGPATH ];
877
- char dst_bkup_label_file [MAXPGPATH ];
878
- char original_bkup_label_file [MAXPGPATH ];
879
- parray * bkuped_arc_files = NULL ;
880
- int i ;
881
-
882
- pgBackupGetPath (& current ,dest_path ,lengthof (dest_path ),DATABASE_DIR );
883
- bkuped_arc_files = parray_new ();
884
- dir_list_file (bkuped_arc_files ,arclog_path ,NULL , true, false);
885
-
886
- for (i = parray_num (bkuped_arc_files )- 1 ;i >=0 ;i -- )
887
- {
888
- char * current_arc_fname ;
889
- pgFile * current_arc_file ;
890
-
891
- current_arc_file = (pgFile * )parray_get (bkuped_arc_files ,i );
892
- current_arc_fname = last_dir_separator (current_arc_file -> path )+ 1 ;
893
-
894
- if (strlen (current_arc_fname ) <=24 )continue ;
895
-
896
- copy_file (arclog_path ,dest_path ,current_arc_file ,NO_COMPRESSION );
897
- join_path_components (src_bkup_history_file ,dest_path ,current_arc_fname );
898
- join_path_components (dst_bkup_label_file ,dest_path ,PG_BACKUP_LABEL_FILE );
899
- join_path_components (original_bkup_label_file ,pgdata ,PG_BACKUP_LABEL_FILE );
900
- remove_stopinfo_from_backup_label (src_bkup_history_file ,dst_bkup_label_file );
901
-
902
- dir_list_file (backup_list ,dst_bkup_label_file ,NULL , false, true);
903
- for (i = 0 ;i < parray_num (backup_list );i ++ )
904
- {
905
- pgFile * file = (pgFile * )parray_get (backup_list ,i );
906
- if (strcmp (file -> path ,dst_bkup_label_file )== 0 )
907
- {
908
- struct stat st ;
909
- stat (dst_bkup_label_file ,& st );
910
- file -> write_size = st .st_size ;
911
- file -> crc = pgFileGetCRC (file );
912
- strcpy (file -> path ,original_bkup_label_file );
913
- }
914
- }
915
- parray_qsort (backup_list ,pgFileComparePath );
916
- break ;
917
- }
918
- }
919
-
920
843
/*
921
844
* get server version and confirm block sizes.
922
845
*/
@@ -1080,6 +1003,19 @@ pg_switch_xlog(pgBackup *backup)
1080
1003
"SELECT * FROM pg_switch_xlog()" );
1081
1004
}
1082
1005
1006
+ /*
1007
+ * Check if node is a standby by looking at the presence of
1008
+ * recovery.conf.
1009
+ */
1010
+ static bool
1011
+ pg_is_standby (void )
1012
+ {
1013
+ char path [MAXPGPATH ];
1014
+ snprintf (path ,lengthof (path ),"%s/recovery.conf" ,pgdata );
1015
+ make_native_path (path );
1016
+ return fileExists (path );
1017
+ }
1018
+
1083
1019
/*
1084
1020
* Get LSN from result of pg_start_backup() or pg_stop_backup().
1085
1021
*/