In many organizations, a test system runs alongside the productive i-doit instance, where updates are tested, new configurations are tried out, or training sessions are conducted. To ensure the test system contains realistic data, the production database is regularly synchronized -- typically once a week.
This article describes two approaches: a classic shell script with mysqldump and the method recommended since i-doit v38 using console.php with system:tenant-export / system:tenant-import.
Backup before sync
The synchronization completely overwrites the database on the test system. Make sure no important test data is lost. Only read operations are performed on the production system -- nothing changes there.
This option works with any i-doit version. The script runs on the test server, fetches the databases via mysqldump from the production server, imports them locally, and then synchronizes the files (uploads, documents, images) via rsync.
The database alone is not enough
i-doit stores uploaded files, documents, and object images in the file system -- not in the database. Without file synchronization, all uploads added on production after the last sync will be missing on the test system.
Starting with i-doit version 38, the console commands system:tenant-export and system:tenant-import are available. These export a complete tenant -- database and uploaded files -- as a ZIP package. This is the cleaner method because the database and files are kept consistent together.
#!/bin/bash# i-doit Prod-to-Test tenant sync via console.php# Must be run as root on the production server.# Prerequisite: SSH key auth from the production server to the test server must be set up.set-e
# ====================================================# Configuration -- please adjust# ====================================================PROD_CONSOLE="/var/www/html/console.php"PROD_TEMP="/var/www/html/temp"TEST_USER="root"TEST_HOST="<TEST-SERVER-IP>"TEST_BACKUP_DIR="/var/backup/idoit-transfer"TEST_CONSOLE="/var/www/html/console.php"IDOIT_USER="admin"IDOIT_PASS="admin"TENANT_ID="1"TEST_DB_NAME="idoit_data"TEST_DB_PASS="<TEST-DB-PASSWORD>"# ====================================================echo"--- Step 1: Export on production ---"
rm-f"$PROD_TEMP"/idoit-tenant-export-*.zip
sudo-uwww-dataphp"$PROD_CONSOLE"system:tenant-export\--user"$IDOIT_USER"--password"$IDOIT_PASS"--tenantId"$TENANT_ID"EXPORT_FILE=$(ls-t"$PROD_TEMP"/idoit-tenant-export-*.zip2>/dev/null|head-1)if[-z"$EXPORT_FILE"];thenecho"ERROR: Export file not found!"exit1fiFILENAME=$(basename"$EXPORT_FILE")echo"--- Step 2: Transfer to $TEST_HOST ---"
ssh"$TEST_USER@$TEST_HOST""mkdir -p $TEST_BACKUP_DIR"
scp"$EXPORT_FILE""$TEST_USER@$TEST_HOST:$TEST_BACKUP_DIR/$FILENAME"echo"--- Step 3: Import on $TEST_HOST ---"
ssh"$TEST_USER@$TEST_HOST"\"sudo -u www-data php $TEST_CONSOLE system:tenant-import \ --file $TEST_BACKUP_DIR/$FILENAME \ --tenant-database-name $TEST_DB_NAME \ --tenant-title 'Test System' \ --with-system-settings \ --with-tenant-settings \ --db-root-user root \ --db-root-pass '$TEST_DB_PASS' \ --db-host localhost \ && rm -f $TEST_BACKUP_DIR/$FILENAME"echo"--- Step 4: Clean up on production ---"
rm-f"$EXPORT_FILE"echo"DONE! The test system was successfully updated."