Learn the hard way

Meaning: To learn something through a difficult or unpleasant experience.

Example: I learned the hard way that you should always back up your important files.