>데이터 베이스 >MySQL 튜토리얼 >Sync live sites to in-house dev servers_MySQL

Sync live sites to in-house dev servers_MySQL

WBOY
WBOY원래의
2016-06-01 13:15:471192검색

One of our customer found it tedious to sync his live websites to his dev servers, it involved using FTP (since he had no version control) as well as the database.
The files were over 2GB by themselves, so it could be a time consuming task. As a result he asked us for a solution, and we were able to provide the following script to help him out.

Put the following into a script (eg sync.sh ), then chmod +x sync.sh

#!/bin/bash # Add your ssh key to the remote server before running this# Where are the local files going to be savedLOCALDIR=~/local/dev/www/ # No trailing / please on this one belowREMOTEDIR=/var/www/vhosts/yourdomain.co.nz/httpdocs # Remote MySQL connection detailsREMOTE_SQL_USER=databaseusernameREMOTE_SQL_PASS=JGOIDBp4553ghREMOTE_SQL_DB=databasename # Local MySQL connection detailsLOCAL_SQL_USER=databaseusernameLOCAL_SQL_PASS=JGOIDBp4553ghLOCAL_SQL_DB=databasename # Remote host IPREMOTE_HOST=49.50.242.111REMOTE_USER=root ssh ${REMOTE_USER}@${REMOTE_HOST} "mysqldump -u${REMOTE_SQL_USER} -p${REMOTE_SQL_PASS} ${REMOTE_SQL_DB} >/tmp/${REMOTE_SQL_DB}.sql" rsync -avP ${REMOTE_USER}@${REMOTE_HOST}:$REMOTEDIR/* ${LOCALDIR} rsync -avP ${REMOTE_USER}@${REMOTE_HOST}:/tmp/${REMOTE_SQL_DB}.sql /tmp/mysql -u${LOCAL_SQL_USER} -p${LOCAL_SQL_PASS} ${LOCAL_SQL_DB} 

Edit the script as needed to reflect the database/files/etc you want, then run ./sync.sh

To make this really seamless, use ssh keys to login. If you want to have this on a cron, make sure you put the full path to the rsync and mysql, or any other binaries used.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.