3 # Backup a database to a local file
5 require './postgresql-lib.pl' ;
9 &error_setup ( $text{'backup_err'} ) ;
11 $access{'backup'} || &error($text{'backup_ecannot'});
12 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
13 $in{'format'} =~ /^[a-z]$/ || &redirect ( "" );
14 $in{'path'} =~ /^\S+$/ || &error(&text('backup_pe3', $in{'path'})) ;
15 if ( -e $in{'path'} ) {
16 &error ( &text ( 'backup_pe2', $in{'path'} ) ) ;
23 foreach ( &list_databases() ) {
25 if ( $_ eq $in{'db'} ) { $db_find_f = 1 ; }
29 if ( $db_find_f == 0 ) { &error ( &text ( 'backup_edb' ) ) ; }
31 $bkup_command = $config{'dump_cmd'}.
32 ($config{'login'} ? " -U $config{'login'}" : "").
33 ($config{'host'} ? " -h $config{'host'}" : "").
34 ($in{'format'} eq 'p' ? "" : " -b").
35 " -F$in{'format'} -f $in{'path'} $in{'db'}" ;
37 if ( $config{'sameunix'} && defined(getpwnam($config{'login'})) ) {
38 $bkup_command =~ s/"/\\"/g ;
39 $bkup_command = "su $config{'login'} -c ".quotemeta($bkup_command);
44 print TEMP "$config{'pass'}\n";
46 $out = &backquote_logged("$bkup_command 2>&1 <$temp");
50 &redirect ("edit_dbase.cgi?db=$in{'db'}") ;
52 &error ( &text ( 'backup_exe', $bkup_command )."<pre>$out</pre>" ) ;