first serious try to write dirtyupdate script
[rersyncrecent.git] / bin / rrr-dirtyupdate
blobcc7f7d936913f49b2b906c8b71f95693ecbaa84e
1 #!/usr/bin/perl -- -*- mode: cperl -*-
3 =head1 NAME
5 rrr-dirtyupdate - add a file with an old timestamp to the dataset
7 =head1 SYNOPSIS
9 rrr-dirtyupdate [options] principalfile file [epoch]
11 rrr-dirtyupdate --force principalfile
13 =head1 OPTIONS
15 =over 8
17 =cut
19 my @opt = <<'=back' =~ /B<--(\S+)>/g;
21 =item B<--force|f>
23 Force this run even without any arguments. E.g. just for the side
24 effect of running an aggregate call.
26 =item B<--help|h>
28 Prints a brief message and exists.
30 =item B<--verbose|v+>
32 More feedback.
34 =back
36 =head1 DESCRIPTION
38 When you later discover missing files...
40 The principalfile argument is the path to local principal recentfile.
42 The file argument must be an existing file.
44 If the epoch argument is missing it is calculated from the
45 modification time of the file.
47 =head1 BUGS
49 This is slow: it calls aggregate twice with force which took 2 x 10-20 seconds on PAUSE.
51 =cut
54 use strict;
55 use warnings;
57 use File::Find qw(find);
58 use File::Rsync::Mirror::Recent;
59 use Getopt::Long;
60 use Pod::Usage qw(pod2usage);
62 our %Opt;
63 GetOptions(\%Opt,
64 @opt,
65 ) or pod2usage(1);
67 if ($Opt{help}) {
68 pod2usage(0);
71 my $aggregate_only = 0;
72 if (@ARGV == 1 && $Opt{force}) {
73 $aggregate_only=1;
74 } elsif (@ARGV >= 3) {
75 pod2usage(1);
78 my($principal,$file,$epoch) = @ARGV;
79 my $recc = File::Rsync::Mirror::Recent->new
80 (local => $principal);
81 my($rf) = $recc->recentfiles;
83 unless ($aggregate_only) {
84 unless (defined $epoch) {
85 my(@stat) = stat $file or die "Could not stat '$file': $!";
86 $epoch = $stat[9];
88 $rf->update($file,"new",$epoch);
90 warn localtime()." starting first aggregate\n";
91 $rf->aggregate(force => 1);
92 warn localtime()." starting second aggregate\n";
93 $rf->aggregate(force => 1);
94 warn localtime()." finished\n";
97 __END__
100 # Local Variables:
101 # mode: cperl
102 # coding: utf-8
103 # cperl-indent-level: 4
104 # End: