« Producing a Stir How Does Change Happen? (Part 2) »

Aug

18

2010

Cleaning the Dropbox Cache

I use Dropbox as a convenient way to keep an online backup of my files as well as sync them between my computer at church and my computer at home. 

Basically, I put my "Documents" folder inside the "Dropbox" folder, and then immediately as soon as I edit a file, it automatically uploads it online, and then synchronizes it with my other computer at home/work. It is a constant backup system. No more emailing files, ever! Pretty cool, eh?

With such constant changes happening, however, the Dropbox cache can get pretty large pretty quickly--a few gigs in a few days. So, rather than deleting it manually, I did what any other nerd normal person might do: I wrote a script to do it for me.

I put it up here in case anybody else wants to use it as well. I find it useful, I hope you will too.

  1. Install cygwin (standard options are fine)
  2. Download my cleanDropboxCache.sh and put it in a permanent location
  3. Open up "Task Scheduler"
  4. Create a new basic task to run daily
  5. Set the "Action" to "Run a Program"
    • Program/script: "c:\cygwin\bin\sh.exe"
    • Add arguments: <insert path to cleanDropboxCache.sh> (ex: "d:\users\matt\bin\cleanDropboxCache.sh")

And you should be good to go! Enjoy. =)

#!/bin/sh

UsersDir="`echo $USERPROFILE | sed -e 's/\\\\/\//g'`/.."

# Look for users
for user in "$UsersDir"/*; do 

 if [ -d "$user" -a "$user" != "$UsersDir" ]; then

  DropboxDir="$user/Application Data/Dropbox/cache"
  
  # Make sure they have a Dropbox Cache to clear
  if [ ! -d "$DropboxDir" ]; then
   continue
  fi

  echo "Found Dropbox Dir: $DropboxDir"
  
  cd "$DropboxDir"
  
  thisMonth=`date +%m`
  thisDate=`date +%d`
  thisYear=`date +%Y`
  
  # Search listing of cache directories to find old ones
  for dir in 20*-*-*; do

   if [ ! -d $dir ]; then
    continue
   fi
   
   year=`echo $dir  | awk -F- '{ print $1 }'`
   month=`echo $dir  | awk -F- '{ print $2 }'`
   date=`echo $dir  | awk -F- '{ print $3 }'`
  
   if [ $year -le $thisYear ]; then
  
    if [ $month -le $thisMonth ]; then
  
     # Deletes directories previous to 'yesterday'
     if [ $date -lt $thisDate ]; then
  
      echo "Deleting $dir"
      rm -fr $dir
  
     fi
    
    fi
   
   fi
  
  done

 fi

done


TrackBack

TrackBack URL:
http://www.typepad.com/services/trackback/6a0105367999a8970b0134864979b9970c

Comments

I reserve the right to remove / abridge comments which are (1) too long (no blog posts please); (2) off topic (again.); or (3) mean-spirited (feel free to disagree, but do so graciously). That is all. Thank you for reading and comment away!

Matt Hauck (郝柏昇)

A once enemy now son, forgiven and freed by Jesus' blood, adopted and called by grace for glory.   (more...)

Related Posts Plugin for WordPress, Blogger...