Rsync wrapper to backup/restore users on a host
BACKUP & RESTORE SCRIPTS
Backup or restore all user profiles on a host.
pyrap [-br] [uxv] [-hH] [SHARE/MOUNT]
-b = Backup user profiles from /Users to /mountpoint/Users/user/date.
-r = Restore user profiles from /mountpoint/Users/user/date to /Users.
-u = Process all users without prompting.
-x = Automatically choose sane excludes (Caches, Trash, etc).
-v = Verbose stream. Useful for debugging.
-h = Display this help and exit.
-H = Display more in depth help page with paging.
Takes a share url as an argument, in either standard mount_smbfs form:
Or standard mount_nfs form:
Or standard rsync URL form:
Takes a mountpoint as an argument:
If a share has been entered it will be mounted here, otherwise we backup to this location.
If no share or mountpoint is entered you will be prompted to enter them.
If your share is a valid rsync url, there is no need to enter a mountpoint.
PITFALLS & CAVEATS
THE PATH ON THE REMOTE HOST MUST POINT TO PARENT OF USERS, NOT USERS!
Once mounted the mountpoint should contain the Users directory underneath it.
The script backups to or restores from the following directory layout underneath the mountpoint:
And logs to:
Where CopyType equals either Backup or Restore.
If this layout does not exist it will be created under the mountpoint.
Unless backing up to a samba share, user, group and permissions will be retained and each backup will be hard-linked against the last to save space and mimic the functionality of Time Machine.
When using Samba, in combination with Active Directory, ownership & permissions attributes are mangled, so these are not preserved in this use case, making incremental backups with hard links impossible. This is also the reason it’s necessary to recursively chown the users directory when restoring from a Samba share.
If possible use this script in conjunction with either an NFS or rsync server, or a USB drive.
It's also worth pointing out that for the time being preserving extended attributes is not supported.
To backup from /Users to a Samba share mounted at /Volumes/Backups/Users:
pyrap -b //user:password@hostname/Backups/macOS /Volumes/Backups
To restore from a Samba share mounted at /Volumes/Backups/Users to /Users, choosing sane defaults:
pyrap -rx //user:password@hostname/Backups/macOS /Volumes/Backups
To backup from /Users to a rsync server, without prompting for each user:
pyrap -bu rsync://user@host:port/backups
To restore from /Users to a rsync server, with increased verbosity:
pyrap -rv rsync://user@host:port/backups
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.