Skip to content

Instantly share code, notes, and snippets.

@eapen
Last active June 26, 2018 21:41
Show Gist options
  • Save eapen/323b0ac5f2c9b48ae8cf9c6d0ce68ae6 to your computer and use it in GitHub Desktop.
Save eapen/323b0ac5f2c9b48ae8cf9c6d0ce68ae6 to your computer and use it in GitHub Desktop.
Stop and start CrashPlan / code42 backups on OS X

This script enables you stop and start CrashPlan / Code42 backup on OS X

If you are concerned about exceeding data usage plans if you are tethering etc., you can utilize this script but be aware that your data WILL NOT BE BACKED UP

To launch the UI agent in the menubar, you'll need to open CrashPlan app after you have started the background service (daemon)

Credits: Most of this script is borrowed from Steve Jansen's script to Start/Stop Symantec Endpoint Protection and CrashPlan documentation

Installation

sudo curl https://gist.githubusercontent.com/eapen/323b0ac5f2c9b48ae8cf9c6d0ce68ae6/raw/code42 -o /usr/local/bin/code42
sudo chmod 755 /usr/local/bin/code42
sudo chown root:staff /usr/local/bin/code42

/etc/sudoers

If your user account is not a member of the admin group (i.e., not an OS X Administrator), you need to add the following line to /etc/sudoers using sudo visudo tool:

myusername ALL= NOPASSWD: /usr/local/bin/sep

Example

me:~$ code42 stop
/usr/local/bin/code42: relaunching as sudo /usr/local/bin/code42 stop me
/usr/local/bin/code42: unloading CrashPlanService daemon and UI widget
me:~$ sudo /usr/local/bin/code42 start
/usr/local/bin/code42: relaunching as sudo /usr/local/bin/code42 start me
/usr/local/bin/code42: launching CrashPlanService daemon

Verify Service is not running

me:~$ code42 status

Example

Not Running

me:~$ code42 status
/usr/local/bin/code42: relaunching as sudo /usr/local/bin/code42 status me
/usr/local/bin/code42: checking whether service is running
       off

Running

me:~$ code42 status
/usr/local/bin/code42: relaunching as sudo /usr/local/bin/code42 status me
/usr/local/bin/code42: checking whether service is running
       off
#!/bin/bash
# relaunch with sudo if we aren't root
if [[ $EUID -ne 0 ]]; then
echo "$0: relaunching as sudo $0 $1 $USER"
sudo "$0" $1 $USER
exit $?
fi
real_user=$USER
if [ -n "$2" ]; then
real_user=$2
fi
stop() {
echo $0: unloading CrashPlanService daemon and UI widget
launchctl unload /Library/LaunchDaemons/com.crashplan.engine.plist
}
start() {
echo $0: launching CrashPlanService daemon
launchctl load /Library/LaunchDaemons/com.crashplan.engine.plist
}
status() {
echo $0: checking whether service is running
ps auxww | grep -i crashplanservice | grep -v grep | wc -l | sed 's/1/on/' | sed 's/0/off/'
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo "Usage: $0 [start|stop|status]"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment