I've had back spasms for decades. I've gotten them pretty much under control, though it's still present every day. Doctors can give you muscle relaxers but they don't work for me. Physical therapy might help but it's sort of geared towards old people so I don't like it myself. But do use it to learn what not to do.
To imagine what it's like if you don't have muscle spams, make a fist and flex the muscles in your arm over and over until it's tiring. Now imagine you can't stop for 24 hours until you are on the floor in pain and then you still can't stop.
First, use a TENS unit. They are cheap. This is the main way to signal to the muscles to stop. Otherwise, the muscle will go forever. So TENS resets that. Sort of the way a defibrillator might be used to reset a heart back into a proper rhythm.
Next, exercise and build up back muscles. I exercise a lot. I like to find something that is fun and exciting so I continue past tiredness, not something that I'll get bored with. The best was probably boxing because it involves a lot of twisting at your core, but most anything will do. Bikram yoga was the only thing that made it worse because the forward stretching was causing nerve compression. For me, building up back muscles allowed me to hold a better posture and that helps too.
I also use foam roller. That works sometimes before it gets bad. A soft bed and a soft couch seem to make it worse, but the opposite won't make it go away. I try not to sit still too long. Lastly, shoveling show is the worst thing. If you have to do it, do it in teaspoons at a time. In general, don't be macho about carrying things. Carrying one bag of groceries at a time is good for you anyway.
Hopefully some of that is relevant to you or someone else.