c4fd65d2f95423b6e33dbb712dfd11c01c25cb27
[ZOOM-Perl-moved-to-github.git] / samples / zoom / zoomdump
1 #!/usr/bin/perl -w
2
3 # $Id: zoomdump,v 1.2 2007-03-07 11:34:26 mike Exp $
4 #
5 # Dumps the contents of the nominated Zebra database to a set of
6 # separate XML files with numeric names.
7
8 use strict;
9 use warnings;
10 use ZOOM;
11
12 if (@ARGV != 1) {
13     print STDERR "Usage: $0 target\n";
14     exit 1;
15 }
16
17 my $conn = new ZOOM::Connection($ARGV[0]);
18 $conn->option(preferredRecordSyntax => "xml");
19 $conn->option(elementSetName => "zebra::data");
20 my $rs = $conn->search_pqf('@attr 1=_ALLRECORDS @attr 2=103 ""');
21 my $n = $rs->size();
22 $| = 1;
23 print "$0: dumping $n records\n";
24 foreach my $i (1..$n) {
25     print ".";
26     print " $i/$n (", int($i*100/$n), "%)\n" if $i % 50 == 0;
27     my $rec = $rs->record($i-1);
28     my $xml = $rec->render();
29     open F, ">$i.xml" or die "can't open\n";
30     print F $xml;
31     close F;
32 }
33 print " $n/$n (100%)\n" if $n % 50 != 0;