HOW TO MAKE A ROBOT THAT RETREATS TO STARTING POINT AFTER RECORDING THE MOVEMENT

I'm new to arduino , im doing a robot which moves on gestures of my hand..
the assembly and code of the project is done but my idea is that i want to record every movements of the robot travelling path and if i want to retreat it , it must comeback by simply replaying the movements in reverse.
SO PLEASE HELP ME , ANY GOOD ADVICE IS ALL I NEED..
I have UNO , Motors , accelerometer , SD CARD module ..
I want accelerometer data to be dumped in sd card and uno repeats on command

I would save the motor movement commands and durations also, and play those back.
Then, monitor the accelerometer data and see if the motor commands given are resulting in the same data, and if not, adjust the motor commands to make data match.

And then it gets tricky - say there is some motor slip, or a change in gradient so the motor has to work easier or harder to get up to the same acceleration - do you still end up in the same place after the same commanded length of time? Hard to say, yes?