Pi-hole's long-term query database is stored at /etc/pihole/pihole-FTL.db
.
You could just stop your old Pi-hole process and copy that file over to your new Pi-hole (which has also to be stopped).
Or you could create a clean copy of the existing database to a new file with the following command:
pihole-FTL sqlite3 /etc/pihole/pihole-FTL.db "VACUUM INTO '/path/to/pihole-FTL.backup.db'"
Replace /path/to/
with an existing location as required (e.g. with a network mount).
This results in a potentially smaller file than the direct copy, and it can be executed while your old Pi-hole is running.
You'd then copy that pihole-FTL.backup.db
to /etc/pihole/pihole-FTL.db
in your new Pi-hole's installation. The new Pi-hole should be stopped for the copy/move, and only be restarted once that has completed.