Which is grammatically correct? I can only do so much in this time. Or i can do only so much in this time.

It was only when is by comparision more 'relaxed' writing, more like someone is recounting something to someone. The only way to avoid ambiguity is to say we are getting only that printed and to emphasize that. When it's written, where only is placed can eliminate or create ambiguity. The oxford english dictionary defines but only (which can also occur as only but) as meaning ‘ (a) only, merely; (b) except only’, and comments that its use is now poetical. The question asks for a general answer but gives only one special context. In general, only and but only are not substitutable.

(b) except only’, and comments that its use is now poetical. The question asks for a general answer but gives only one special context. In general, only and but only are not substitutable. *they but only work that way occasionally.