Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  010_pg_archivecleanup.pl

  Sprache: Shell
 


# Copyright (c) 2021-2025, PostgreSQL Global Development Group

use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Utils;
use Test::More;

program_help_ok('pg_archivecleanup');
program_version_ok('pg_archivecleanup');
program_options_handling_ok('pg_archivecleanup');

my $tempdir = PostgreSQL::Test::Utils::tempdir;

# WAL file patterns created before running each sub-scenario.  "present"
# tracks if the file with "name" still exists or not after running
# pg_archivecleanup.
my @walfiles_verbose = (
 { name => '00000001000000370000000D', present => 0 },
 { name => '00000001000000370000000E', present => 1 });
my @walfiles_with_gz = (
 { name => '00000001000000370000000C.gz', present => 0 },
 { name => '00000001000000370000000D', present => 0 },
 { name => '00000001000000370000000D.backup', present => 1 },
 { name => '00000001000000370000000E', present => 1 },
 { name => '00000001000000370000000F.partial', present => 1 },
 { name => 'unrelated_file', present => 1 });
my @walfiles_for_clean_backup_history = (
 { name => '00000001000000370000000D', present => 0 },
 { name => '00000001000000370000000D.00000028.backup', present => 0 },
 { name => '00000001000000370000000E', present => 1 },
 { name => '00000001000000370000000F.partial', present => 1 },
 { name => 'unrelated_file', present => 1 });

sub create_files
{
 foreach my $fn (map { $_->{name} } @_)
 {
  open my $file, '>'"$tempdir/$fn" or die $!;

  print $file 'CONTENT';
  close $file;
 }
 return;
}

sub remove_files
{
 foreach my $fn (map { $_->{name} } @_)
 {
  unlink "$tempdir/$fn";
 }
 return;
}

command_fails_like(
 ['pg_archivecleanup'],
 qr/must specify archive location/,
 'fails if archive location is not specified');

command_fails_like(
 [ 'pg_archivecleanup', $tempdir ],
 qr/must specify oldest kept WAL file/,
 'fails if oldest kept WAL file name is not specified');

command_fails_like(
 [ 'pg_archivecleanup''notexist''foo' ],
 qr/archive location .* does not exist/,
 'fails if archive location does not exist');

command_fails_like(
 [ 'pg_archivecleanup', $tempdir, 'foo''bar' ],
 qr/too many command-line arguments/,
 'fails with too many command-line arguments');

command_fails_like(
 [ 'pg_archivecleanup', $tempdir, 'foo' ],
 qr/invalid file name argument/,
 'fails with invalid restart file name');

# Test a dry run, no files are physically removed, but logs are generated
# to show what would be removed.
{
 create_files(@walfiles_verbose);

 my $stderr;
 my $oldestkeptwalfile = '00000001000000370000000E';
 my $result = IPC::Run::run [
  'pg_archivecleanup''--debug''--dry-run', $tempdir,
  $oldestkeptwalfile
   ],
   '2>' => \$stderr;
 ok($result, "pg_archivecleanup dry run: exit code 0");

 for my $walpair (@walfiles_verbose)
 {
  if ($walpair->{present})
  {
   unlike(
    $stderr,
    qr/$walpair->{name}.*would be removed/,
    "pg_archivecleanup dry run for $walpair->{name}: matches");
  }
  else
  {
   like(
    $stderr,
    qr/$walpair->{name}.*would be removed/,
    "pg_archivecleanup dry run for $walpair->{name}: matches");
  }
 }
 foreach my $fn (map { $_->{name} } @walfiles_verbose)
 {
  ok(-f "$tempdir/$fn""$fn not removed");
 }

 remove_files(@walfiles_verbose);
}

sub run_check
{
 local $Test::Builder::Level = $Test::Builder::Level + 1;

 my ($testdata, $oldestkeptwalfile, $test_name, @options) = @_;

 create_files(@$testdata);

 command_ok(
  [ 'pg_archivecleanup', @options, $tempdir, $oldestkeptwalfile ],
  "$test_name: runs");

 for my $walpair (@$testdata)
 {
  if ($walpair->{present})
  {
   ok(-f "$tempdir/$walpair->{name}",
    "$test_name:$walpair->{name} was not cleaned up");
  }
  else
  {
   ok(!-f "$tempdir/$walpair->{name}",
    "$test_name:$walpair->{name} was cleaned up");
  }
 }

 remove_files(@$testdata);
 return;
}

run_check(\@walfiles_with_gz, '00000001000000370000000E',
 'pg_archivecleanup''-x.gz');
run_check(
 \@walfiles_with_gz,
 '00000001000000370000000E.partial',
 'pg_archivecleanup with .partial file''-x.gz');
run_check(
 \@walfiles_with_gz,
 '00000001000000370000000E.00000020.backup',
 'pg_archivecleanup with .backup file''-x.gz');
run_check(\@walfiles_for_clean_backup_history,
 '00000001000000370000000E',
 'pg_archivecleanup with --clean-backup-history''-b');

done_testing();

Messung V0.5 in Prozent
C=97 H=-11 G=68

¤ Dauer der Verarbeitung: 0.24 Sekunden  (vorverarbeitet am  2026-08-09) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002