Have worked in vet med for 15 yrs, but no clue on how to prevent this issue. The only thing I can offer you is tips if you need to do it again: wear gloves and shampoo his rear afterward. If any of that "stuff" gets on your hands or skin, wash with liquid soap with some salt mixed in. It's the only way to get the smell out.
My dog has had trouble with his anal glands (though not recently, thank goodness). Our vet recommended adding bran to his food, which helped. I've never expressed them myself, but my neighbor does this with her pug. Yuck!
Our dog is getting on in years and had some rear end issues in January. The vet/vet techs took care of the glands and told us to get a better quality dog food to bulk up her stools so the natural digestion/elimination process will naturally express the glands. We switched her to Evo and its has all cleared up. Its more expensive, but she seems happier too. She still gets other foods, but we mix them into the dry food so she gets more of the dry food.
A lot of times groomers will do it when they groom your pet. Maybe just add that as a routine thing?
But omg, I can't imagine doing it to our dog myself. He's 120 lbs! Can you imagine?!