1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-06 08:49:29 +02:00

Added start and stop backup.

This commit is contained in:
David Steele
2013-12-15 20:04:07 -05:00
parent 1d21f4f9fa
commit 0d3fa39117
2 changed files with 58 additions and 27 deletions

View File

@@ -6,7 +6,7 @@ decompress=/usr/bin/gzip -dc %file%
checksum=/usr/bin/shasum %file% | awk '{print $1}'
copy=/bin/cp %source% %destination%
manifest=/opt/local/bin/gfind %path% -printf '%P\t%y\t%u\t%g\t%m\t%T@\t%i\t%s\t%l\n'
tablespace_map=/Library/PostgreSQL/9.3/bin/psql --port=6001 -c 'copy (select oid, spcname from pg_tablespace) to stdout' postgres
psql=/Library/PostgreSQL/9.3/bin/psql --port=6001
diff=/bin/bash -c '/usr/bin/diff -q %file1% %file2%'
[common]

View File

@@ -5,6 +5,7 @@ use warnings;
use File::Basename;
use Getopt::Long;
use Config::IniFiles;
use IPC::System::Simple qw(capture);
use JSON;
# Process flags
@@ -58,12 +59,21 @@ sub log
sub execute
{
my $strCommand = shift;
# print("$strCommand\n");
my $strOutput = qx($strCommand) or return 0; #die "Unable to run ${strCommand}";
# print("$strOutput\n");
return($strOutput);
my $strOutput;
# print("$strCommand");
$strOutput = capture($strCommand);
# if ($strOutput eq "")
# {
# print(" ... complete\n\n");
# }
# else
# {
# print(" ... complete\n$strOutput\n\n");
# }
return $strOutput;
}
####################################################################################################################################
@@ -141,7 +151,7 @@ sub data_hash_build
}
$oHash{"$stryHeader[0]"}{"$stryLine[0]"}{"$stryHeader[$iColumnIdx]"} = $stryLine[$iColumnIdx];
#print "Hash {$stryHeader[0]}{$stryLine[0]}{$stryHeader[$iColumnIdx]} = " . (defined $oHash{"$stryHeader[0]"}{"$stryLine[0]"}{"$stryHeader[$iColumnIdx]"} ? $oHash{"$stryHeader[0]"}{"$stryLine[0]"}{"$stryHeader[$iColumnIdx]"} : "null") . "\n";
# print "Hash {$stryHeader[0]}{$stryLine[0]}{$stryHeader[$iColumnIdx]} = " . (defined $oHash{"$stryHeader[0]"}{"$stryLine[0]"}{"$stryHeader[$iColumnIdx]"} ? $oHash{"$stryHeader[0]"}{"$stryLine[0]"}{"$stryHeader[$iColumnIdx]"} : "null") . "\n";
#$oHash{$stryHeader[$iColumnIdx]}{$stryLine[$iColumnIdx]}{$stryHeader[0]} = $stryLine[0];
}
}
@@ -154,9 +164,10 @@ sub data_hash_build
####################################################################################################################################
sub tablespace_map_get
{
my $strCommandTablespaceMap = shift;
my $strCommandPsql = shift;
my %oTablespaceMap = data_hash_build("oid\tname\n" . execute($strCommandTablespaceMap), "\t");
my %oTablespaceMap = data_hash_build("oid\tname\n" . execute($strCommandPsql .
" -c 'copy (select oid, spcname from pg_tablespace) to stdout' postgres"), "\t");
return %oTablespaceMap;
}
@@ -186,7 +197,7 @@ sub backup_manifest_load
my $strBackupManifestFile = shift;
my %oBackupManifestFile;
tie %oBackupManifestFile, 'Config::IniFiles', (-file => $strBackupManifestFile) or die &log(ERROR, "backup manifest '%{strBackupManifestFile}' could not be loaded");
tie %oBackupManifestFile, 'Config::IniFiles', (-file => $strBackupManifestFile) or die &log(ERROR, "backup manifest '${strBackupManifestFile}' could not be loaded");
my %oBackupManifest;
my $strSection;
@@ -541,16 +552,10 @@ if ($strOperation eq "archive-push")
die "destination file already exists";
}
# Calculate sha1 hash for the file (unless disabled)
if (!$bNoChecksum)
{
$strDestinationFile .= "-" . file_hash_get($strCommandChecksum, $strSourceFile);
}
# Setup the copy command
my $strCommand = "";
if ($bNoCompression)
if ($strSourceFile =~ /\.backup$/)
{
$strCommand = $strCommandCopy;
$strCommand =~ s/\%source\%/$strSourceFile/g;
@@ -558,9 +563,24 @@ if ($strOperation eq "archive-push")
}
else
{
$strCommand = $strCommandCompress;
$strCommand =~ s/\%file\%/$strSourceFile/g;
$strCommand .= " > $strDestinationFile.gz";
# Calculate sha1 hash for the file (unless disabled)
if (!$bNoChecksum)
{
$strDestinationFile .= "-" . file_hash_get($strCommandChecksum, $strSourceFile);
}
if ($bNoCompression)
{
$strCommand = $strCommandCopy;
$strCommand =~ s/\%source\%/$strSourceFile/g;
$strCommand =~ s/\%destination\%/$strDestinationFile/g;
}
else
{
$strCommand = $strCommandCompress;
$strCommand =~ s/\%file\%/$strSourceFile/g;
$strCommand .= " > $strDestinationFile.gz";
}
}
# Execute the copy
@@ -601,7 +621,7 @@ unless (-e $strBackupClusterPath)
# Load commands required for backup
my $strCommandManifest = config_load(\%oConfig, "command", "manifest");
my $strCommandTablespace = config_load(\%oConfig, "command", "tablespace_map");
my $strCommandPsql = config_load(\%oConfig, "command", "psql");
####################################################################################################################################
# BACKUP
@@ -645,18 +665,29 @@ if ($strOperation eq "backup")
# Create a new backup manifest hash
my %oBackupManifest;
# Start backup
my $strLabel = "test_lablel";
&log(INFO, 'Backup start: ' . trim(execute($strCommandPsql .
" -c \"copy (select * from pg_start_backup('${strLabel}')) to stdout\" postgres")));
# Build the backup manifest
my %oTablespaceMap = tablespace_map_get($strCommandTablespace);
my %oTablespaceMap = tablespace_map_get($strCommandPsql);
backup_manifest_build($strCommandManifest, $strClusterDataPath, \%oBackupManifest, \%oTablespaceMap);
#\%oBackupConfig
# Delete files leftover from a partial backup
# !!! do it
# Perform the backup
backup($strCommandChecksum, $strCommandCompress, $strCommandDecompress, $strCommandCopy, $strCommandDiff,
$strClusterDataPath, $strBackupTmpPath, \%oBackupManifest);
# Stop backup
&log(INFO, 'Backup start: ' . trim(execute($strCommandPsql .
" -c \"copy (select * from pg_stop_backup()) to stdout\" postgres")));
#\%oBackupConfig
# Delete files leftover from a partial backup
# !!! do it
# Save the backup conf file
backup_manifest_save($strBackupConfFile, \%oBackupManifest);
backup_manifest_load($strBackupConfFile);