This question already has an answer here:
I want to format my system, but I don’t want to lose my updates and installed packages. I also want the same packages on other systems as well.
Backing up should be:
and restoring should be
...If I'm not mistaken.