You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How To Backup and Restore OS X Server (Mountain Lion)

I always use Carbon Copy Cloner and TIme Machine to create independent backups of my OS X Server. Last night, I upgraded my box to new 1 TB drives and used CCC to clone from the original smaller drives. Most steps went great (including CCC's creation of the ML Recovery partition), and the new drive boots fine.


But Open Directory doesn't work—Server.app says "can't locate replica". Googling around <https://discussions.apple.com/thread/4142833>, I see that I simply can't clone the OS X Server drive if it's set up as an OD Master. And I don't see a set of clear instructions for both backing up and restoring an Open Directory Master using Carbon Copy Cloner and, I assume, the serveradmin command.


Does anyone know the commands to fully backup and fully restore OS X Server (Mountain Lion 10.8.3) when it's set up as an OD Master? Or a robust way to automate this process with both Time Machine and Carbon Copy Cloner so that I know I'm making a good backup of my server?

Mac mini Server (Mid 2010), OS X Mountain Lion (10.8.2), Lion Server, EyeTV HD, Turbo.264 HD

Posted on Apr 3, 2013 5:58 AM

Reply
14 replies

Apr 3, 2013 7:45 AM in response to essandess

OD is one of those files that is constantly being written to, so backing up via "normal" methods can leave you with unpleasant results. Mail is another one.

You could try turning off all server services, before creating the image.

Or you could try some of the server backup routines that have been specifically written to deal with this.


http://krypted.com/mac-os-x-server/using-serverbackup-to-backup-lion-servers/


http://techjournal.318.com/scripts/open-directory-auto-archiver/


Personally, I use the second one.

Apr 3, 2013 8:04 AM in response to cpragman

Thanks for the suggestions, but the first link is Lion Server specific and honestly looks very, very complicated and error prone, and the second link and scripts were written in 2009 for Snow Leopard Server.


Is there not a simple, foolproof command for making a solid backup of OS X Server? I thought I was doing with with CCC, and was surprised to find that OD failed. I'm just glad this happened while I'm working with a good live OS X Server drive.


I just got off the line with Enterprise Support and they suggested to boot into the Recovery partition, then use Disk Utility to recover using the original drive as the source and the new drive as the destination. I expect that to work, but I'm hoping not to have to bring down a server every time I want to create a solid bootable backup.

Apr 9, 2013 9:29 AM in response to essandess

Thanks to some help from Mike Bombich and this thread, I've put together a bash script for Open Directory backup (using opendirectorybackup), backup backup (using serveradmin), and PostgreSQL backup (using pg_dumpall). This puts all the db backups in /private/var/backups, and keeps two-week-old sequential OD backups.


To restore OD, follow the instructions at OS X Server: Advanced Administration:


To restore Open Directory data, open the Terminal app (located in the Other folder in Launchpad) and enter the following command:

sudo slapconfig -restoredb /full/path/to/archive.sparseimage

For example, /full/path/to/archive.sparseimage could be /Volumes/Data/myODArchive.sparseimage


Here's the script with details on finer-grain backups in the comments:


ccc_preflight.sh


#!/bin/bash -x

# Carbon Copy Cloner pre-flight script


# OS X Server Backup


# Open Directory backup

# See /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.a pple.opendirectorybackup.plist

/Applications/Server.app/Contents/ServerRoot/usr/libexec/server_backup/opendirec torybackup



# Open Directory backup backup

# See http://help.bombich.com/discussions/questions/31239-how-to-backup-and-restore-os -x-server-mountain-lion

# See https://discussions.apple.com/thread/4142833?answerId=20243730022#20243730022


RECOVER=/private/var/backups/odbackup

TS=`date ''+%F''`

ODBACKUP_PASSWD=odbackuppasswd


# Remove archives older than two weeks

find $RECOVER -mindepth 1 -mtime +14 -exec /bin/rm {} ';'


cat <<SERVERADMIN_ODBACKUP | sudo /Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin command

dirserv:backupArchiveParams:archivePassword = $ODBACKUP_PASSWD

dirserv:backupArchiveParams:archivePath = $RECOVER/od_$TS

dirserv:command = backupArchive

SERVERADMIN_ODBACKUP



# PostgreSQL backups


# Backup all tables

sh -c '/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_dumpall -U _postgres | bzip2 -c > /private/var/backups/postgres.dumpall.bz2'


# List all tables

# /Applications/Server.app/Contents/ServerRoot/usr/bin/psql -q -d postgres _postgres --password -c '\list'


# Backup individual tables

# sh -c '/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_dump -Fc -U _postgres roundcubemail > /private/var/backups/postgresbackup/roundcubemail.dump'


exit 0

Apr 9, 2013 10:13 PM in response to essandess

Hi ..this is a really really dumb question to your helpful reply. So do I cut and paste the script (with the server admin addition) into Text Wrangler and save iot as a plain text file. Then do I add it to Carbon Copy Cloner and then add it to a scheduled backup using the Beforte/After option in CCC? Does it matteer what the file is named and what extenesion I give it please? Failing that, is there any chnace you could email me a ready file which I simply need to add into CCC pleasse. I too had trouble whne trying to restore a bacjup of our mail server using CCC, and would love this added functionality for peace of mind. Thank yiu for yoiur help. Understand if you arew not in a place to actually send a file ...thought it was worth asking at least 🙂


Cheers

David

Oct 4, 2013 10:54 AM in response to OoO_Bailey_OoO

are any new tweaks or updates to this.

No, aside from serveradmin settings backup mentioned above. I've been running this a while now and it's all gone well. Please post any issues.


You have configured CCC to abort your backup task if the preflight scripts ends with a non-zero exit status.

I don't know about that error. I keep a few loose offsite backup drives around and run this script by hand whenever I carry one "home," so I'm not an expert on CCC's auto configuration -- you may wish to ask Mike B.

So do I cut and paste the script (with the server admin addition) into Text Wrangler

Use vi! Half-kidding. Use your favorite ASCII text editor (TextEdit.app, emacs, vim, vi, whatever) to create a bash script file called ~/bin/ccc_preflight.sh . You can cut-and-paste from above, but this forum's line breaks and added spaces can create glitches, so edit those out. Then with the command line,


chmod a+x ~/bin/ccc_preflight.sh

sudo ~/bin/ccc_preflight.sh

Nov 15, 2013 3:54 AM in response to essandess

Hi essandess,


did you manage to get the script running under OS X 10.9 Server? We are getting this error:


2013-11-15 12:20:11.227 serveradmin[3236:507] --Module servermgr_devicemgr's response has retain count of 3.

/var/db/bsdpd_clients: No such file or directory

+ sh -c '/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_dumpall -U _postgres | bzip2 -c > /private/var/backups/postgres.dumpall.bz2'

pg_dumpall: could not connect to database "template1": could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?


Thanks in advance!

Jan 18, 2014 10:08 AM in response to filipv-be

It finally happened: a server crash corrupted my OD Master. Fortunately, restoring from the recent backup just worked. The Terminal command, documented at http://help.apple.com/advancedserveradmin/mac/3.0/#apdD88A9F25-BCA9-4AD8-A317-60 DB8A52353C, is:


sudo slapconfig -restoredb /private/var/backups/odbackup/od_2014-01-18.sparseimage


After that, I had to use Server.app to restart all my authentication-using services, and retell them to use my server's TLS certificate for authentication.

How To Backup and Restore OS X Server (Mountain Lion)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.