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

Annotation of /trunk/bin/BackupPC_incPartsUpdate

Parent Directory Parent Directory | Revision Log Revision Log


Revision 172 - (hide annotations)
Tue Oct 11 16:00:02 2005 UTC (18 years, 7 months ago) by dpavlin
File size: 2694 byte(s)
 r8463@llin:  dpavlin | 2005-10-11 16:06:47 +0200
 removed File::Pid which isn't used

1 dpavlin 157 #!/usr/local/bin/perl -w
2    
3     use strict;
4     use lib "__INSTALLDIR__/lib";
5    
6     use DBI;
7     use BackupPC::Lib;
8     use BackupPC::View;
9     use Data::Dumper;
10     use Time::HiRes qw/time/;
11     use POSIX qw/strftime/;
12     use BackupPC::SearchLib;
13     use Cwd qw/abs_path/;
14    
15     my $path = abs_path($0);
16     $path =~ s#/[^/]+$#/#;
17     my $tarIncCreate = $path .= 'BackupPC_tarIncCreate';
18    
19     die "can't find $tarIncCreate: $!\n" unless (-x $tarIncCreate);
20    
21 dpavlin 162 my $debug = 0;
22 dpavlin 157 $|=1;
23    
24     my $start_t = time();
25    
26     my $t_fmt = '%Y-%m-%d %H:%M:%S';
27    
28     my $hosts;
29     my $bpc = BackupPC::Lib->new || die;
30     my %Conf = $bpc->Conf();
31     my $TopDir = $bpc->TopDir();
32     my $beenThere = {};
33    
34     my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
35     my $user = $Conf{SearchUser} || '';
36    
37     my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
38    
39     my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir};
40    
41     die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_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    
62     select
63 dpavlin 158 backups.id as backup_id,
64 dpavlin 157 hosts.name as host,
65     shares.name as share,
66 dpavlin 158 backups.num as num
67 dpavlin 157 from backups
68     join shares on backups.hostid = shares.hostid
69     and shares.id = backups.shareid
70     join hosts on shares.hostid = hosts.id
71     where inc_size < 0 and not inc_deleted
72     order by backups.date
73    
74     } );
75    
76     $sth->execute();
77    
78 dpavlin 158 my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ? where id = ? });
79 dpavlin 163 my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? });
80 dpavlin 158
81 dpavlin 157 %BackupPC::SearchLib::Conf = %Conf;
82    
83     while (my $row = $sth->fetchrow_hashref) {
84     my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});
85     print curr_time, sprintf(" %s:%s %-3d ", $row->{'host'}, $row->{'share'}, $row->{'num'}), " -> $tar_file ";
86    
87     my $t = time();
88    
89     my $cmd = qq{$tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | gzip -9 > $tar_dir/$tar_file};
90     print STDERR "## $cmd\n" if ($debug);
91    
92     system($cmd) == 0 or die "failed: $?";
93    
94 dpavlin 158 my $size = (stat( "$tar_dir/$tar_file" ))[7];
95 dpavlin 157
96 dpavlin 163 print " dur: ",fmt_time(time() - $t)," $size bytes";
97 dpavlin 158
98 dpavlin 167 if ($size > 45) {
99 dpavlin 163 $sth_inc_size->execute($size, $row->{'backup_id'});
100 dpavlin 168 $sth_inc_deleted->execute(0, $row->{'backup_id'});
101 dpavlin 163 } else {
102     $sth_inc_deleted->execute(1, $row->{'backup_id'});
103     unlink "$tar_dir/$tar_file" || die "can't delete $tar_dir/$tar_file: $!\n";
104     print " EMPTY";
105     }
106     print "\n";
107 dpavlin 158
108     $dbh->commit;
109    
110 dpavlin 157 }
111    
112     undef $sth;
113     $dbh->disconnect;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26