How currval of sequence being preserved during the backup and restore in postgres
If you look at the SQL script generated by pg_dump you will see that it generates a setval() call for each sequence exported. So if you have a sequence test_seq and the last value it generated was 42, you will see this line in the SQL script:

SELECT pg_catalog.setval('public.test_seq', 42, true); 


this makes the sequence return 43, the next time nextval() is called.

See the manual for details on the setval() function.