Linux Shell script that migrates FTP & DB from DEMO to LIVE
Budget: €30 – €250 EUR
We are losing time with the manual work of moving demo environments to live environments, we need to have this optimized in an automated way.
FYI : the websites are based on WordPress CMS (FTP files + DB)
There should be a settings file named example1.settings which consists of following variables:
- DemoFTPURL (example ftp.demosite.be)
- DemoFTPUsername (example demoftpuser)
- DemoFTPPassword (example GryD641!h)
- DemoHTTPUrl (example blablabla.be)
- DemoDBHost (example mysql.demosite.be)
- DemoDBName (example mydemodb)
- DemoDBUsername (example demodbuser)
- DemoDBPassword (example demodbpass)
- LiveFTPURL (example ftp.livesite.be)
- LiveFTPUsername (example liveftpuser)
- LiveFTPPassword (example liveftppassword)
- LiveDBHost (example mysql.livesite.be)
- LiveDBName (example mylivedb)
- LiveDBUsername (example livebduser)
- LiveDBPassword (example livedbpass)
- STRING1DEMO (example /data/sites/web/xxxx/subsites/yyyy)
- STRING1LIVE (example /data/sites/web/yyyy/www)
- STRING2DEMO (example blabla.blablabla.com)
- STRING2LIVE (example demosite.be)
Bear in mind that passwords might include special characters.
The script should be bash (linux) based and working on Debian-based systems.
The script should be called in the following format and should be able to run in a screen (linux command) so that it is possible to run parallel jobs:
./migrate.sh --settings=example1 (which automatically searches for example1.settings) and imports the variables to be used)
1. Connect to DemoFTPURL, browse to DEMOPATH and download all files (including hidden) & directories to a local directory named as DemoHTTPUrl (DEMOPATH should be constructed by looking at the STRING1DEMO, and only taking the part after the "xxxx/" so in this case that would be subsites/yyyy)
2. Go into the DemoHTTPUrl directory, open wp-config.php and change the DB_NAME, DB_USER, DB_PASSWORD, DB_HOST fields to be the ones of the LiveDB-credentials
3. Use linux app named mysqldump to connect to DEMO-dbhost/dbname/dbuser&pass in order to export the .sql (example : mysqldump -h DemoDBHost -u DemoDBUser -pDemoDBPass DemoDBName --no-tablespaces > DemoDBName.sql)
4. In the DemoDBName.sql, replace STRING1DEMO with STRING1LIVE, replace STRING2DEMO with STRING2LIVE)
5. Use linux app named mysql to connect to LIVE-dbhost/dbname/dbuser&pass in order to import the .sql (example : mysql -h LiveDBHost -u LiveDBUser -pLiveDBPass LiveDBame < DemoDBName.sql
6. Connect to FTP of LiveFTPURL, browse to /www, and upload all files (including hidden) & directories from FTPURL
On every step of the way it should show the progress in the bash shell and log it in a seperate file named DEMOHTTPUrl)
You can definitely do suggestions if you have a better set-up for this, but above should be the basis.
FYI : the websites are based on WordPress CMS (FTP files + DB)
There should be a settings file named example1.settings which consists of following variables:
- DemoFTPURL (example ftp.demosite.be)
- DemoFTPUsername (example demoftpuser)
- DemoFTPPassword (example GryD641!h)
- DemoHTTPUrl (example blablabla.be)
- DemoDBHost (example mysql.demosite.be)
- DemoDBName (example mydemodb)
- DemoDBUsername (example demodbuser)
- DemoDBPassword (example demodbpass)
- LiveFTPURL (example ftp.livesite.be)
- LiveFTPUsername (example liveftpuser)
- LiveFTPPassword (example liveftppassword)
- LiveDBHost (example mysql.livesite.be)
- LiveDBName (example mylivedb)
- LiveDBUsername (example livebduser)
- LiveDBPassword (example livedbpass)
- STRING1DEMO (example /data/sites/web/xxxx/subsites/yyyy)
- STRING1LIVE (example /data/sites/web/yyyy/www)
- STRING2DEMO (example blabla.blablabla.com)
- STRING2LIVE (example demosite.be)
Bear in mind that passwords might include special characters.
The script should be bash (linux) based and working on Debian-based systems.
The script should be called in the following format and should be able to run in a screen (linux command) so that it is possible to run parallel jobs:
./migrate.sh --settings=example1 (which automatically searches for example1.settings) and imports the variables to be used)
1. Connect to DemoFTPURL, browse to DEMOPATH and download all files (including hidden) & directories to a local directory named as DemoHTTPUrl (DEMOPATH should be constructed by looking at the STRING1DEMO, and only taking the part after the "xxxx/" so in this case that would be subsites/yyyy)
2. Go into the DemoHTTPUrl directory, open wp-config.php and change the DB_NAME, DB_USER, DB_PASSWORD, DB_HOST fields to be the ones of the LiveDB-credentials
3. Use linux app named mysqldump to connect to DEMO-dbhost/dbname/dbuser&pass in order to export the .sql (example : mysqldump -h DemoDBHost -u DemoDBUser -pDemoDBPass DemoDBName --no-tablespaces > DemoDBName.sql)
4. In the DemoDBName.sql, replace STRING1DEMO with STRING1LIVE, replace STRING2DEMO with STRING2LIVE)
5. Use linux app named mysql to connect to LIVE-dbhost/dbname/dbuser&pass in order to import the .sql (example : mysql -h LiveDBHost -u LiveDBUser -pLiveDBPass LiveDBame < DemoDBName.sql
6. Connect to FTP of LiveFTPURL, browse to /www, and upload all files (including hidden) & directories from FTPURL
On every step of the way it should show the progress in the bash shell and log it in a seperate file named DEMOHTTPUrl)
You can definitely do suggestions if you have a better set-up for this, but above should be the basis.