Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save passionweb-manuel-schnabel/1855e408ca6b891f615388a20cb11068 to your computer and use it in GitHub Desktop.
Save passionweb-manuel-schnabel/1855e408ca6b891f615388a20cb11068 to your computer and use it in GitHub Desktop.
Synchronization of fileadmin and database between staging and live system (for different TYPO3 versions)
#! /bin/bash
# this file synchronizes database and fileadmin from a TYPO3 v11 system to a TYPO3 v12 system
# example based on a Mittwald project (TYPO3 legacy)
# /home/www/p123456/html/typo3-v12/ is the root path of the v12 system
# /home/www/p123456/html/typo3/ is the root path of the v11 system
# please this file in the root path of the v12 system (you can of course place the file in a subdirectory and adjust the paths accordingly)
# adjust path to this file on Mittwald server
# change "p123456" to your project number
# change "typo3-v12" to your project root path
cd /home/www/p123456/html/typo3-v12
# get database credentials from LocalConfiguration.php of TYPO3 v11 system
db_user="$(php -r '$db = include("/home/www/p123456/html/typo3/typo3conf/LocalConfiguration.php"); print $db["DB"]["Connections"]["Default"]["user"];')"
db_password="$(php -r '$db = include("/home/www/p123456/html/typo3/typo3conf/LocalConfiguration.php"); print $db["DB"]["Connections"]["Default"]["password"];')"
db_hostname="$(php -r '$db = include("/home/www/p123456/html/typo3/typo3conf/LocalConfiguration.php"); print $db["DB"]["Connections"]["Default"]["host"];')"
db_name="$(php -r '$db = include("/home/www/p123456/html/typo3/typo3conf/LocalConfiguration.php"); print $db["DB"]["Connections"]["Default"]["dbname"];')"
# create database dump
mysqldump -u"$db_user" -p"$db_password" -h"$db_hostname" $db_name --no-tablespaces> db-dump.sql
# get database credentials from settings.php of TYPO3 v12 system
db_user_v12="$(php -r '$db = include("/home/www/p123456/html/typo3-v12/typo3conf/system/settings.php"); print $db["DB"]["Connections"]["Default"]["user"];')"
db_password_v12="$(php -r '$db = include("/home/www/p123456/html/typo3-v12/typo3conf/system/settings.php"); print $db["DB"]["Connections"]["Default"]["password"];')"
db_hostname_v12="$(php -r '$db = include("/home/www/p123456/html/typo3-v12/typo3conf/system/settings.php"); print $db["DB"]["Connections"]["Default"]["host"];')"
db_name_v12="$(php -r '$db = include("/home/www/p123456/html/typo3-v12/typo3conf/system/settings.php"); print $db["DB"]["Connections"]["Default"]["dbname"];')"
# import database dump
mysql -u"$db_user_v12" -p"$db_password_v12" -h"$db_hostname_v12" $db_name_v12 < db-dump.sql
# synchronize fileadmin with rsync
printf "${GREEN}\nSyncing files from TYPO3 v11 system...${NC}\n"
rsync -hrPt --exclude='_processed_/*' --exclude='_temp_/*' --exclude='user_upload/_temp_/*' /home/www/p123456/html/typo3/fileadmin/ ./fileadmin/
printf "${GREEN}Files synchronization finished.${NC}\n\n"
# OPTIONAL: add specific database queries here that should be executed before ./typo3/sysext/core/bin/typo3 database:updateschema
# migrate database to v12
printf "\n prepare database...\n"
php ./typo3/sysext/core/bin/typo3 database:updateschema "*.add"
printf "\n truncate sys_log table...\n"
echo 'TRUNCATE `sys_log`;' | php ./typo3/sysext/core/bin/typo3 database:import
# OPTIONAL: add specific database queries here that should be executed after ./typo3/sysext/core/bin/typo3 database:updateschema
printf "\n run referenceindex update...\n"
php ./typo3/sysext/core/bin/typo3 referenceindex:update
# find necessary database upgrade wizards with php ./typo3/sysext/core/bin/typo3 upgrade:list
printf "\n run database upgrade wizards...\n"
php ./typo3/sysext/core/bin/typo3 upgrade:run backendGroupsExplicitAllowDenyMigration
php ./typo3/sysext/core/bin/typo3 upgrade:run backendModulePermission
# add more upgrade wizards here
printf "\n update database schema...\n"
# you can of course add additional options here, e.g. "*.prefix,*.drop"
php ./typo3/sysext/core/bin/typo3 database:updateschema
printf "\n flush and warmup caches...\n"
php ./typo3/sysext/core/bin/typo3 cache:flush
php ./typo3/sysext/core/bin/typo3 cache:warmup
printf "\n\nDon't forget to check database compares in the Install Tool.\n"
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment