essandess

Q: 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

Close

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

  • All replies
  • Helpful answers

  • by cpragman,

    cpragman cpragman Apr 3, 2013 7:45 AM in response to essandess
    Level 2 (464 points)
    Servers Enterprise
    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.

  • by essandess,

    essandess essandess Apr 3, 2013 8:04 AM in response to cpragman
    Level 1 (28 points)
    Applications
    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.

  • by essandess,

    essandess essandess Apr 9, 2013 9:29 AM in response to essandess
    Level 1 (28 points)
    Applications
    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/message/20243730#20243730

     

    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

  • by essandess,

    essandess essandess Apr 9, 2013 5:10 PM in response to essandess
    Level 1 (28 points)
    Applications
    Apr 9, 2013 5:10 PM in response to essandess

    And add this command to backup serveradmin settings:

     

    # serveradmin configuration plist

    echo "Generating serveradmin configuration plist..."

    sh -c 'serveradmin -x settings all | bzip2 -c > /private/var/backups/serveradmin.plist.bz2'

  • by DavidRIC,

    DavidRIC DavidRIC Apr 9, 2013 10:13 PM in response to essandess
    Level 1 (0 points)
    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

  • by fkick1,

    fkick1 fkick1 May 6, 2013 10:57 AM in response to essandess
    Level 1 (73 points)
    Servers Enterprise
    May 6, 2013 10:57 AM in response to essandess

    Hi,

     

    I created a preflight.sh file with the code above, but I keep getting the following error:

     

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

     

    I get this both with and without the serveradmin addition.


    Any thoughts?

  • by OoO_Bailey_OoO,

    OoO_Bailey_OoO OoO_Bailey_OoO Jul 31, 2013 11:35 AM in response to essandess
    Level 1 (0 points)
    Jul 31, 2013 11:35 AM in response to essandess

    Hi,

     

    I just discovered your post here. Thanks for detailing your solution.

     

    I'm wondering if there have been any tweaks or updates to the above since you implemented it. Also, why are a lot of the quote/code blocks blank at the Bombich forum?

     

    Thanks!

  • by WU-SLS,

    WU-SLS WU-SLS Sep 6, 2013 5:44 AM in response to essandess
    Level 1 (0 points)
    Sep 6, 2013 5:44 AM in response to essandess

    I too am wondering if there are any new tweaks or updates to this.

  • by schlichter11,

    schlichter11 schlichter11 Oct 4, 2013 10:31 AM in response to WU-SLS
    Level 1 (0 points)
    Oct 4, 2013 10:31 AM in response to WU-SLS

    Me too.

  • by essandess,

    essandess essandess Oct 4, 2013 10:54 AM in response to OoO_Bailey_OoO
    Level 1 (28 points)
    Applications
    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

  • by Put_mind_in_gear,

    Put_mind_in_gear Put_mind_in_gear Nov 15, 2013 3:54 AM in response to essandess
    Level 1 (0 points)
    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!

  • by essandess,

    essandess essandess Nov 15, 2013 2:30 PM in response to Put_mind_in_gear
    Level 1 (28 points)
    Applications
    Nov 15, 2013 2:30 PM in response to Put_mind_in_gear

    Not an expert, but it doesn't look like postgreSQL is running, or listening on localhost. Try these:

     

    sudo serveradmin status postgres

    sudo serveradmin start postgres

     

    sudo serveradmin stop postgres

    sudo settings postgres:listen_addresses = "127.0.0.1,::1"

    sudo serveradmin start postgres

  • by filipv-be,

    filipv-be filipv-be Dec 17, 2013 10:50 AM in response to essandess
    Level 1 (0 points)
    Dec 17, 2013 10:50 AM in response to essandess

    What todo when you restored os-x server with Timemachine?

     

    How can you fix Open Directory?

     

    Kind Regards!

  • by essandess,

    essandess essandess Jan 18, 2014 10:08 AM in response to filipv-be
    Level 1 (28 points)
    Applications
    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.