Three major points were in help in the situation.
First - every factory was connected to a railway by design. You can check the map here - http://users.tpg.com.au/adslbam9//Railways1941.png to see that there were routes established from western frontlines to the eastern parts of the union.
Second - despite the great losses of military forces, USSR still had enormous quantity of human reserves.
Third - most of the Luftwaffe was appointed to the western front and eastern forces lacked in the possibility of strategic bombing thus were unable to greatly injure soviet infrastructure past the frontlines. Also Germans didn’t really believed that the evacuation would be possible so they restrained from bombing the major factories hoping to use them later. Here are more details - https://www.rand.org/content/dam/rand/pubs/research_memoranda/2006/RM6206.pdf
So let’s take as an example Kharkiv Locomotive Factory (KhPZ) where the t-34 was designed and manufactured. The evacuation started in September 1941 when it become clear that it won’t be possible to hold the front on Dnieper.
By the initial plan there should’ve been 2100 railway wagons with equipment sent from Kharkiv to Nizhny Tagil where on base of Uralvagonzavod factory it was to be redeployed along with the equipment from Mariupol and other cities. But due to lack of time (the evacuation ended in October) and the general war chaos only 1500 wagons reached the destination. Compared to number of workers evacuated (10-20% of them) it was still a huge success. There the factory was rebuilt and started operating. By December 8 1941 25 tanks were built there and by March the production exceeded pre-evacuation numbers.
Every other factory was evacuated in a similar fashion. Some of them had to start production without actual factory buildings available, so the people worked without roofs (Aviaagregat factory, for example). And in general the evacuation didn’t went absolutely well, and lend-lease was a great help to cover the loses.