Apple Configurator - Backup & Restoration

I work a bit with Apple Configurator to provision, supervise and join various Apple devices to mobile device management (MDM) servers. One thing not integrated into Apple Configurator is the ability to backup and restore data easily. The need for this might arise if you have a remote operator who may need to remotely provision devices, or if you’d like to hand off a set configuration to a client. Hopefully, the below bash script makes life a little easier in this regard.

If the directories change, adjust accordingly. This is current as of Apple Configurator 1.5. On a second note, if you’d like to supervise devices which have already been supervised, you will also need to copy the Apple Configurator certificate and key from your keychain. Meraki has created a utility which extracts this here. I have not tested this, but in theory, you should be able to delete the Configurator certificate & key from the remote user’s keychain and have them import yours.

#!/bin/bash
# Apple Configurator Backup & Restoration Script
# Brian Dwyer - Intelligent Digital Services 6/18/14

# IPSW File Location - ~/Library/Containers/com.apple.configurator/Data/Library/Caches/com.apple.configurator/Firmware/

# Configuration Files Location
config_dir="/Users/$USER/Library/Containers/com.apple.configurator/Data/Library/Application Support/com.apple.configurator"
db_dir="/var/db/lockdown"

ConfigName=ConfiguratorFiles_Backup
ConfigDBName=ConfiguratorDB_Backup

function backup() {
  # Backup the Restore Files & Stuff
  if [ -d "$config_dir" ]; then
    echo 'Backing up the Configurator Files...'
    nohup tar zpcvf $ConfigName.tar.gz -C "$config_dir" . >/dev/null 2>&1
    echo 'Done'
  fi

  # Backup the Database
  if [ -d "$db_dir" ]; then
    echo 'Backing up the Configurator Database...'
    nohup tar zpcvf $ConfigDBName.tar.gz -C "$db_dir" . >/dev/null 2>&1
    echo 'Done'
  fi
}


function restore() {
  if [ -e "$ConfigName.tar.gz" ]; then
      # Use -o to make the current user the owner of extracted files
      tar xvpof $ConfigName.tar.gz -C "$config_dir"
  else
    echo "Configurator File Backup does not exist. Make sure $ConfigName.tar.gz exists..."
  fi

  if [ -e "$ConfigDBName.tar.gz" ]; then
    echo "We needs sudo to preserve ownership on the database files at $db_dir"
      sudo tar xvpf $ConfigDBName.tar.gz -C "$db_dir"
  else
    echo "Configurator Database Backup does not exist. Make sure $ConfigDBName.tar.gz exists..."
  fi
}


case "$1" in

   backup)
        backup
        ;;
   restore)
        restore
        ;;
        *)
       echo "Usage:  {backup|restore}"
       echo "Backup: Backs up Configurator data to the current directory"
       echo "Restore: Restores backups in the current directory"
       RETVAL=2
esac
comments powered by Disqus