It may be a good  idea to set a flag on the successfully indexed documents so that, if there is an error when running the script, it's possible to run it again without reindexing documents.