Can't you take care of locking with one line?

flock -n ~/s3sync_by_date.lockfile || exit 1

(instead of lines 10, 13, and 16)