2005-02-25

Automatically back up your LDAP database

Here's the script I use to automatically back up the LDAP database on 10.3 Server. If you stick it into /etc/periodic/daily, the system cron jobs will run it automatically for you when they do the other system maintenance jobs. Don't forget to chmod +x it once you're done editing the script.

You can download the script from here.


#! /bin/bash
#
# Usage: put this into /etc/periodic/daily as something like 800.backup_LDAP
# and the stock Apple cron jobs will run it automatically every day.
#
# Copyright 2004 J. P. Block
#
# This is released under the BSD license, but please send me any
# modifications so I can update the released version.

source /sw/bin/init.sh

# how many days we keep backups for
DAYLIMIT=30

STAMP=`date +%Y-%m-%d-%H%M%S`
DESTDIR=/usr/local/backups/OSXServerDirectoryService

# ensure the destination exists
mkdir -p $DESTDIR

tar cvf $DESTDIR/DirectoryService_$STAMP.tar /Library/Preferences/DirectoryService
gzip -9v $DESTDIR/DirectoryService_$STAMP.tar
chmod 400 $DESTDIR/DirectoryService_$STAMP.tar.gz

# backup LDAP
/usr/sbin/slapcat -l $DESTDIR/slapcat_$STAMP.ldif -f /etc/openldap/slapd.conf
gzip -9v $DESTDIR/slapcat_$STAMP.ldif

# Backup password server
mkdir -p $DESTDIR/mkpassdb
mkpassdb -backupdb $DESTDIR/mkpassdb
tar cvf $DESTDIR/passdb_$STAMP.tar $DESTDIR/mkpassdb
gzip -9v $DESTDIR/passdb_$STAMP.tar
rm -fr $DESTDIR/mkpassdb

find $DESTDIR -mtime +$DAYLIMIT -exec rm '{}' ';'

No comments:

Creative Commons License

This work is licensed under a Creative Commons License.
Copyright 2007-2010, Joseph P. Block, Some Rights Reserved.

Creative Commons Logo