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.
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Backing up should be:
and restoring should be
...If I'm not mistaken.