Have Time Machine backup just user folder

GabeShack
Valued Contributor III

Anyone already doing this? We are experimenting with a time machine backup qnap. I'm trying to work out how to tell time machine on each computer to only backup its user folder. Didn't want to re invent the wheel.

Any ideas?

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools
1 ACCEPTED SOLUTION

GabeShack
Valued Contributor III

So here is how I got it to work for our needs...

#!/bin/bash
# Set file share path to timemachine afp (edit username and password, ip address and volume/share name)
tmutil setdestination afp://username:password@ipaddress/volumename

# Exclude all System folders
tmutil addexclusion -p /Applications
tmutil addexclusion -p /Library
tmutil addexclusion -p /System

# Exclude any other users on the computer (Edit for your specifics)
tmutil addexclusion -p /Users/localadmin
tmutil addexclusion -p /Users/Shared
tmutil addexclusion -p /Users/template
tmutil addexclusion -p /Users/teacher
tmutil addexclusion -p /Users/student

# Exclude hidden root os folders
tmutil addexclusion -p /bin
tmutil addexclusion -p /cores
tmutil addexclusion -p /etc
tmutil addexclusion -p /Network
tmutil addexclusion -p /private
tmutil addexclusion -p /sbin
tmutil addexclusion -p /tmp
tmutil addexclusion -p /usr
tmutil addexclusion -p /var

# Enable timemachine to start auto backing up
tmutil enable

exit 0

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

View solution in original post

14 REPLIES 14

thoule
Valued Contributor II

In TimeMachine system prefs you can click Options and 'add' items to be excluded. You can edit/view that command line (defaults read /Library/Preferences/com.apple.TimeMachine.plist). So you'd have to exclude most everything else.

GabeShack
Valued Contributor III

Its really too bad they don't have an "inclusion" list. Yes, I saw that, but I think I'd have to script a way to add exclusions to anything other than that specific user. Especially if the computer has multiple user accounts. Makes it hard I think.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

thoule
Valued Contributor II

Well, time machine is really just rsync with lots of wrappers. You could write an rsync to do as you want, but that may be recreating the wheel depending on what you want with versioning and stuff.

GabeShack
Valued Contributor III

So here is how I got it to work for our needs...

#!/bin/bash
# Set file share path to timemachine afp (edit username and password, ip address and volume/share name)
tmutil setdestination afp://username:password@ipaddress/volumename

# Exclude all System folders
tmutil addexclusion -p /Applications
tmutil addexclusion -p /Library
tmutil addexclusion -p /System

# Exclude any other users on the computer (Edit for your specifics)
tmutil addexclusion -p /Users/localadmin
tmutil addexclusion -p /Users/Shared
tmutil addexclusion -p /Users/template
tmutil addexclusion -p /Users/teacher
tmutil addexclusion -p /Users/student

# Exclude hidden root os folders
tmutil addexclusion -p /bin
tmutil addexclusion -p /cores
tmutil addexclusion -p /etc
tmutil addexclusion -p /Network
tmutil addexclusion -p /private
tmutil addexclusion -p /sbin
tmutil addexclusion -p /tmp
tmutil addexclusion -p /usr
tmutil addexclusion -p /var

# Enable timemachine to start auto backing up
tmutil enable

exit 0

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

mm2270
Legendary Contributor III

@gshackney Why all the sudos throughout the script? You should probably remove those from the final script if its being run by a policy. They aren't needed.

GabeShack
Valued Contributor III

Mostly because I copied and pasted from terminal to make sure it was all working 1st ; ) Edited the post.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

mpermann
Valued Contributor II

@gshackney won't Time Machine continue to backup all the hidden folders in the root level of the hard drive? I've never tried what you are suggesting but I was just curious what is in your Time Machine backup after you've tested. You'll have to do an

ls -l

to see the invisible stuff on the root level of the hard drive.

GabeShack
Valued Contributor III

Good call, and you were correct. Added the hidden folders to the exclusions list.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

mpermann
Valued Contributor II

@gshackney you mind updating your script above? It would save me some typing when I "borrow" it to play with it. :-)

Edit: I guess you were in the process. Thanks.

GabeShack
Valued Contributor III

One thing I'd like to change about this is setting the computer to use the AD user credentials to login to the TimeMachine backup qnap. So I'll have to grab this code from another script to pass the username and password from AD to the script.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

Xopher
New Contributor III

@gshackney Hi, were you able to get this to work? If so can you post the script with setting the computer to use the AD user credentials to login to the TimeMachine backup qnap? Thanks!

GabeShack
Valued Contributor III

You know, I never did finish this. But as we start backing up more users data I may need to revisit this script. Let me look at this sometime this week and see if I can get it to work.

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

philipwoods
New Contributor III

Anyone ever figure out if Time Machine can be used to backup and restore network users on a Mac with forced local home directories.

We work with lots of schools who have to use things like Carbon Copy Cloner to backup the /Users folder on each Mac because students can't be relied upon to copy their data to a server.

It's easy enough to get Time Machine to do the backup using the scripts mentioned above (thanks @gshackney):

#!/bin/bash
# Set file share path to timemachine
tmutil setdestination smb://$user:$password@$servername/$sharepoint

# Exclude all System folders
tmutil addexclusion -p /Applications
tmutil addexclusion -p /Library
tmutil addexclusion -p /System

# Exclude any other users on the computer (Edit for your specifics)
tmutil addexclusion -p /Users/localadmin
tmutil addexclusion -p /Users/Shared
tmutil addexclusion -p /Users/template
tmutil addexclusion -p /Users/teacher
tmutil addexclusion -p /Users/student

# Exclude hidden root os folders
tmutil addexclusion -p /bin
tmutil addexclusion -p /cores
tmutil addexclusion -p /etc
tmutil addexclusion -p /Network
tmutil addexclusion -p /sbin
tmutil addexclusion -p /tmp
tmutil addexclusion -p /usr
tmutil addexclusion -p /var
tmutil addexclusion -p /Volumes
tmutil addexclusion -p /vm

# Enable timemachine to start auto backing up
tmutil enable

exit 0

And using that script Time Machine backs up the forced local home directories of network accounts accounts, but when you come to restore the backup network accounts aren't offered as something to restore. Its like the Time Machine assistant recognises that the UID is from a network users and presume that you won't want to restore it.

philipwoods
New Contributor III

Ignore my previous post. I was being dumb.

Time Machine backup won't see network accounts as users unless they're mobile accounts.

Shhhh......... nothing to see here.........