 
 exports.migrate = (client, done = ->)->
 	getDocIds (err, ids)->
+		totalDocCount = ids.length
+		alreadyFinishedCount = Object.keys(finished_docs).length
+		t0 = Date.now()
+		printProgress = () ->
+			count = Object.keys(finished_docs).length
+			processedFraction = (count-alreadyFinishedCount)/totalDocCount
+			remainingFraction = (totalDocCount-count)/totalDocCount
+			t = Date.now()
+			dt = (t-t0)*remainingFraction/processedFraction
+			estFinishTime = new Date(t + dt)
+			console.log "completed #{count}/#{totalDocCount} processed=#{processedFraction.toFixed(2)} remaining=#{remainingFraction.toFixed(2)} elapsed=#{(t-t0)/1000} est Finish=#{estFinishTime}"
 		interval = setInterval printProgress, 3*1000
-		jobs = _.map ids, (id)->
+
+		jobs = _.map _.filter(ids, (id) -> not finished_docs[id]), (id)->
 			return (cb)->
 				processNext(id, cb)
 		async.series jobs, (err)->
 			if err?
 				console.error err, "at end of jobs"
 			else
-				console.log "finished"
+				console.log "finished at #{new Date}"
 			clearInterval interval
 			done(err)
 

mongojs = require("mongojs")
ObjectId = mongojs.ObjectId
db = mongojs(Settings.mongo.url, ['docs','docHistory', 'docHistoryStats'])
_ = require("lodash")
async = require("async")
exec = require("child_process").exec
BSON = db.bson.BSON

	log: ->
	err: ->
}

needToExit = false
handleExit = () ->
	needToExit = true
	console.log('Got signal.  Shutting down.')

process.on 'SIGINT', handleExit
process.on 'SIGHUP', handleExit

finished_docs_path = "/tmp/finished-docs-3"
all_docs_path = "/tmp/all-docs-3"
