Backup Open Directory Script

I recently needed to backup our OD server to make sure in case of a disaster we could recover the accounts used to access our separate web server.  I found in Apple’s Open Directory Administration Manual steps you need to take to backup the OD files and databases.  Below is my backup shell script.

#!/bin/sh

# From Apple OD Administration Manual

# To back up an Open Directory master, you need to backup

# its shared LDAP directory domain, its configuration files,

# and its Open Directory Password Server database.

# Check for root privs

if [ $(whoami) != “root” ]

then

echo “You need to be root to do this.”

exit 0;

fi

#Set some variables

SLAPCAT=$(which slapcat)

CP=$(which cp)

MKPASSDB=$(which mkpassdb)

# Save the complete contents of the LDAP directory

# as a raw LDIF dump in a text file named backup.ldif

# The file contains all user records, group records,

# computer records and so on. It does NOT contain passwords.

$SLAPCAT -l /Path/to/backups/backup.ldif

# Make a copy of the /etc/openldap folder. This folder

# contains files that determine the setup of the LDAP directory

# domain, including schema files.

$CP -rp /etc/openldap/ /Path/to/backups/

# If your LDAP server uses SSL, make a copy of the server

# certificate file, LDAP server’s private key file, and the CA

# certificate file.

#$CP file_location file_destination

# Make a copy of the OD Password backup folder, located at

#

# CAREFULLY SAFEGUARD THE OD PASSWORD SERVER BACKUP FOLDER!

# IT CONTAINS PASSWORDS OF ALL USERS WHO HAVE AN OD PASSWORD

# BOTH THE SHARED LDAP DIRECTORY DOMAIN AND THE LOCAL NETINFO

# DIRECTORY DOMAIN. Keep the backup media as secure as the

# OD master server.

$MKPASSDB -backupdb /Path/to/backups/mkpassdb/

# Optionally, make a copy of the Library/Preferences/Directory/Service folder

# Files in this folder specify the server’s search policies and specify

# how the server access other directory domains.

# Optionally make a copy of /etc/hostconfig file

Advertisements

2 Comments

  1. I have a basic question that is along the lines of this post. Now, this is to simply back up Open Directory information, what if I needed to move the information from one partition to the next. Im helping out in a Mac lab and we’re all having trouble trying to find a way to move the Open Directory information from one partition that is not working correctly to a new partition. Would I have to make the backup first and then copy it to an external source or would does open directory have all the entries saved in the preferences folder and I can just copy it from there? Any help would be appreciated. Thanks.

  2. From the top of the post where it is commented out, in order to backup an OD master, you need to backup its shared LDAP directory domain, its configuration files and its OD password server. The script basically just does that much. I have not tested restoring from backup or haven’t needed to move an OD master to a new server. Sorry I couldn’t be of more help.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s