@@ -463,11 +463,81 @@ sub backup
463
463
my $port = $self -> port;
464
464
my $name = $self -> name;
465
465
466
- print " # Taking backup $backup_name from node \" $name \"\n " ;
466
+ print " # Taking pg_basebackup $backup_name from node \" $name \"\n " ;
467
467
TestLib::system_or_bail(" pg_basebackup -D $backup_path -p $port -x" );
468
468
print " # Backup finished\n " ;
469
469
}
470
470
471
+ =item $node->backup_fs_hot(backup_name)
472
+
473
+ Create a backup with a filesystem level copy in $node->backup_dir,
474
+ including transaction logs. Archiving must be enabled as pg_start_backup
475
+ and pg_stop_backup are used. This is not checked or enforced.
476
+
477
+ The backup name is passed as the backup label to pg_start_backup.
478
+
479
+ =cut
480
+
481
+ sub backup_fs_hot
482
+ {
483
+ my ($self , $backup_name ) = @_ ;
484
+ $self -> _backup_fs($backup_name , 1);
485
+ }
486
+
487
+ =item $node->backup_fs_cold(backup_name)
488
+
489
+ Create a backup with a filesystem level copy in $node->backup dir,
490
+ including transaction logs. The server must be stopped as no
491
+ attempt to handle concurrent writes is made.
492
+
493
+ Use backup or backup_fs_hot if you want to back up a running
494
+ server.
495
+
496
+ =cut
497
+
498
+ sub backup_fs_cold
499
+ {
500
+ my ($self , $backup_name ) = @_ ;
501
+ $self -> _backup_fs($backup_name , 0);
502
+ }
503
+
504
+
505
+ # Common sub of backup_fs_hot and backup_fs_cold
506
+ sub _backup_fs
507
+ {
508
+ my ($self , $backup_name , $hot ) = @_ ;
509
+ my $backup_path = $self -> backup_dir . ' /' . $backup_name ;
510
+ my $port = $self -> port;
511
+ my $name = $self -> name;
512
+
513
+ print " # Taking filesystem level backup $backup_name from node \" $name \"\n " ;
514
+
515
+ if ($hot ) {
516
+ my $stdout = $self -> psql_check(' postgres' , " SELECT * FROM pg_start_backup('$backup_name ');" );
517
+ print " # pg_start_backup: $stdout \n " ;
518
+ }
519
+
520
+ RecursiveCopy::copypath($self -> data_dir, $backup_path ,
521
+ filterfn => sub {
522
+ my $src = shift ;
523
+ return $src !~ / \/ pg_log\/ / && $src !~ / \/ postmaster.pid$ / ;
524
+ }
525
+ );
526
+
527
+ if ($hot )
528
+ {
529
+ # We ignore pg_stop_backup's return value. We also assume archiving
530
+ # is enabled; otherwise the caller will have to copy the remaining
531
+ # segments.
532
+ my $stdout = $self -> psql_check(' postgres' , ' SELECT * FROM pg_stop_backup();' );
533
+ print " # pg_stop_backup: $stdout \n " ;
534
+ }
535
+
536
+ print " # Backup finished\n " ;
537
+ }
538
+
539
+
540
+
471
541
=pod
472
542
473
543
=item $node->init_from_backup(root_node, backup_name)
@@ -917,17 +987,6 @@ Pass additional parameters to psql. Must be an arrayref.
917
987
918
988
e.g.
919
989
920
- my ($stdout, $stderr, $timed_out);
921
- my $cmdret = $psql_expert('postgres', 'SELECT pg_sleep(60)',
922
- stdout => \$stdout, stderr => \$stderr,
923
- timeout => 30, timed_out => \$timed_out,
924
- extra_params => ['--single-transaction'])
925
-
926
- will set $cmdret to undef and $timed_out to a true value.
927
-
928
- $psql_expert('postgres', $sql, on_error_die => 1);
929
-
930
- dies with an informative message if $sql fails.
931
990
932
991
=cut
933
992
0 commit comments