/[BackupPC]/trunk/bin/BackupPC_burnArchiveCLI
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/BackupPC_burnArchiveCLI

Parent Directory Parent Directory | Revision Log Revision Log


Revision 174 - (show annotations)
Tue Oct 11 16:59:16 2005 UTC (18 years, 7 months ago) by dpavlin
File size: 3072 byte(s)
 r8467@llin:  dpavlin | 2005-10-11 18:59:10 +0200
 first cut at BackupPC_burnArchiveCLI, used to burn archive media from command
 line.

1 #!/usr/local/bin/perl
2
3 use strict;
4 #use lib "__INSTALLDIR__/lib";
5 # FIXME
6 use lib "/data/backuppc/lib";
7
8 use DBI;
9 use BackupPC::Lib;
10 use BackupPC::SearchLib;
11 use Time::HiRes qw/time/;
12 use POSIX qw/strftime/;
13 use Term::Menus;
14
15 use Data::Dumper;
16
17 my $debug = 0;
18 $|=1;
19
20 my $start_t = time();
21
22 my $t_fmt = '%Y-%m-%d %H:%M:%S';
23
24 # don't check for user
25 my $bpc = BackupPC::Lib->new(undef, undef, 1) || die;
26 my %Conf = $bpc->Conf();
27 %BackupPC::SearchLib::Conf = %Conf;
28
29 my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
30 my $user = $Conf{SearchUser} || '';
31
32 my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 1 });
33
34 my $tar_dir = $Conf{InstallDir}.'/';
35 $tar_dir .= $Conf{GzipTempDir} || die "GzipTempDir isn't defined in configuration";
36
37 die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir);
38
39 my $iso_dir = $Conf{InstallDir}.'/';
40 $iso_dir .= $Conf{ISOTempDir} || die "ISOTempDir isn't defined in configuration";
41 die "problem with $iso_dir, check ISOTempDir in configuration\n" unless (-d $iso_dir && -w $iso_dir);
42
43 #---- subs ----
44
45 sub fmt_time {
46 my $t = shift || return;
47 my $out = "";
48 my ($ss,$mm,$hh) = gmtime($t);
49 $out .= "${hh}h" if ($hh);
50 $out .= sprintf("%02d:%02d", $mm,$ss);
51 return $out;
52 }
53
54 sub curr_time {
55 return strftime($t_fmt,localtime());
56 }
57
58 #----- main
59
60 my $sth = $dbh->prepare( qq{
61 select
62 id,dvd_nr,total_size,note,username,
63 archive.date as date,
64 count(archive_burned.archive_id) as copies
65 from archive
66 left outer join archive_burned on archive.id=archive_burned.archive_id
67 group by id,dvd_nr,total_size,note,username,archive.date
68 order by date asc
69 } );
70
71 $sth->execute();
72
73 sub fmt_archive($) {
74 my $row = shift || die;
75
76 $row->{'date'} =~ s/\.\d+$//;
77 $row->{'copies'} =~ s/^\s*0+\s*$/no/;
78 $row->{'total_size'} /= (1024*1024);
79
80 my $copies = 'copies';
81 $copies = 'copy' if ($row->{'copies'} == 1);
82
83 return
84 sprintf("%d by %s on %s, %s %s [%.2f Mb]",
85 $row->{'dvd_nr'},
86 $row->{'username'},
87 $row->{'date'},
88 $row->{'copies'}, $copies,
89 $row->{'total_size'},
90 );
91 }
92
93 my @burned;
94 my @not_burned;
95
96 while (my $row = $sth->fetchrow_hashref) {
97 if ($row->{'copies'}) {
98 push @burned, fmt_archive($row);
99 } else {
100 push @not_burned, fmt_archive($row);
101 }
102 }
103
104 my %Menu_archive = (
105 Label => 'Menu_archive',
106
107 Item_1 => {
108 Text => 'DVD #]Convey[',
109 Convey => [ @not_burned ],
110 Default => '*',
111 },
112 Item_2 => {
113 Text => 'DVD #]Convey[',
114 Convey => [ @burned ],
115 },
116
117 Select => 'Many',
118
119 Banner => "Select one or more DVD media for burning",
120 );
121
122 my @archives_to_burn = Menu(\%Menu_archive);
123
124 print "\n";
125
126 foreach my $arc (@archives_to_burn) {
127 exit if ($arc eq ']quit[');
128
129 my $dvd_nr = $1 if ($arc =~ m/DVD #(\d+)/);
130 die "BUG: can't find dvd_nr in $arc\n" unless ($dvd_nr);
131
132 print "Working on DVD #$dvd_nr\n";
133
134 }
135
136 #my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});
137 #print curr_time, sprintf(" %s:%s %-3d ", $row->{'host'}, $row->{'share'}, $row->{'num'}), " -> $tar_file ";
138
139 $sth->finish;
140 $dbh->disconnect;
141

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26