document `make newdb'
[irspy-moved-to-github.git] / bin / irspy-dump.pl
1 #!/usr/bin/perl
2
3 # Invoke as:
4 #       $ mkdir records-2010-04-06
5 #       $ cd records-2010-04-06
6 #       $ irspy-dump.pl irspy.indexdata.com:8018/IR-Explain---1
7 #       $ cd ..
8 #       $ tar cfz records-2010-04-06.tar.gz records-2010-04-06
9
10 use strict;
11 use warnings;
12 use ZOOM;
13
14 if (@ARGV != 1) {
15     print STDERR "Usage: $0 target\n";
16     exit 1;
17 }
18
19 my $conn = new ZOOM::Connection($ARGV[0]);
20 $conn->option(preferredRecordSyntax => "xml");
21 $conn->option(elementSetName => "zebra::data");
22 my $rs = $conn->search_pqf('@attr 1=_ALLRECORDS @attr 2=103 ""');
23 my $n = $rs->size();
24 $| = 1;
25 print "$0: dumping $n records\n";
26 foreach my $i (1..$n) {
27     print ".";
28     print " $i/$n (", int($i*100/$n), "%)\n" if $i % 50 == 0;
29     my $rec = $rs->record($i-1);
30     my $xml = $rec->render();
31     open F, ">$i.xml";
32     print F $xml;
33     close F;
34 }
35 print " $n/$n (100%)\n" if $n % 50 != 0;
36 print "complete\n";