Slightly more informative closing message
[scpubgit/stemmatology.git] / analysis / idp_server / idpbackup.pl
CommitLineData
d1dfc40d 1#!/usr/bin/env perl
2
3use lib 'lib';
4use feature 'say';
5use strict;
6use warnings;
7use JSON;
8use Text::Tradition::Directory;
9
10binmode STDOUT, ':utf8';
11binmode STDERR, ':utf8';
12eval { no warnings; binmode $DB::OUT, ':utf8'; $DB::deep = 1000 };
13
14my %VARS = (
15 DBTYPE => 'mysql',
16 DBHOST => '127.0.0.1',
17 DBPORT => '3006',
18 DBNAME => 'idpresult',
19 DSN => undef,
20 DBUSER => undef,
21 DBPASS => undef,
22 TMPDIR => '/var/tmp'
23);
24
25if( -f "/etc/graphcalc.conf" ) {
26 # Read the variables in from here.
27 open( GCCONF, "/etc/graphcalc.conf" )
28 or die "Could not open configuration file /etc/graphcalc.conf";
29 while(<GCCONF>) {
30 chomp;
31 s/^\s+//;
32 my( $name, $val ) = split( /\s*\=\s*/, $_ );
33 if( exists $VARS{$name} ) {
34 $VARS{$name} = $val;
35 }
36 }
37 close GCCONF;
38}
39unless( $VARS{DSN} ) {
40 $VARS{DSN} = sprintf( "dbi:%s:dbname=%s;host=%s;port=%s",
41 $VARS{DBTYPE}, $VARS{DBNAME}, $VARS{DBHOST}, $VARS{DBPORT} );
42}
43
44my $dirargs = {};
45$dirargs->{user} = $VARS{DBUSER} if $VARS{DBUSER};
46$dirargs->{password} = $VARS{DBPASS} if $VARS{DBPASS};
47my $dir = Text::Tradition::Directory->new(
48 'dsn' => $VARS{DSN}, 'extra_args' => $dirargs );
49
50my $scope = $dir->new_scope();
51my $dumpfile = $VARS{TMPDIR}.'/idpbackup.json';
52open( IDPBACKUP, ">$dumpfile" )
53 or die "Could not open dump file $dumpfile for writing";
54binmode IDPBACKUP, ':utf8';
55$dir->scan( sub {
56 say IDPBACKUP JSON->new->allow_blessed->convert_blessed->encode( @_ );
57});
58close IDPBACKUP;