source: trunk/LATMOS-Accounts/bin/la-sync @ 1888

Last change on this file since 1888 was 1563, checked in by nanardon, 9 years ago

Allow la-sync to synchronize the full set object of specific type

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 2.3 KB
RevLine 
[41]1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use LATMOS::Accounts::Synchro;
7use Getopt::Long;
8use Pod::Usage;
9
10=head1 NAME
11
12    la-sync - Tools to synchronize base
13
14=head1 SYNOPSIS
15
16Show configured bases:
17
[594]18    la-sync [options]
[1563]19    la-sync --from source --to dest -o type [-a|obj1 obj2]
[41]20
21=cut
22
23GetOptions(
[132]24    'c|config=s'   => \my $config,
25    'help'         => sub { pod2usage(0) },
26    'from=s'       => \my $from,
27    'to=s'         => \my @to,
28    'nocreate'     => \my $nocreate,
[861]29    'nodelete'     => \my $nodelete,
[132]30    'test'         => \my $test,
31    'o|object=s'   => \my $otype,
32    's|syncname=s' => \my $syncname,
[861]33    'b|batch'      => \my $batch,
34    'unexp'        => \my $unexp,
[1563]35    'a|all'        => \my $all
[41]36) or pod2usage();
37
38=head1 OPTIONS
39
[985]40=over 4
41
[861]42=item -c|--config configdir
[41]43
[861]44Use this configuration directory instead of the default one.
[41]45
46=item --from basename
47
[594]48Specify source base to use
[41]49
50=item --to basename
51
52Specify destination base to use, this option can be used
53severals times
54
[594]55=item --nocreate
56
[1375]57Don't create object, synchronize existing
[594]58
59=item --test
60
[1375]61Don't change anything, just test
[594]62
63=item -s|--syncname name
64
[1375]65Use synchronisation named C<name> in configuration instead default
[594]66
67=item -o|object object_type
68
69Query will be performed on this object. Default is the 'User' object.
70
[578]71=item -b|--batch
72
73Don't really perform any synchronisation but try to call daemon process
74to perform immediate synchronisation.
75
[861]76=item --unexp
77
78Sync unexported objects in source base
79
[985]80=back
81
[41]82=cut
83
[457]84my $LA = LATMOS::Accounts->new($config, noacl => 1);
[41]85
[578]86if ($batch) {
[1201]87    warn "Using la-sync -b is deprecated, use la-sync-ctl -s instead\n";
[578]88    exit ($LA->call_batch_sync ? 0 : 1);
89}
90
[73]91my $sync = $LA->create_synchro(
[132]92    $syncname,
[73]93    from => $from,
94    to => (@to ? [ @to ] : undef),
[66]95    test     => $test,
[861]96    unexported => $unexp,
[73]97) or die "cannot create sync object\n";
98$sync->load_dest and return;
[83]99if ($otype) {
[1563]100    my @list = $all
101        ? $sync->from->list_objects($otype)
102        : @ARGV;
103
104    foreach (@list) {
[83]105        warn "Try to sync $otype: $_\n";
[777]106        $sync->sync_object($otype, $_, onepass => 1) or do {
[197]107            warn "Error while synching $_ ($otype)\n";
108            exit 1;
109        }
[83]110    }
111} else {
[861]112    $sync->process(
113        test     => $test,
114        nodelete => $nodelete,
115        nocreate => $nocreate,
116    ) or warn "Sync has failed\n";
[83]117}
[197]118
119exit 0;
Note: See TracBrowser for help on using the repository browser.