Skip to content

Instantly share code, notes, and snippets.

@froemken
Last active October 28, 2021 10:29
Show Gist options
  • Save froemken/75ea776305089f47c392744add0204c9 to your computer and use it in GitHub Desktop.
Save froemken/75ea776305089f47c392744add0204c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Remote Server
# If you don't use a SSH-Key you have to use format: user[:password]@jweilandXYZ.net
# else domainname is enough
server="jweilandXYZ.net"
rPath="~/typo3cms/dev/"
# Path to project root, not FE root (web)
lPath="/Users/stefan/htdocs/kunden/project/"
# PID of first root page. Needed to create a sys_domain record. In most cases this will be 1
lRootPageUid="1"
# The name of the domain you have configured in MAMP (or whereever). Please add port to this value, if your apache does not run at port 80. F.e. pforzheim:8080
lRootPageDomain="project"
# WebDav. Do not add @web.dav to username
wUser="12345-whatever"
wPass="WebDavSecret"
#Variables for remote MySQL Server
rHostname="127.0.0.3"
rUsername="db123456_XY"
rPassword="mySecret"
rDatabase="db123456_XY"
#Variables for local MySQL Server
lHostname="localhost"
lUsername="myUser"
lPassword="mySecret"
lDatabase="project"
#System variables
localSsh="/usr/bin/ssh"
localScp="/usr/bin/scp"
localGunzip="/usr/bin/gunzip"
localRm="/bin/rm"
#For MAMP please use /Applications/MAMP/bin/php/php{version}/bin/php
localPhp="/usr/local/bin/php"
#For MAMP please use /Applications/MAMP/Library/bin/mysql
localMySql="/usr/local/bin/mysql"
EXCLUDED_TABLES=(
be_sessions
cache_imagesizes
cache_md5params
cache_sys_dmail_stat
cache_treelist
cache_typo3temp_log
cf_cache_hash
cf_cache_hash_tags
cf_cache_news_category
cf_cache_news_category_tags
cf_cache_pages
cf_cache_pagesection
cf_cache_pagesection_tags
cf_cache_pages_tags
cf_cache_rootline
cf_cache_rootline_tags
cf_extbase_datamapfactory_datamap
cf_extbase_datamapfactory_datamap_tags
cf_extbase_object
cf_extbase_object_tags
cf_extbase_reflection
cf_extbase_reflection_tags
cf_extbase_typo3dbbackend_queries
cf_extbase_typo3dbbackend_queries_tags
cf_extbase_typo3dbbackend_tablecolumns
cf_extbase_typo3dbbackend_tablecolumns_tags
cf_maps2_cachedhtml
cf_maps2_cachedhtml_tags
cf_tx_solr
cf_tx_solr_tags
cf_workspaces_cache
cf_workspaces_cache_tags
fe_sessions
fe_session_data
sys_dmail
sys_dmail_maillog
sys_history
sys_log
sys_news
sys_preview
sys_refindex
tx_devlog
tx_extensionmanager_domain_model_extension
tx_gbweather_cache
tx_kcemailnotification_emaillog
tx_ptextbase_cache_state
tx_ptextbase_cache_state_tags
tx_realurl_pathdata
tx_realurl_uniqalias
tx_realurl_uniqalias_cache_map
tx_realurl_urldata
tx_rsaauth_keys
tx_solr_cache
tx_solr_cache_tags
tx_solr_indexqueue_file
tx_solr_indexqueue_indexing_property
tx_solr_indexqueue_item
tx_solr_last_searches
tx_solr_statistics
tx_solr_universal_boost_domain_model_boostkeyword
tx_solr_universal_boost_domain_model_boostkeyword
tx_wtspamshield_log
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
IGNORED_TABLES_STRING+=" --ignore-table=${rDatabase}.${TABLE}"
done
echo "Dump MySQL database and zip it."
${localSsh} ${server} "mysqldump -v --opt -u${rUsername} -p'${rPassword}' -h${rHostname} ${rDatabase} ${IGNORED_TABLES_STRING} | gzip -v > ${rDatabase}.sql.gz"
echo ""
echo "Start downloading remote MySQL database"
${localScp} ${server}:~/${rDatabase}.sql.gz ./
echo ""
echo "Remove zip from remote server"
${localSsh} ${server} "rm -f ${rDatabase}.sql.gz"
echo ""
echo "Unzip on local machine and import dump to local MySQL server"
${localGunzip} < ./${rDatabase}.sql.gz | ${localMySql} -u${lUsername} -p${lPassword} -h${lHostname} ${lDatabase}
echo ""
echo "Remove local zip download"
${localRm} -f ./${rDatabase}.sql.gz
echo ""
echo "Synchonize remote PackageState with local TYPO3 environment"
${localScp} ${server}:${rPath}typo3conf/PackageStates.php ${lPath}web/typo3conf/
echo ""
echo "Synchonize remote LocalConfiguration with local TYPO3 environment"
${localScp} ${server}:${rPath}typo3conf/LocalConfiguration.php ${lPath}web/typo3conf/
echo ""
echo "Update DB parameters in LocalConfiguration"
${localPhp} ${lPath}vendor/bin/typo3cms configuration:set DB/Connections/Default/dbname "${lDatabase}"
${localPhp} ${lPath}vendor/bin/typo3cms configuration:set DB/Connections/Default/host "${lHostname}"
${localPhp} ${lPath}vendor/bin/typo3cms configuration:set DB/Connections/Default/password "${lPassword}"
${localPhp} ${lPath}vendor/bin/typo3cms configuration:set DB/Connections/Default/user "${lUsername}"
${localPhp} ${lPath}vendor/bin/typo3cms configuration:set DB/Connections/Default/unix_socket ""
echo ""
echo "Deactivating BE.lockSSL"
${localPhp} ${lPath}vendor/bin/typo3cms configuration:set BE/lockSSL 0
echo ""
echo "Cache has to be clear just before update DB scheme. It's normal that you will see some Exceptions, because of missing tables."
${localPhp} ${lPath}vendor/bin/typo3cms cache:flush
echo ""
echo "Update database schema. This may need some time..."
${localPhp} ${lPath}vendor/bin/typo3cms database:updateschema "*.add,*.change"
echo "INSERT INTO sys_domain (pid, tstamp, crdate, domainName, sorting) VALUES ('${lRootPageUid}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '${lRootPageDomain}', '1');" | ${lPath}vendor/bin/typo3cms database:import
echo ""
echo "Create fileadmin and uploads directory"
mkdir ${lPath}web/fileadmin
mkdir ${lPath}web/uploads
echo ""
echo "un-mount fileadmin"
umount ${lPath}web/fileadmin/
echo ""
echo "Mount fileadmin with Webdav"
echo "User: ${wUser}@web.dav"
echo "Pass: ${wPass}"
mount_webdav -i -s -v vol_name https://${wUser}.webdav.ispgateway.de/webdav/fileadmin/ ${lPath}web/fileadmin/
echo "You can un-mount this directory with: umount ${lPath}web/fileadmin/"
echo ""
echo "un-mount uploads"
umount ${lPath}web/uploads/
echo ""
echo "Mount uploads with Webdav"
echo "User: ${wUser}@web.dav"
echo "Pass: ${wPass}"
mount_webdav -i -s -v vol_name https://${wUser}.webdav.ispgateway.de/webdav/uploads/ ${lPath}web/uploads/
echo "You can un-mount this directory with: umount ${lPath}web/uploads/"
echo ""
echo "Now I clear all caches for you"
${localPhp} ${lPath}vendor/bin/typo3cms cache:flush
echo ""
echo "Juhuu...You are done. Check installation by browsing to: http://${lRootPageDomain}/typo3/index.php"
echo ""
@wowaTYPO3
Copy link

wowaTYPO3 commented Mar 20, 2018

Please attach random string ( f.e. unix timestamp) to remote database dump filename ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment