Automated Archiving of OD and Exploring serveradmin
You can archive OD from Server Admin, but how do you do this from a script?I asked myself the same question. It's not that pretty, but it's not too hard to get working. This is also a decent walk through how to bend Server Admin to your will!
The first line of thought I had on this was to use the slapconfig -backupdb command. This works great, but it's interactive. So I'd either have to learn expect or move on to something else. By far though slapconfig -backupdb is the easiest way to do this interactively from the CLI, so if you need an immediate backup, and your on the box, use it.
So putting on my thinking toque and with an assist from Mr. Bartosh I figured this one out.
Before getting too far into this, you have to know how Server Admin is even telling the serveradmin facilities on the remote server how to do this. Usually this would involve a lot of mucking about in the servermgrd files and using strings to find out what commands the cgi's support.
Bah!
With a tiny bit of guess work you can actually open up a debug menu in Server Admin. This will give you a log of all the info that's being sent to the server and what's coming back.
Woot!
To enable this just run a quick defaults command to put the right key into the Server Admin plist.
defaults write com.apple.serveradmin UseDebugMenu YES
Then run Server Admin again and actually issue the archive command. You'll see in the transaction window a big blob of xml with lots of commands and stuff in it.
[2005-06-22 16:28:31 -0400] #2 https://odm:311/
commands/servermgr_dirserv
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST
1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>backupArchiveParams</key>
<dict>
<key>archivePassword</key>
<string>test</string>
<key>archivePath</key>
<string>/usr/local/backup/archive1</string>
</dict>
<key>command</key>
<string>backupArchive</string>
</dict>
</plist>
Ick! What are you going to do with this?If you've ever used serveradmin you probably don't have a clue how to enter this into the command. Server Admin talks in XML whereas serveradmin doesn't. What's an admin to do?
Read the man page for serveradmin and you get a glimpse that you can actually send serveradmin interactive commands to do more than one thing at a time.
serveradmin command
will give you a subshell that you can tap out your commands. Read the manpage on the syntax but you'll see it ends up being something like this:
dirserv:backupArchiveParams:archivePassword = test dirserv:backupArchiveParams:archivePath = /usr/local/backup/archive1 dirserv:command = backupArchive
Will give you the same output, that is if you remember to finish it with control-D.
So now that you are this close, let me mention that you can actually feed serveradmin those commands from a text file by doing this:
serveradmin command < yourfileAnd you're off to the races. So to make this into a real system you'll need a shell script that gets the current date, or some other incremental variable, and builds the archive path with that. Then writes the three commands out to a text file and calls serveradmin to read in that file and do the dirty work. Run that script from cron or launchd and you're home from the office early on Fridays.
I'll post a sample script up here in a bit. Until then consider this a homework exercise in scripting. Feel free to post what works for you in the comments.
