Scripting help for Time Machine backups.

ncottle
New Contributor III

While doing some digging on how to allow our users to start backing their data up automatically I ran across this thread. [https://www.jamf.com/jamf-nation/discussions/18257/have-time-machine-backup-just-user-folder](link URL) and I think it's (almost) perfect for what I need. The issue is that I need to see if using something along the lines of an osascript with an input dialogue box I can have the users populate the username and password entries and possibly part of the volume name. Well, the real issue is that my script-fu is severely lacking. I have a basic idea of what I want to do but thus far my results have been poor at best. Any help would be much appreciated.

4 REPLIES 4

BOBW
Contributor II

I would use Cocoadialog

with something like this, haven't tested but it should work OK, added a few lines prior to the script from @gshackney

#!/bin/bash

## install cocoadialog into /usr/local/bin

CD="/usr/local/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog"
UN=($($CD standard-inputbox --title "Backup" --string-output --no-cancel --no-newline --informative-text "Enter your username. Then press OK" --value-required --empty-text "Field cannot be left blank." --quiet))

PW=($($CD standard-inputbox --title "Backup" --string-output --no-cancel --no-newline --no-show --informative-text "Enter your Password. Then press OK" --value-required --empty-text "Field cannot be left blank." --quiet))

VL=($($CD standard-inputbox --title "Backup" --string-output --no-cancel --no-newline --informative-text "Name of Share" --value-required --empty-text "Field cannot be left blank." --quiet))


# Set file share path to timemachine afp (edit username and password, ip address and volume/share name)
tmutil setdestination afp://$UN:$PW@$VL

# 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

ncottle
New Contributor III

@BOBW Thanks for the input. I just got around to running some tests with that. I really appreciate the help. I'll let you know how it goes.

oddity-mdm
New Contributor III

Ive tried this script but Im a lil bit confused. Even in the TM plist than in the UI settings of TM I can't find the exclusion.

Im tryring to change my script to an exclusion of iTunes / music folder:

#!/bin/sh
echo "*************************************"
echo "*** TimeMachine wird konfiguriert ***"
echo "*************************************"
echo " "
echo "HINWEIS:"
echo "========"
echo "Bei der Passworteingabe wird nichts angezeigt (keine Sternchen)!"
echo "* TimeMachine wird deaktiviert"
sudo tmutil disable
echo "* TimeMachine wird aktiviert"
sudo tmutil enable
echo "* bestehende Konfiguration wird entfernt"
sudo rm /Library/Preferences/com.apple.TimeMachine.plist
echo "* lokale Backups werden deaktiviert"
sudo tmutil disablelocal


*echo „*Exclusion of music“*
*sudo tmutil addexclusion -p /music
*

echo "* Netzwerkshare wird konfiguriert"
sudo tmutil setdestination afp://TimeMachine:Backup@172.16.10.60/TMBackup
sudo defaults write /Library/Preferences/com.apple.TimeMachine MaxSize 512000
echo "* erstes Backup wird gestartet"
tmutil startbackup

ncottle
New Contributor III

@oddity-mdm Sorry about the late reply. Did you get this up and running? We ended up going a totally different route due some things out of our control. We are using a basic rsync script with an Exclusions.merge file and it is working great.