#!/usr/local/bin/perl # backup.cgi # Backup a database to a local file require './postgresql-lib.pl' ; &ReadParse ( ) ; &error_setup ( $text{'backup_err'} ) ; $access{'backup'} || &error($text{'backup_ecannot'}); &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'}); $in{'format'} =~ /^[a-z]$/ || &redirect ( "" ); $in{'path'} =~ /^\S+$/ || &error(&text('backup_pe3', $in{'path'})) ; if ( -e $in{'path'} ) { &error ( &text ( 'backup_pe2', $in{'path'} ) ) ; } $db_find_f = 0 ; if ( $in{'db'} ) { foreach ( &list_databases() ) { if ( $_ eq $in{'db'} ) { $db_find_f = 1 ; } } } if ( $db_find_f == 0 ) { &error ( &text ( 'backup_edb' ) ) ; } $bkup_command = $config{'dump_cmd'}. ($config{'login'} ? " -U $config{'login'}" : ""). ($config{'host'} ? " -h $config{'host'}" : ""). ($in{'format'} eq 'p' ? "" : " -b"). " -F$in{'format'} -f $in{'path'} $in{'db'}" ; if ( $config{'sameunix'} && defined(getpwnam($config{'login'})) ) { $bkup_command =~ s/"/\\"/g ; $bkup_command = "su $config{'login'} -c ".quotemeta($bkup_command); } $temp = &tempname(); open(TEMP, ">$temp"); print TEMP "$config{'pass'}\n"; close(TEMP); $out = &backquote_logged("$bkup_command 2>&1 <$temp"); unlink($temp); if ( $? == 0 ) { &redirect ("edit_dbase.cgi?db=$in{'db'}") ; } else { &error ( &text ( 'backup_exe', $bkup_command )."
$out
" ) ; }