#!/usr/bin/perl -w # # simple_jes_directory_backup.pl # October 25, 2006 # Morgan Jones (morgan@morganjones.org) use strict; my $serverroot = "/var/opt/mps/serverroot/slapd-instance"; my $db2ldif = $serverroot . "/db2ldif"; my $backup_path = $serverroot . "/ldif"; my $search_out = `ldapsearch -b "" -s base objectclass=\*`; die "$backup_path does not exist, exiting.." if (! -d $backup_path); print "beginning directory backup..\n"; for (split /\n/, $search_out) { chomp; next unless (my ($context) = /namingContexts:\s+(.*)$/); print "context: /$context/\n"; my $date = `date +%y%m%d.%H:%M.%S`; chomp $date; # normalize the context for the filename my $context_filename = $context; $context_filename =~ s/[^a-zA-Z0-9._]+/_/g; print "\n$db2ldif -s $context -a " . $serverroot . "/ldif/" . $context_filename . "_" . $date . ".ldif\n"; system "\n$db2ldif -s $context -a " . $serverroot . "/ldif/" . $context_filename . "_" . $date . ".ldif\n"; if ($? >> 8 != 0) { print "failed to back up context $context: $!\n";; next; } } print "done.\n";