Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A simple backup script for the trash can UNIX
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.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[7,193 views]  

A simple backup script for the trash can | 10 comments | Create New Account
Click here to return to the 'A simple backup script for the trash can' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
TrashTimer for the rescue…
Authored by: nick on Sep 05, '06 07:50:24AM
i had the same problem until i started using TrashTimer (http://www.hieper.nl/pages/content/trashtimer.html). this little gem deletes files from trash which are in there for a configurable time. i kond of completely stopped emtpying my trash manually. if i wanna delete HUGE files instantly i use the terminal.

[ Reply to This | # ]
TrashTimer for the rescue…
Authored by: themacnut on Sep 05, '06 04:51:28PM
That's funny, I implemented the same solution using a 3-line trash-emptying Applescript and launchd (cron's replacement in Tiger). I don't empty the trash manually anymore either. Of course I can't remember the last time I put something in the trash that I didn't intend to send there, so the "backup the trash" part of that hint wouldn't apply to me...

---
The MacNut
Owner, ClarisWorks/AppleWorks Email List
http://awlist.macnuthome.com
The Vanguard, my webcomic:
http://thevanguardhome.com

[ Reply to This | # ]

TrashTimer for the rescue…
Authored by: chally on Sep 13, '06 02:10:14PM

Perhaps you can enlighten us as to what those "three lines" were...



[ Reply to This | # ]
TrashTimer for the rescue…
Authored by: themacnut on Sep 14, '06 12:28:56PM

Oh sorry, here it is:

tell application "Finder"
empty trash
end tell

Sometimes Applescripts really are that simple. Sometimes. Anyway, that should be enough to empty the trash, especially if you put it in your "Scripts" menu. You can also schedule it to empty the trash on a regularly scheduled interval, either with cron or launchd.


---
The MacNut
Owner, ClarisWorks/AppleWorks Email List
http://awlist.macnuthome.com
The Vanguard, my webcomic:
http://thevanguardhome.com



[ Reply to This | # ]
A simple backup script for the trash can
Authored by: neuralstatic on Sep 05, '06 11:25:15AM

call we wacky, but to prevent losing important files, i back THEM up instead of the trash. ;)



[ Reply to This | # ]
A simple backup script for the trash can
Authored by: wickidpisa on Sep 05, '06 08:01:44PM

But what happens if you empty the trash backup then realize you need something that was there? Maybe you should backup the trash backup...

Seriously, backing up the trash makes no sense. If you just emptied the trash as infrequently as you now empty your trash backup, it would acomplish the same thing.



[ Reply to This | # ]
A simple backup script for the trash can
Authored by: bothomasen on Sep 06, '06 04:36:43AM

Well, for me it makes good sense. The problem sometimes occour for me when dragging several files from the desktop to the trash can. Without knowing it, I accidentially included an important file when selecting the files.
At some point later, I emptied the trash can... and my important file were gone.

This is unlikly to happen in the future as I now backup ~/.Trash/. :-)



[ Reply to This | # ]
A simple backup script for the trash can
Authored by: chally on Sep 13, '06 02:06:33PM

Perhaps you can enlighten us as to what those "three lines" were.



[ Reply to This | # ]
A simple backup script for the trash can
Authored by: chally on Sep 13, '06 02:09:05PM

The previous was meant to be a response to themacnut's post.



[ Reply to This | # ]
A simple backup script for the trash can
Authored by: chally on Sep 15, '06 03:18:06AM

Okay...that's why I didn't understand...because this doesn't merely empty the trash...it sorts out the OLD trash and tosses that out. I haven't tested it yet, but it's what I want.



[ Reply to This | # ]