Stretch and Exercise. You should stretch daily and exercise your back muscles regularly to keep your body functioning optimally. This works for the great majority of people with back pain. Anti-inflammatories are helpful too so consider taking fish oil supplements over the counter in that they have anti-inflammatory action. As always, see your doctor before taking any supplement, etc.
Core strength. The long-term fix, as long as there are no significant problems with the back, to back spasms is a strong core. In addition to strengthening your core, use good form when lifting objects and doing exercise. Add volume and intensity of exercise with common sense. If you have concerns that you have a problem with your back, such as a herniated disc or a degenerative spine, see your doctor.