1#!/usr/local/bin/perl 2# Do an immediate backup 3 4use strict; 5use warnings; 6require './backup-config-lib.pl'; 7our (%in, %text, %config, $module_config_file); 8&ReadParse(); 9 10# Validate inputs 11&error_setup($text{'backup_err'}); 12my $dest = &parse_backup_destination("dest", \%in); 13my ($configfile, $nofiles, $others) = &parse_backup_what("what", \%in); 14$others ||= ""; 15my @mods = split(/\0/, $in{'mods'}); 16@mods || ($nofiles && !$configfile) || &error($text{'backup_emods'}); 17 18# Go for it 19my ($mode, $user, $pass, $server, $path, $port) = &parse_backup_url($dest); 20my $err; 21if ($mode != 4) { 22 # Save somewhere, and tell the user 23 &ui_print_header(undef, $text{'backup_title'}, ""); 24 print &text('backup_doing', &nice_dest($dest, 1)),"<p>\n"; 25 my $size; 26 my @files; 27 $err = &execute_backup(\@mods, $dest, \$size, \@files, 28 $configfile, $nofiles, 29 [ split(/\t+/, $others) ]); 30 if ($err) { 31 print &text('backup_failed', $err),"<p>\n"; 32 } 33 else { 34 print &text('backup_done', &nice_size($size), 35 scalar(@files)),"<p>\n"; 36 } 37 &ui_print_footer("", $text{'index_return2'}); 38 } 39else { 40 # Output file in browser 41 my $temp = &transname(); 42 my $size; 43 $err = &execute_backup(\@mods, $temp, \$size, undef, 44 $configfile, $nofiles, 45 [ split(/\t+/, $others) ]); 46 if ($err) { 47 &unlink_file($temp); 48 &error($err); 49 } 50 print "Content-type: application/x-gzip\n\n"; 51 my $buf; 52 open(TEMP, "<$temp"); 53 my $bs = &get_buffer_size(); 54 while(read(TEMP, $buf, $bs)) { 55 print $buf; 56 } 57 close(TEMP); 58 &unlink_file($temp); 59 } 60 61if (!$err) { 62 # Save config 63 $config{'dest'} = $dest; 64 $config{'mods'} = join(" ", @mods); 65 $config{'configfile'} = $in{'configfile'}; 66 $config{'nofiles'} = $in{'nofiles'}; 67 &lock_file($module_config_file); 68 &save_module_config(); 69 &unlock_file($module_config_file); 70 &webmin_log("backup", undef, $dest, { 'mods' => \@mods }); 71 } 72 73