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

Last change on this file since 1930 was 1930, checked in by nanardon, 7 years ago

Complete doc

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 2.4 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 --nodelete
56
57Don't delete object on destination
58
59=item --nocreate
60
61Don't create object, synchronize existing
62
63=item --test
64
65Don't change anything, just test
66
67=item -s|--syncname name
68
69Use synchronisation named C<name> in configuration instead default
70
71=item -o|object object_type
72
73Query will be performed on this object. Default is the 'User' object.
74
75=item -b|--batch
76
77Don't really perform any synchronisation but try to call daemon process
78to perform immediate synchronisation.
79
80=item --unexp
81
82Sync unexported objects in source base
83
84=back
85
86=cut
87
88my $LA = LATMOS::Accounts->new($config, noacl => 1);
89
90if ($batch) {
91    warn "Using la-sync -b is deprecated, use la-sync-ctl -s instead\n";
92    exit ($LA->call_batch_sync ? 0 : 1);
93}
94
95my $sync = $LA->create_synchro(
96    $syncname,
97    from => $from,
98    to => (@to ? [ @to ] : undef),
99    test     => $test,
100    unexported => $unexp,
101) or die "cannot create sync object\n";
102$sync->load_dest and return;
103if ($otype) {
104    my @list = $all
105        ? $sync->from->list_objects($otype)
106        : @ARGV;
107
108    foreach (@list) {
109        warn "Try to sync $otype: $_\n";
110        $sync->sync_object($otype, $_, onepass => 1) or do {
111            warn "Error while synching $_ ($otype)\n";
112            exit 1;
113        }
114    }
115} else {
116    $sync->process(
117        test     => $test,
118        nodelete => $nodelete,
119        nocreate => $nocreate,
120    ) or warn "Sync has failed\n";
121}
122
123exit 0;
Note: See TracBrowser for help on using the repository browser.