Date created: Saturday, June 11, 2011 9:03:35 PM. Last modified: Monday, January 25, 2021 2:10:33 PM
Open Directory and Server Admin Backup
I couldn't find any obvious easy way to have sceduled rolling backups for Open Directory and Server Admin under OS X Server 10.5 so these two scripts which are essentialy one do the job together. I had these running on the first of the month creating an archive of Open Directory and plists of Server Admin settings.
I cron jobbed the saBackup script and have the odBackup script in the same folder so the saBackup script can call it;
saBackup.sh: #!/bin/bash # This backup script will backup all Server Admin services # (even those not in use to save tracking what is and is not being used) # and make the sparse image of the OD Master generated by slapconfig -backupdb echo "Starting at `date +%H:%M:%S`" # Set the backup path to be in a sub folder backupPath="/some_drive/Backups/OpenDirectory/`date +%Y-%m-%d`/" echo "Backing up ServerAdmin to: $backupPath" # Check the backup path exists and set permissions, # If the folder doesnt exist it will be created mkdir -p $backupPath chmod 750 $backupPath # Export each server admin service into the backup directory services=`serveradmin list` for service in $services; do echo "Backing up: $service" result=`serveradmin -x settings $service > $backupPath/$service.plist` if [ $? -ne 0 ]; then echo " ...failed!" echo "$result\n" fi sleep 1 done # call the OD backup script (because of the use of 'expect' as its shell it is its own script) ./odBackup echo "Finished at `date +%H:%M:%S`"
Note: the date is being passed as the password for the OD archive, it must have a password, so its worth changing this! Also, these scripts must be called by root to use 'slapconfig -backupdb'
odBackup.sh: #!/usr/bin/expect -f # We can't parse variables from the SA backup script so the same variables must be redefined here set date [timestamp -format "%Y-%m-%d"] set path "/some_drive/Backups/OpenDirectory/" # Create the OD Master sprase image archive spawn /usr/sbin/slapconfig -backupdb $path$date/odBackup expect "Enter archive password" send "$date\r" expect eof
Previous page: Mac BASH Profile
Next page: Randomise Wi-Fi MAC