This article is from the Canine Medical Information FAQ, by Cindy Tittle Moore with numerous contributions by others.
(summarized from Carlson & Giffin)
Normally, anal sacs are emptied when the dog defecates. Some dogs with
overactive anal glands may require occasional help. Your vet can
demonstrate the procedure.
A common indication of trouble with anal sacs is "scooting" (dragging
the rear on the ground).
Impaction: occurs when the anal sacs fail to empty properly. This is
more common in smaller breeds. Squeezing the sacs yourself as needed
will control the problem.
Infection: complicates impaction. There is blood or pus in the
secretions, and the dog may scoot (drag its rear on the ground). It
may be painful. Check with your vet for an antibiotic you can apply
after you empty the sacs.
Abscess: Signs of anal infection, with a swelling at the site of the
gland. It goes from initially red to a deep purple. You will have to
have it lanced and cleaned by the vet.
Dogs whose anal sacs become repeatedly infected and/or abscessed will
need to have the glands removed. Surgery is uncomplicated, although
the dog will have poor bowel control for the next few days after
surgery. Try putting a pair of small boy's underpants, with the dog's
tail through the third opening, on the dog to contain accidents.