diff options
Diffstat (limited to 'perl-install/standalone/drakbackup')
-rwxr-xr-x | perl-install/standalone/drakbackup | 137 |
1 files changed, 83 insertions, 54 deletions
diff --git a/perl-install/standalone/drakbackup b/perl-install/standalone/drakbackup index 351f363f3..dbce62c84 100755 --- a/perl-install/standalone/drakbackup +++ b/perl-install/standalone/drakbackup @@ -119,7 +119,7 @@ my @list_of_rpm_to_install; my @other_files; my @sys_files = "/etc"; my $host_passwd; -my $untar_prefix; +my $untar_prefix = "tar -C $restore_path -x"; # allow not-root user with own config if ($ENV{USER} ne 'root' && $ENV{HOME} ne '/root') { @@ -147,6 +147,20 @@ foreach (@ARGV) { /--debug/ and $DEBUG = 1, next; } +sub getVarsFromSh { + my %l; + open(my $F, $_[0]) or return; + local $_; + while (<$F>) { + s/#.*//; # remove comments + s/^\s*//; # leading space + my ($v, $val) = /^(\w+)=(.*)/ or next; + $val = $1 if $val =~ /^"(.*)"$/ || $val =~ /^'(.*)'$/; + $l{$v} = $val; + } + %l; +} + sub setup_tooltips() { %help = ( 'use_expect' => N("Expect is an extension to the Tcl scripting language that allows interactive sessions without user intervention."), @@ -223,16 +237,13 @@ sub get_tape_info() { my @line_data; my $info = "$ENV{HOME}/tmp/dmesg"; @tape_devices = (); - system("dmesg | grep 'st[0-9] at' > $info"); + system("dmesg -s 100000 | grep 'st[0-9] at' > $info"); - local *INFO; - open INFO, $info or warn("Can't open $info\n"); - local $_; - while (<INFO>) { + my @info = cat_($info); + foreach (@info) { @line_data = split(/[ \t,]+/, $_); push @tape_devices, "/dev/" . $line_data[3]; } - close INFO; unlink($info); } @@ -246,8 +257,8 @@ sub get_free_space { sub check_storage_quota { my ($dir) = @_; - my $used = `du $dir`; - my $used_space = $used / 1024; + my $used = `du -b $dir`; + my $used_space = $used / 1024 / 1024; if ($used_space > $conf{MAX_SPACE}) { return $used_space; } else { @@ -310,7 +321,7 @@ sub get_cd_info() { print "{$key}->{dvdr} = $cd_devices{$key}{dvdr}\n"; print "{$key}->{dvdram} = $cd_devices{$key}{dvdram}\n"; } else { - delete $cd_devices{$key} if $cd_devices{$key}{rec_dev} eq '' + delete $cd_devices{$key} if $cd_devices{$key}{rec_dev} eq ''; } } } @@ -392,7 +403,7 @@ sub save_cron_files() { system("chmod +x /etc/cron.$conf{DAEMON_TIME_SPACE}/drakbackup"); } if ($conf{DAEMON_TIME_SPACE} eq "custom" || !$backup_daemon) { - my $newdetail = join(" ", $time_string, $exec_string, "\n") if $backup_daemon; + my $newdetail = $backup_daemon && join(" ", $time_string, $exec_string, "\n"); system("crontab -l | tail +4 > $tmpcron"); my @cronlines = cat_($tmpcron); my $index = 0; @@ -400,7 +411,7 @@ sub save_cron_files() { if (/$exec_string/) { splice(@cronlines, $index, 1); } - $index++ + $index++; } push(@cronlines, $newdetail) if $backup_daemon; output($tmpcron, @cronlines); @@ -547,6 +558,7 @@ sub ftp_client() { $ftp = 0; } return 1 if !$ftp; + $ftp->binary(); $ftp->cwd($conf{HOST_PATH}); foreach (@file_list_to_send_by_ftp) { $interactive and $pbar->set_fraction(0); @@ -728,9 +740,11 @@ sub check_for_cd() { show_warning("f", N("Does not appear to be recordable media!")); return 1; } - if ($log_buff =~ /Is not erasable/ && $conf{MEDIA_ERASE}) { - show_warning("f", N("Not erasable media!")); - return 1; + #- non-fatal, just disable erase + if (($log_buff =~ /Is not erasable/ || $log_buff =~ /Found DVD media/) && $conf{MEDIA_ERASE}) { + show_warning("w", N("Not erasable media!")); + $conf{MEDIA_ERASE} = 0; + save_conf_file(); } if ($conf{MULTI_SESSION}) { @@ -755,8 +769,8 @@ sub check_for_cd() { sub write_on_cd() { my $command = "cdrecord -v dev=$conf{CD_DEVICE} -data "; - # DVD+RW use -dao - $command .= "-dao " if $conf{DVDRW}; + # DVD+RW use -sao + $command .= "-sao " if $conf{DVDRW}; #- only blank if it's the first session $command .= "blank=fast " if $conf{MEDIA_ERASE} && $session_offset eq ''; #- multi-session mode @@ -1029,7 +1043,7 @@ sub build_backup_files() { my $list_file = name_list_file($incr . $user); do_find($more_recent, $find_args_user, $list_file, $path_name); if (check_rm_list($list_file)) { - do_tar($tar_cmd_user, "backup_$incr$user", $list_file, undef); + do_tar($tar_cmd_cuser, "backup_$incr$user", $list_file, undef); } $first_done = 1; } else { @@ -1042,13 +1056,13 @@ sub build_backup_files() { if (!$first_done) { my $list_file = name_list_file($incr . $user); do_find(undef, $find_args_user, $list_file, $path_name); - do_tar($tar_cmd_user, "backup_$incr$user", undef, $path_name); + do_tar($tar_cmd_cuser, "backup_$incr$user", undef, $path_name); } - push_list("$incr$user") if $incr =~ /_user/; + push_list("list_$incr$user") if $incr =~ /_user/; files_to_results("$incr$user"); } } - $interactive and progress($pbar2, $plabel1, 1, N("Backup User files...")); + $interactive and progress($pbar1, $plabel1, 1, N("Backup User files...")); $interactive and progress($pbar3, $plabel3, 0.4, N("Hard Disk Backup files...")); if ($conf{OTHER_FILES}) { @@ -1078,12 +1092,12 @@ sub build_backup_files() { if (!$first_done) { my $list_file = name_list_file($incr); do_find(undef, $find_args_other, $list_file, @other_files); - do_tar($tar_cmd_user, "backup_$incr", undef, @other_files); + do_tar($tar_cmd_other, "backup_$incr", undef, @other_files); } push_list("list_$incr") if $incr =~ /_other/; files_to_results($incr); } - $interactive and progress($pbar1, $plabel2, 1, N("Backup Other files...")); + $interactive and progress($pbar2, $plabel2, 1, N("Backup Other files...")); $interactive and progress($pbar3, $plabel3, 0.3, N("Hard Disk Backup Progress...")); } @@ -1172,7 +1186,7 @@ sub build_backup_files() { $catalog .= ":Users=(@user_list)" unless $conf{NO_USER_FILES}; $catalog .= ":I" if $conf{USER_INCREMENTAL_BACKUPS} && !$conf{NO_USER_FILES} && !$conf{USER_DIFFERENTIAL_BACKUPS}; $catalog .= ":D" if $conf{USER_INCREMENTAL_BACKUPS} && !$conf{NO_USER_FILES} && $conf{USER_DIFFERENTIAL_BACKUPS}; - $catalog .= ":F" if !$conf{USER_INCREMENTAL_BACKUPS} && !$conf{NO_USER_FILES};; + $catalog .= ":F" if !$conf{USER_INCREMENTAL_BACKUPS} && !$conf{NO_USER_FILES}; $catalog .= ":Other=(@other_files)" if $conf{OTHER_FILES}; $catalog .= ":I" if $conf{OTHER_INCREMENTAL_BACKUPS} && $conf{OTHER_FILES} && !$conf{OTHER_DIFFERENTIAL_BACKUPS}; $catalog .= ":D" if $conf{OTHER_INCREMENTAL_BACKUPS} && $conf{OTHER_FILES} && $conf{OTHER_DIFFERENTIAL_BACKUPS}; @@ -1239,6 +1253,8 @@ sub do_find { #- $newer may be undef - if it's defined then "-cnewer $newer" $newer = $conf{PATH_TO_SAVE} . "/" . $newer if defined($newer); defined($newer) ? system("find @where -cnewer $newer $more_args > $into") : system("find @where $more_args > $into"); + #- someone on club complained about perms being too open + chmod(0600, $into) if -e $into; } sub do_tar { @@ -1246,6 +1262,8 @@ sub do_tar { my $full_dest_file = $conf{PATH_TO_SAVE} . "/" . $dest_file . $the_time . "." . $conf{OPTION_COMP}; #- if $list_file is undefined, then use the @files list defined($list_file) ? system("$tar_cmd -f $full_dest_file -T $list_file") : system("$tar_cmd -f $full_dest_file @files"); + #- someone on club complained about perms being too open + chmod(0600, $full_dest_file) if -e $full_dest_file; push_list($dest_file); } @@ -1254,7 +1272,7 @@ sub push_list { my $filename = $conf{PATH_TO_SAVE} . "/" . $prefix . $the_time . "."; $filename .= $conf{OPTION_COMP} if $prefix =~ /^backup/; $filename .= "txt" if $prefix =~ /^list/; - push @file_list_to_send_by_ftp, $filename; + push @file_list_to_send_by_ftp, $filename if -e $filename; } sub files_to_results { @@ -1262,6 +1280,7 @@ sub files_to_results { $results .= "\nfile: " . $conf{PATH_TO_SAVE} . "/backup_" . $basename . $the_time . "." . $conf{OPTION_COMP} . "\n\n"; $results .= cat_("$conf{PATH_TO_SAVE}/list_" . $basename . $the_time . ".txt"); $results .= "\nignored:\n" . $ignore_files_list . "\n" if $ignore_files_list; + } sub handle_ignores { @@ -1358,6 +1377,8 @@ sub filedialog_generic { $$widget->set_text($file_dialog->get_filename); } else { my $file_name = $file_dialog->get_filename; + #- catch files and dirs with spaces + $file_name = '"' . $file_name . '"' if $file_name =~ / /; if (!member($file_name, @other_files)) { push(@other_files, $file_name); $list_model->append_set(undef, $file_name); @@ -1783,7 +1804,7 @@ sub advanced_where_cd { foreach ([$check_cdrw_erase, \$conf{MEDIA_ERASE}], [$check_dvdrw, \$conf{DVDRW}], [$check_dvdr, \$conf{DVDR}], [$check_dvdram, \$conf{DVDRAM}], [$check_multisession, \$conf{MULTI_SESSION}]) { my $ref = $_->[1]; - gtksignal_connect(gtkset_active($_->[0], $$ref), toggled => sub { $$ref = $$ref ? 0 : 1 }) + gtksignal_connect(gtkset_active($_->[0], $$ref), toggled => sub { $$ref = $$ref ? 0 : 1 }); } gtksignal_connect(gtkset_active($check_where_cd, $conf{USE_CD}), toggled => sub { $conf{USE_CD} = $conf{USE_CD} ? 0 : 1; @@ -1945,7 +1966,7 @@ sub advanced_where_hd { 1, new Gtk2::VBox(0, 6), 0, gtkset_size_request(gtkset_sensitive($save_path_entry = new Gtk2::Entry(), $conf{USE_HD}), 152, 20), 0, gtkset_sensitive($button = gtksignal_connect(Gtk2::Button->new, clicked => sub { - filedialog_generic(N("Directory to save to"), \$save_path_entry) + filedialog_generic(N("Directory to save to"), \$save_path_entry); }), $conf{USE_HD}), ), 0, new Gtk2::VBox(0, 6), @@ -2156,7 +2177,7 @@ sub advanced_when() { advanced_when(); }); if ($custom_cron) { - $entry_crontab->set_text("$time_string $exec_string") + $entry_crontab->set_text("$time_string $exec_string"); } $combo_minute_when->entry->signal_connect('changed', sub { combo_to_cron_string($combo_minute_when->get_history - 1, 0) }); @@ -2272,7 +2293,7 @@ sub advanced_box() { sub wizard_step3() { destroy_widget(); - my $no_device = 1 if $conf{USE_CD} && $conf{CD_DEVICE} eq '' || $conf{USE_TAPE} && $conf{TAPE_DEVICE} eq '' || $conf{USE_NET} && $conf{NET_PROTO} eq ''; + my $no_device = $conf{USE_CD} && $conf{CD_DEVICE} eq '' || $conf{USE_TAPE} && $conf{TAPE_DEVICE} eq '' || $conf{USE_NET} && $conf{NET_PROTO} eq '' && 1; if ($no_device) { show_warning("f", N("Backup destination not configured...")); wizard_step2(); @@ -2413,7 +2434,7 @@ sub wizard() { } else { @user_list = (); } - }) + }); } if (!$conf{NO_SYS_FILES} || !$conf{NO_USER_FILES} && @user_list) { fonction_env(\$box2, \&wizard, \&interactive_mode_box, \&wizard_step2); @@ -2580,7 +2601,7 @@ sub select_user_data_to_restore() { @user_list_to_restore = (); local $_; - -d $path_to_find_restore and my @list_backup_tmp2 = grep { /^backup/ } all($path_to_find_restore); + my @list_backup_tmp2 = -d $path_to_find_restore && grep { /^backup/ } all($path_to_find_restore); @list_tmp2 = @list_backup_tmp2; foreach (@list_backup_tmp2) { s/_base//gi; @@ -2776,22 +2797,18 @@ sub restore_aff_result() { button_box_ok_only(); $central_widget = \$do_restore; $up_box->show_all; - } sub return_path { my ($username) = @_; my $usr; my $home_dir; - my $passwdfile = "/etc/passwd"; - local *PASSWD; - open(PASSWD, $passwdfile) or exit 1; - while (defined(my $line = <PASSWD>)) { + my @passwords = cat_("/etc/passwd"); + foreach my $line (@passwords) { chomp($line); ($usr, $home_dir) = (split(/:/, $line))[0,5]; last if $usr eq $username; } - close(PASSWD); return $home_dir; } @@ -2884,6 +2901,7 @@ sub restore_do() { } sub restore_do2() { + destroy_widget(); my $do_restore; my $text = new Gtk2::TextView; restore_state(); @@ -2964,7 +2982,7 @@ sub restore_step_user() { if (!$check_user_to_restore{$name_complet}[1]) { $check_user_to_restore{$name_complet}[1] = 1; if (!any { /$name/ } @user_list_to_restore2) { - push @user_list_to_restore2, $name_complet + push @user_list_to_restore2, $name_complet; } } else { $check_user_to_restore{$name_complet}[1] = 0; @@ -3071,7 +3089,8 @@ sub restore_step2() { my $sys_exist; my $user_exist; local $_; - + destroy_widget(); + my $restore_info_path = $conf{PATH_TO_SAVE}; $restore_info_path = $path_to_find_restore if $conf{USE_HD} || $conf{USE_CD}; my $info_prefix = "backup"; @@ -3088,7 +3107,7 @@ sub restore_step2() { $sys_exist = 0; $restore_sys = 0; } if (any { /_user_/ } grep { /^$info_prefix/ } all("$restore_info_path/")) { - $user_exist = 1 + $user_exist = 1; } else { $user_exist = 0; $restore_user = 0; } @@ -3143,7 +3162,7 @@ sub restore_step2() { } else { $next_widget = \&restore_do; } - }) + }); } gtksignal_connect(gtkset_active($check_restore_other_path, $restore_other_path), toggled => sub { $restore_other_path = $restore_other_path ? 0 : 1; @@ -3187,7 +3206,8 @@ sub find_files_to_restore() { my @files_to_restore; my $cat_entry; my @catalog = cat_("$cfg_dir/drakbackup_catalog"); - + destroy_widget(); + #- file info in tree view my $model = Gtk2::TreeStore->new("Glib::String", "Gtk2::Gdk::Pixbuf", "Glib::Int"); my $file_list = Gtk2::TreeView->new_with_model($model); @@ -3222,7 +3242,7 @@ sub find_files_to_restore() { chop; $model->append_set($list_entry, [ 0 => $_, 1 => $unselected, 2 => 0 ]); } - $match = 1 + $match = 1; } } show_warning("i", N("No matches found...")) if $match == 0; @@ -3281,7 +3301,8 @@ sub catalog_restore { my $cat_entry; my @restore_files; my $restore_path_entry; - + destroy_widget(); + #- catalog info in tree view my $model = Gtk2::TreeStore->new("Glib::String"); my $tree_catalog = Gtk2::TreeView->new_with_model($model); @@ -3411,7 +3432,7 @@ sub catalog_restore { }); $button->add(gtkpack(new Gtk2::HBox(0,10), gtkcreate_img("ic82-dossier-32"))); button_box_restore(); - fonction_env(\$catalog_box, \&catalog_restore, \&restore_find_media_box, \&catalog_restore) if $call_method eq "need media";; + fonction_env(\$catalog_box, \&catalog_restore, \&restore_find_media_box, \&catalog_restore) if $call_method eq "need media"; fonction_env(\$catalog_box, \&catalog_restore, \&restore_box, \&catalog_restore) if $call_method eq "button"; $central_widget = \$catalog_box; $up_box->show_all; @@ -3612,6 +3633,7 @@ sub restore_ftp { else { $ftp = Net::FTP->new($hostname, Debug => 0) or return 1 } $ftp->login($username, $userpass); $ftp->cwd($hostpath); + $ftp->binary(); my $wild_card = catalog_to_wildcard($cat_entry); @@ -3693,9 +3715,12 @@ sub wildcard_to_tarfile { sub file_to_tarfile { my ($restore_file, $wildcard) = @_; + #- remove leading "/" + $restore_file = substr($restore_file, 1); + #- filename with spaces + $restore_file = "'" . $restore_file . "'" if $restore_file =~ / /; my $tarfile = `grep -l $restore_file $conf{PATH_TO_SAVE}/*$wildcard.txt`; chop $tarfile; - $restore_file = substr($restore_file, 1); $tarfile = basename($tarfile); $tarfile =~ s/txt/$conf{OPTION_COMP}/; $tarfile =~ s/list/backup/; @@ -3727,7 +3752,7 @@ sub get_file_from_tape { my $offset = find_tape_offset($cat_entry); spawn_progress("mt -f $dev_path rewind", "Rewinding tape on $dev_path."); spawn_progress("mt -f $dev_path fsf $offset", "Moving forward $offset file records."); - spawn_progress("tar -C cfg_dir/restores -xf $dev_path", "Untarring from $dev_path to work directory."); + spawn_progress("tar -C $cfg_dir/restores -xf $dev_path", "Untarring from $dev_path to work directory."); } sub restore_box() { @@ -3750,7 +3775,7 @@ sub restore_box() { 1, new Gtk2::VBox(0,10), 1, gtksignal_connect(Gtk2::Button->new(N("Search for files to restore")), clicked => sub { button_box_file_restore(); - find_files_to_restore() + find_files_to_restore(); }), 1, gtksignal_connect(Gtk2::Button->new(N("Restore all backups")), clicked => sub { button_box_restore(); @@ -3758,7 +3783,7 @@ sub restore_box() { $restore_sys = 1; $restore_other = 1; $restore_user = 1; - restore_do() + restore_do(); }), 1, gtksignal_connect(Gtk2::Button->new(N("Custom Restore")), clicked => sub { button_box_restore(); @@ -3775,7 +3800,7 @@ sub restore_box() { ); } else { destroy_widget(); - restore_find_media_box(), + restore_find_media_box(); } fonction_env(\$box2, \&restore_box, \&interactive_mode_box); $central_widget = \$box2; @@ -3820,7 +3845,7 @@ sub restore_find_media_box() { gtksignal_connect(Gtk2::Button->new(N("Search for files to restore")), clicked => sub { $box2->destroy; button_box_file_restore(); - find_files_to_restore() + find_files_to_restore(); }), ), new Gtk2::VBox(0, 5), @@ -3874,6 +3899,10 @@ sub cbutton() { 0, gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => \&interactive_mode_box); } +sub cbuttonr() { + 0, gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => \&restore_box); +} + sub ibutton { my ($msg) = @_; 0, gtksignal_connect(Gtk2::Button->new($msg), clicked => \&interactive_mode_box); @@ -3983,7 +4012,7 @@ sub button_box_restore_end() { $button_box_tmp->destroy; gtkpack($button_box, $button_box_tmp = gtkpack_(new Gtk2::HButtonBox, - cbutton(), + cbuttonr(), hbutton(), hspace(), pbutton(), @@ -4010,7 +4039,7 @@ sub button_box_restore() { $button_box_tmp->destroy; gtkpack($button_box, $button_box_tmp = gtkpack_(new Gtk2::HButtonBox, - cbutton(), + cbuttonr(), hbutton(), hspace(), pbutton(), @@ -4179,7 +4208,7 @@ sub build_backup_ftp_status() { $table = gtkpack_(new Gtk2::VBox(0, 15), 1, N("Sending files by FTP"), 1, new Gtk2::VBox(0, 15), - 1, create_packtable ({ col_spacings => 10, row_spacings => 5 }, + 1, create_packtable({ col_spacings => 10, row_spacings => 5 }, [N("Sending files...")], [""], [ $plabel = new Gtk2::Label(' ') ], |