Backup / Restore a profile in OS X

gpalau
New Contributor II

I am currently trying to figure out how to script a process, to create a backup of a user profile and restore it to a new system… The design of the application is as follows:

The Backup portion of the script allows:

  1. Identify the computer name and create a folder on our NAS under //NAS/Public/Backup/computername
  2. ``` hdiutil create smb://MyNAS/Public/computername/{backupusername}.dmg -volname "{username}" -srcfolder /Users/username’
    So for example on the Backup FileSet script I will have as launch arguments, the username of the profile I want to backup, that way the script will know what to backup and will place it on the  //NAS/Public/Backup/computernameenm.dmg for example

The restore script will then:

  1. the launch arguments will have the computer name, and the username, so it will know to go to //NAS/Public/Backup/ and find the computer name in question, and the bend.dmg to extract
  2. for restoring the profile will be done with this line: ``` sudo asr restore -source smb://NAS/Public/Backup/computername/benm.dmg —target /Users/ -noprompt -noverify -erase
  3. will inject the command: ``` /System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount -n$(ls -l /dev/console | awk '{ print $3 }') S ``` to enable the mobile account into the profile so the user can log in.

Do you guys have another suggestion how I can approach this? any links you can provide to examples would be great.

1 REPLY 1

davidacland
Honored Contributor II
Honored Contributor II

To save a bit of time, I'd recommend taking a look at the scripts included with DeployStudio. They have a home folder backup / restore workflow step with a script behind it. You can dig into the package to take a look at the script.

I don't have any examples to hand I'm afraid but when we've done this in the past the script steps have typically been:

  1. Rsync the specified data to the networkdrive, logging any failures
  2. Rsync back to the new Mac, logging any failures
  3. Reset home folder ownership with chown -R username

The rsync syntax would be something like:

rsync -uhzrlv --progress "/Users/username" "/Volumes/server/share/"" 2>> /Volumes/server/share/${USER}syncerrors