While you can't fully backup and restore everything if you lose your jailbreak in a software upgrade or restore, AptBackup is a free app available in Cydia that can help alleviate the trouble of getting all your jailbreak apps back where they belong.

As you can see in the video above, the backup and restore process is very easy. To back up, just launch AptBackup. To restore all your apps, you'll need to re-download AptBackup from Cydia. Once you do, all you have to do is press the restore button. This will automate the process by re-downloading all the necessary apps from Cydia to your iOS device. While it can't restore settings, it does take the tedious work out of setting things up every time you upgrade.

AptBackup accomplishes this by saving a text file with the apps you have installed when you click the Backup button. This text file is saved in a location that will be backed up by iTunes. This way the text file will be restored when you restore your iOS device and AptBackup will have a text file that will tell it what to download. It's not perfect, but it's a pretty simple and clever workaround to an annoying problem.