Skip to content

Instantly share code, notes, and snippets.

@pjv
Created October 8, 2013 16:42

Revisions

  1. pjv created this gist Oct 8, 2013.
    14 changes: 14 additions & 0 deletions mac.backup.plist
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>mac.backup</string>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>3600</integer>
    <key>Program</key>
    <string>/path/to/tm_backup.sh</string>
    </dict>
    </plist>
    16 changes: 16 additions & 0 deletions tm_backup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/bin/bash

    # This is the name of your backup disk
    BACKUP_DISK="Backup"

    # Mount the disk if it is unmounted
    if ! mount | grep "$BACKUP_DISK" ; then
    diskutil mount "$BACKUP_DISK"
    fi

    # If the drive is successfully mounted, do the backup (nothing will happen if disk is not connected)
    if mount | grep "$BACKUP_DISK" ; then
    # do backup, then unmount backup volume
    tmutil startbackup --auto --block &&
    diskutil eject "$BACKUP_DISK"
    fi