final code for db-copy