Commit | Line | Data |
d1dfc40d |
1 | #!/usr/bin/env perl |
2 | |
3 | use lib 'lib'; |
4 | use feature 'say'; |
5 | use strict; |
6 | use warnings; |
7 | use JSON; |
8 | use Text::Tradition::Directory; |
9 | |
10 | binmode STDOUT, ':utf8'; |
11 | binmode STDERR, ':utf8'; |
12 | eval { no warnings; binmode $DB::OUT, ':utf8'; $DB::deep = 1000 }; |
13 | |
14 | my %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 | |
25 | if( -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 | } |
39 | unless( $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 | |
44 | my $dirargs = {}; |
45 | $dirargs->{user} = $VARS{DBUSER} if $VARS{DBUSER}; |
46 | $dirargs->{password} = $VARS{DBPASS} if $VARS{DBPASS}; |
47 | my $dir = Text::Tradition::Directory->new( |
48 | 'dsn' => $VARS{DSN}, 'extra_args' => $dirargs ); |
49 | |
50 | my $scope = $dir->new_scope(); |
51 | my $dumpfile = $VARS{TMPDIR}.'/idpbackup.json'; |
52 | open( IDPBACKUP, ">$dumpfile" ) |
53 | or die "Could not open dump file $dumpfile for writing"; |
54 | binmode IDPBACKUP, ':utf8'; |
55 | $dir->scan( sub { |
56 | say IDPBACKUP JSON->new->allow_blessed->convert_blessed->encode( @_ ); |
57 | }); |
58 | close IDPBACKUP; |