There is a wiki page for this situation
pacman/Restore local database - ArchWiki
[root tip] [Utililty Script] Backup configuration and package list