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

Last change on this file since 1563 was 1563, checked in by nanardon, 8 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
Line 
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
18    la-sync [options]
19    la-sync --from source --to dest -o type [-a|obj1 obj2]
20
21=cut
22
23GetOptions(
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,
29    'nodelete'     => \my $nodelete,
30    'test'         => \my $test,
31    'o|object=s'   => \my $otype,
32    's|syncname=s' => \my $syncname,
33    'b|batch'      => \my $batch,
34    'unexp'        => \my $unexp,
35    'a|all'        => \my $all
36) or pod2usage();
37
38=head1 OPTIONS
39
40=over 4
41
42=item -c|--config configdir
43
44Use this configuration directory instead of the default one.
45
46=item --from basename
47
48Specify source base to use
49
50=item --to basename
51
52Specify destination base to use, this option can be used
53severals times
54
55=item --nocreate
56
57Don't create object, synchronize existing
58
59=item --test
60
61Don't change anything, just test
62
63=item -s|--syncname name
64
65Use synchronisation named C<name> in configuration instead default
66
67=item -o|object object_type
68
69Query will be performed on this object. Default is the 'User' object.
70
71=item -b|--batch
72
73Don't really perform any synchronisation but try to call daemon process
74to perform immediate synchronisation.
75
76=item --unexp
77
78Sync unexported objects in source base
79
80=back
81
82=cut
83
84my $LA = LATMOS::Accounts->new($config, noacl => 1);
85
86if ($batch) {
87    warn "Using la-sync -b is deprecated, use la-sync-ctl -s instead\n";
88    exit ($LA->call_batch_sync ? 0 : 1);
89}
90
91my $sync = $LA->create_synchro(
92    $syncname,
93    from => $from,
94    to => (@to ? [ @to ] : undef),
95    test     => $test,
96    unexported => $unexp,
97) or die "cannot create sync object\n";
98$sync->load_dest and return;
99if ($otype) {
100    my @list = $all
101        ? $sync->from->list_objects($otype)
102        : @ARGV;
103
104    foreach (@list) {
105        warn "Try to sync $otype: $_\n";
106        $sync->sync_object($otype, $_, onepass => 1) or do {
107            warn "Error while synching $_ ($otype)\n";
108            exit 1;
109        }
110    }
111} else {
112    $sync->process(
113        test     => $test,
114        nodelete => $nodelete,
115        nocreate => $nocreate,
116    ) or warn "Sync has failed\n";
117}
118
119exit 0;
Note: See TracBrowser for help on using the repository browser.