A simple backup script for the trash can

Sep 05, '06 07:30:00AM

Contributed by: bothomasen

By accident I have several times moved some important files from the Desktop to the Trash Can, and then emptied the Trash Can before discovering that the files were missing ... sigh! I decided that I needed some sort of automatic backup mechanism for the Trash Can -- in that way I would have some time to react to such mistakes.

I wrote a very simple bash script to copy files in the trash can to a backup directory:

#!/bin/sh
# trashbackup.sh ; version 1.0
ditto ~/.Trash/ ~/.Trash_backup/
I invoke the script every 10 minutes via /etc/crontab, using this crontab entry: (I am the user bt):

# The periodic and atrun jobs have moved to launchd jobs
# See /System/Library/LaunchDaemons
#
# minute        hour    mday    month   wday    who     command
*/10            *       *       *       *       bt      /Users/bt/app-unix-scripts/trashbackup.sh

I also invoke another small script that empties the .Trash_backup directory once a week. This could be done more often, or executed manually, if you trash a large amount of data. Nothing fancy, but I think it will same me some frustration in the future. Hopefully some of you might find it useful as well.

[robg adds: Note that this script will only handle items on your boot drive. If you have multiple partitions or drives, you'll have to get fancier with the code to backup the contents of the .Trashes folder on each volume.]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20060831022320126