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.
Comments :
No comments »
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!
# 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!
Categories : Linux Luvin'
Trackbacks : No Trackbacks »

Trackbacks
No Trackbacks