BackupRestore

Back to Scripts

One of the minor annoyances I've run into during a re-imaging process is the time and trouble it takes to backup and restore user data. Our users store home folders locally on their Macs and use AD accounts to log in. I don't want to get into network homes or syncing homes. We do backup computers over the network via Tivoli storage manager, but thats another topic and we don't backup graduate student machines.

Usually, I have to spend time backing up the home folders and restoring them after imaging the Mac. This relatively easy task slows me down taking up my (precious?) time to do this. Training someone would be fairly simple, but then we'd have to hire someone who can support Macs; thats not an option right now. The manpower I do have available to me have already been trained to use DeployStudio. The great thing about DeployStudio is; I can tell the staff person what workflow to run, I know the workflow will run the correct steps for the task, and I can give access to workflows for specific users as they grow to do more (or remove access if needed). Since DeployStudio does not have a built in option to; ...then we have to do it ourselves! Introducing the DeployStudio BackupRestore* scripts The concept with the scripts are easy... Backup Script: Once the backup task is finished, you can run as many other tasks as you'd like. Image the hard drive, install packages, create users, etc... The last step is to restore the user data. Restore Script: It's important to note that the data is not removed from the backup folder. If you leave the data there, it will be restored on the machine if you run the workflow again. This could lead to unexpected results. For example, if you run the BackupRestore scripts in January you will backup "userA" and "userB". Lets say "userB" leaves in March, you delete their data on the machine, then "userC" starts using the Mac. Then, sometime in May, you run the BackupRestore scripts again The script will overwrite the backups of "userA" and "userB" and, for the first time, backup "userC". When the data is restored, you will restore all three users. This can be avoided by removing the specific users files in the Backups folder. Example: MAC Address: 01:02:03:04:05:06 Users: "userA" and "userB" "userA" is a local user - GeneratedUID="ABC12345" "userB" is a mobile account When the Backup script creates a machine specific folder, it uses the MAC address of the machine without the ":". //Backups/010203040506/ Then the users home folder is backed up, with tar, to the Backups folder using their username, machine MAC address, and the keyword "HOME": userA.010203040506.HOME.tar and userB.010203040506.HOME.tar The account details are backed up to a plist file with the naming convention of: userA.010203040506.USER.plist Then the password hash is backed up as: userA.010203040506.ABC12345 ...the mobile account is skipped because it can be recreated when the user logs back in. That is it for backing up! When the Restore script runs it creates the user account, restores the GeneratedUID (for the local accounts), then restores the home folders on the target for EVERY record in the folder that matches the Macs MAC address. The implementation in DeployStudio is very easy. Simply take the scripts and wrap them around your workflow: **Updated**: The beta 4 edition now allows you to set the variables for some of the parameters. Just enter them into the parameters field. Usage: DS_BACKUP_DATA.sh [ -e "guest admin shared" ] [ -v "/Volumes/Macintosh HD" ] [ -u /Users ] [ -d "/Volumes/External Drive/" ]BackupRestore Variables: -e Users to Skip Must use quotes for multiple users Default is "guest" and "shared" You must specify "guest" and "shared" if your use the argument  -v Target volume Specify full path to mount point of volume Default is the internal volume  -u User path on target Set to path of users on volume Default is /Users-d Backup destination Specify full ath to the backup volume Default is /tmp/DSNetworkRepository
 * backup user data
 * backup user account
 * restore user data
 * Creates a new folder called "Backups" DeployStudio Repository
 * Data is stored in a subfolder using the MAC address as the name (sans ":")
 * User home folder is backed up using tar
 * User account is backed up using plist, password hash is also backed up
 * Network and Mobile accounts (AD/OD) are skipped (if uid is > 1000, skip account)
 * Finds the backup folder based on the MAC address
 * For local accounts; Creates all the accounts & restores password hash
 * Restores the user home folders
 * Does NOT delete backups

Thats it! I'm releasing this code for all, please share, edit, use! Please report bugs and branches back to me at rustymyers@gmail.com. I'd love to hear what your doing! Thanks to Pete Akins and his createUser.pkg from the instaDMG project. It was heavily relied upon for the backing up and creating of users. Seriously, Thank You Pete! Thanks to the ##osx-server channel on the freenode IRC server. Everyone was very helpful in helping me work out the "bugs". - Updated January 28th, 2011 [|Download the scripts!] * Updated Monday December 20, 2010 - Resolved issue with accounts not showing in System Preferences after restore. - Added support for restoring admin rights for network users Notes: *Crappy generic name subject to change without notification
 * These scripts have been tested on 10.6 with local accounts and AD accounts. Machines are bound to AD via Directory Utility, with mobile accounts being created at login.
 * Script chooses the internal drive to the machine, so your hard drive target may be incorrect. You can use the variable option in the script task to set the variable.