Unfortunately, since backpack hardware must stand up to so much wear and tear, there is no simple and effective method to actually repair a plastic buckle. Luckily though, new plastic buckles are widely available and inexpensive. You may even be able to move a buckle from another part of the same backpack.
Match your buckle. The best match, of course, is the same exact type of buckle. If there's a less important, primarily decorative matching buckle somewhere else on the bag, that's probably your best bet. Otherwise, any sturdy buckle of approximately the same size should work. Replacement plastic buckles are available at most fabric and craft stores.
Use a seam ripper to carefully remove the stitches on the strap, near the buckle. Be careful not to cut the strap fabric if possible. When all the stitches are removed, the end of the strap should be able to unfold, freeing the buckle.
Fold the end of the strap through the non-business end of the new buckle and sew the folded strap to itself securely. For a very sturdy attachment, sew almost all the way across the strap, up one edge a little, back across the strap in the other direction, then back down to where you started, forming a rectangle. Then sew an "X" inside the rectangle, connecting the corners. Securely knot the thread at the end of the seam.
Check whether the new buckle piece you've attached fits into the other end of the old buckle. If it does, you're in luck, and finished. If not, you'll need to replace the other piece.
Use the same basic steps to replace the other half of the original buckle with the other half of your replacement buckle, if necessary: remove the stitches from the flap holding the old buckle in place, remove the buckle, fold the strap over the back end of the new buckle (make sure it's facing in the right direction to attach to the other new buckle piece), and sew the folded strap in place using the rectangle and "X" pattern. Securely knot thread when finished.
Since backpack hardware needs to be sturdy, choose a replacement buckle at least as hefty as the original, or the function of the bag may be impaired.