Clone the system to another server

Hello, What is the best practise to clone the system to a second server?

I have a TEST-server to test the latest updates and to make larger changes to the system, i´m to afraid to do in production directly.
I have a copy of the web-directory and dump the database, and on the second server restored the database and web.
Usually I only dumped the database from PROD and restored it in TEST when they have the same version.
But lager changes lately in PROD, (extra entities and more options in lists), does not show correctly in TEST. For example product status, we have made one more status in PROD, but it now shows as its ID in TEST.

Anyone have a working routine for this type of work?

I recommend you to write bash script for it.
Bash scriot should do:

  1. Delete test project files. Example: rm -rf /var/www/test.pim
  2. Create dump. Example: mysqldump -h localhost -u ${SOURCE_DB_USER} --port=3306 -p${SOURCE_DB_PASS} ${SOURCE_DB} > db_dump.sql
  3. Copy files via rsync. Example: rsync -av --exclude=‘upload’ --exclude=‘db-dump’ --exclude=‘dump’ ‘/var/www/prod.pim/’ ‘/var/www/test.pim/’
  4. Import dump. Example: mysql -h localhost -u ${TEST_DB_USER} --port=3306 -p${TEST_DB_PASS} ${TEST_DB} < db_dump.sql
  5. Change config.php for test environment.
    $config->set(‘database’, [
    ‘driver’ => ‘pdo_mysql’,
    ‘host’ => ‘localhost’,
    ‘port’ => ‘’,
    ‘dbname’ => $argv[1],
    ‘user’ => $argv[2],
    ‘password’ => $argv[3]
    ]);
    $config->set(‘appId’, $argv[5]);
    $config->set(‘siteUrl’, ‘https://’ . $argv[4]);
    $config->set(‘smtpServer’, ‘’);
    $config->set(‘assignmentEmailNotifications’, false);
    $config->set(‘mentionEmailNotifications’, false);
    $config->set(‘streamEmailNotifications’, false);
    $config->save();