File: safe-ldif.in

package info (click to toggle)
ldap-git-backup 1.0.8-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 452 kB
  • sloc: perl: 753; sh: 501; makefile: 31
file content (89 lines) | stat: -rw-r--r-- 1,688 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl
# vim: set filetype=perl :
use strict;
use warnings;
use 5.010;
use English qw( -no_match_vars );
use Carp;
use autodie;

use Pod::Usage;
use Getopt::Long;

my $ldif_cmd = '/usr/sbin/slapcat';
my $help;
GetOptions(
    'ldif-cmd=s' => \$ldif_cmd,
    'help'       => \$help,
);
pod2usage('-verbose' => 2, '-exit_status' => 0) if $help;

print read_ldif($ldif_cmd);
exit 0;

sub read_ldif {
    my ($ldif_cmd) = @_;

    my $old_entry_count = -2;
    my $new_entry_count = -1;
    my $ldif = '';
    until ($old_entry_count == $new_entry_count) {
        $old_entry_count = $new_entry_count;
        $ldif            = read_ldif_raw($ldif_cmd);
        my @ldifs        = split("\n\n", $ldif);
        $new_entry_count = @ldifs;

    }

    return $ldif;
}

sub read_ldif_raw {
    my ($ldif_cmd) = @_;

    open my $in, '-|', $ldif_cmd;
    my $ldif = do { local $RS ; <$in> };
    close $in;

    return $ldif;
}

__END__
=head1 NAME

safe-ldif - verify and dump an LDIF file for backup

=head1 SYNOPSIS

ldap-git-backup [--ldif-cmd=E<lt>/path/to/ldif-dumpE<gt>]

ldap-git-backup --help

=head1 DESCRIPTION

Runs the command given by C<--ldif-cmd> multiple times and returns the last output
as soon as there are two consecutive invocations giving the same number of LDIF
stanzas.

=head1 OPTIONS

=over 4

=item B<--ldif-cmd E<lt>dump_ldif_commandE<gt>>

Specify a command to create a complete LDIF dump of the LDAP directory suitable
for a backup.  It should contain all entries necessary to restore the LDAP
database.  By default /usr/sbin/slapcat from OpenLDAP is taken.

=item B<--help>

Prints this page.

=back

=head1 AUTHOR

Elmar S. Heeb <elmar@heebs.ch>

=cut