You can prevent that from going too far by doing small careful exercise on a regular basis.
You have to find out what works for you and learn to listen closely to your body so you know how much you can do on any given day. but you have to move your body every day at least a bit...however much you can stand...or you will end up not being able to do anything at all. It's also very important for mental health to do some form of exercise.
If you are down for a week after doing exercise you are trying to do too much, which is a very common thing for those of us who used to be very active. Start very small.....so small that you don't even think you have done any exercise at all. And build up so slowly that your body hardly notices it. That's how to do it. It's not easy (for me it took a long time to stop trying to go too fast), but you have to do it for yourself or suffer the consequences of being too sedentary and really losing muscle, which are worse than what you are experiencing now.