[41] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts; |
---|
| 6 | use LATMOS::Accounts::Synchro; |
---|
| 7 | use Getopt::Long; |
---|
| 8 | use Pod::Usage; |
---|
| 9 | |
---|
| 10 | =head1 NAME |
---|
| 11 | |
---|
| 12 | la-sync - Tools to synchronize base |
---|
| 13 | |
---|
| 14 | =head1 SYNOPSIS |
---|
| 15 | |
---|
| 16 | Show configured bases: |
---|
| 17 | |
---|
[73] | 18 | la-sync [sync name] [options] |
---|
[41] | 19 | |
---|
| 20 | =cut |
---|
| 21 | |
---|
| 22 | GetOptions( |
---|
[132] | 23 | 'c|config=s' => \my $config, |
---|
| 24 | 'help' => sub { pod2usage(0) }, |
---|
| 25 | 'from=s' => \my $from, |
---|
| 26 | 'to=s' => \my @to, |
---|
| 27 | 'nocreate' => \my $nocreate, |
---|
| 28 | 'test' => \my $test, |
---|
| 29 | 'o|object=s' => \my $otype, |
---|
| 30 | 's|syncname=s' => \my $syncname, |
---|
[578] | 31 | 'b|batch' => \my $batch, |
---|
[41] | 32 | ) or pod2usage(); |
---|
| 33 | |
---|
| 34 | =head1 OPTIONS |
---|
| 35 | |
---|
| 36 | =item -c|--config configfile |
---|
| 37 | |
---|
| 38 | Use this configuration file instead default |
---|
| 39 | |
---|
| 40 | =item --from basename |
---|
| 41 | |
---|
| 42 | Specify souce base to use |
---|
| 43 | |
---|
| 44 | =item --to basename |
---|
| 45 | |
---|
| 46 | Specify destination base to use, this option can be used |
---|
| 47 | severals times |
---|
| 48 | |
---|
[578] | 49 | =item -b|--batch |
---|
| 50 | |
---|
| 51 | Don't really perform any synchronisation but try to call daemon process |
---|
| 52 | to perform immediate synchronisation. |
---|
| 53 | |
---|
[41] | 54 | =cut |
---|
| 55 | |
---|
[457] | 56 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
[41] | 57 | |
---|
[578] | 58 | if ($batch) { |
---|
| 59 | exit ($LA->call_batch_sync ? 0 : 1); |
---|
| 60 | } |
---|
| 61 | |
---|
[73] | 62 | my $sync = $LA->create_synchro( |
---|
[132] | 63 | $syncname, |
---|
[73] | 64 | from => $from, |
---|
| 65 | to => (@to ? [ @to ] : undef), |
---|
[66] | 66 | nocreate => $nocreate, |
---|
| 67 | test => $test, |
---|
[73] | 68 | ) or die "cannot create sync object\n"; |
---|
| 69 | $sync->load_dest and return; |
---|
[83] | 70 | if ($otype) { |
---|
| 71 | foreach (@ARGV) { |
---|
| 72 | warn "Try to sync $otype: $_\n"; |
---|
[197] | 73 | $sync->sync_object($otype, $_) or do { |
---|
| 74 | warn "Error while synching $_ ($otype)\n"; |
---|
| 75 | exit 1; |
---|
| 76 | } |
---|
[83] | 77 | } |
---|
| 78 | } else { |
---|
| 79 | $sync->process() or warn "Sync has failed\n"; |
---|
| 80 | } |
---|
[197] | 81 | |
---|
| 82 | exit 0; |
---|