It's important to differentiate between "Russia's motives" and "Putin's motives".
Putin's motive is to stay in power in the face of a stagnate and dated economy that is largely due to his own failures of leadership. He needs a scapegoat for Russia going backward despite abundant natural resources and a well educated populace.
In retrospect, invading Ukraine appears not to have been in Russia's best interest and it seemed pretty apparent in foresight. It's Putin that needed a war. This is the fundamental downfall of every authoritarian regime ever.