Cron LDAP Backup to File and Email

21 07 2006
If you keep up with this site, you'll know that I lost my entire LDAP database once due to server errors from a power outage. I made this script below to counter that. This script must be run as root because the command "slapcat" won't work otherwise (AFAIK). I created a cron job to run this script every night and email me the ldif dump. This is where your unused Gmail account comes into play.


CODE:
#! /bin/bash

# Ameir Abdeldayem
# http://www.ameir.net
# You are free to modify and distribute this code,
# so long as you keep my name and URL in it.

# directory to backup to
BACKDIR=~/backups

# your LDAP server's name
SERVER=abubakr

# date format that is appended to filename
DATE=`date +'%m-%d-%Y'`

# check of the backup directory exists
# if not, create it
if  [ -e $BACKDIR ]
then
 echo Backups directory already exists
else
mkdir $BACKDIR
fi


echo Backing up LDAP entries...

slapcat -l $BACKDIR/$SERVER-ldapbackup-$DATE.ldif

# if you have the mail program 'mutt' installed on
# your server, uncomment this line to have the ldif
# dump emailed to you as an attachment.  You can add
# multiple email addresses at the end of the line to
# send this file to each of them.
echo Your backup is ready | mutt -a $BACKDIR/*$DATE.ldif \
        -s "LDAP backup on $SERVER ($DATE)" email1@server.com \
        email2@server.com

echo Your backup is complete!


Trackbacks


No Trackbacks

Comments

Display comments as (Linear | Threaded)
No comments

Add Comment


You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
BBCode format allowed

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA