With nur one points to the state in which things are; with erst the emphasis lies on the point when things change or the progress in general.
Ich habe nur zwei Kekse übrig. — I only have two biscuits left and their amount is not going to increase.
Ich habe erst zwei Kekse übrig. — I only have two biscuits left but I’m expecting to get more of them.
The second phrase is a bit strange, of course, since the Word übrig denotes that one indeed does not expect any new biscuits.
Sie mag ihre Arbeit nur, wenn es regnet. — She only likes her work when it’s raining.
Sie mag ihre Arbeit erst, wenn es regnet. — Emphasises that it needs to start raining.
Two more examples:
Mozart war nur drei Jahre alt, als er seine ersten Konzerte gab. — Sounds a bit contrived because one expects ageing to be a progress and therefore saying nur is strange. It would work, if he stopped ageing afterwards or if he’d always been three years old. Or if the young age were simply an additional fact but nothing which made it even more important.
Mozart war erst drei Jahre alt, als er seine ersten Konzerte gab. — Emphasises that it was a young age and even though he was still getting older, he did not wait until then.
(Consider Mozart had been shot at the age of three – then one would have to say nur in order to emphasise his young age but using erst would not work since his age does not have any further influence on the fact that he had been shot.)
Nur auf der Zielgeraden konnte er den Läufer einholen. — Emphasises where he could catch the runner: only on the home stretch. (And they might have run 1500 m and so he had the chance a couple of times.)
Erst auf der Zielgeraden konnte er den Läufer einholen. — Emphasises that he tried but could not do it until on the home stretch.
Note that in the last two examples the meaning is somewhat inverted. In the Mozart example erst means that something good happened very early in the process (of aging). In the sports example it means that it happened rather late. (One could reverse both examples with the word schon/‘already’.)
Ich war nur einmal in Berlin. — More of a simple fact. I know it’s a small number (one)
but that’s just how it is.
Ich war erst einmal in Berlin. — More of a personal statement. I know it’s a small number and I might change it, if I could and if I really wanted to do it. (However, it does not say that one wants to get there another time. It is only possible that one does.)