Bash Script to Copy and Index Using the Restful API

  • Created: Oct 04, 2012

Description

I've needed to do this from time to time, either for an upgrade, or to sync up a live system with a development system.  In the script below you would need to change the top portion to match your servers and info.  In the credentials part "aaa" would be your username and "bbb" would be your password.

Link: http://dotcms.com/docs/latest/RESTfulAPItoManageIndexes

Code

BASE_URL=DotAjaxDirector/com.dotmarketing.portlets.cmsmaintenance.ajax.IndexAjaxAction
LIVE_HOST=http://localhost
DEV_HOST=http://localhost:8080
CREDENTIALS=u/aaa/p/bbb
NOW=${esc.dollar}(date +"%m-%d-%Y")
TEMP_PATH=/temp

${esc.hash} Download the current active live and working indices from the live server
curl ${esc.dollar}LIVE_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/downloadIndex/indexName/live > ${esc.dollar}TEMP_PATH/live-index-${esc.dollar}NOW.zip
curl ${esc.dollar}LIVE_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/downloadIndex/indexName/working > ${esc.dollar}TEMP_PATH/working-index-${esc.dollar}NOW.zip

${esc.hash} Create a new index on the dev server
curl ${esc.dollar}DEV_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/createIndex/shards/2/live/1/indexName/${esc.dollar}NOW
curl ${esc.dollar}DEV_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/createIndex/shards/2/indexName/${esc.dollar}NOW

${esc.hash} Restore the live indicies to the newly created dev server indicies
curl -F indexToRestore=live_${esc.dollar}NOW -F clearBeforeRestore=false -F uploadedfiles[]=@${esc.dollar}TEMP_PATH/live-index-${esc.dollar}NOW.zip ${esc.dollar}DEV_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/restoreIndex
curl -F indexToRestore=working_${esc.dollar}NOW -F clearBeforeRestore=false -F uploadedfiles[]=@${esc.dollar}TEMP_PATH/working-index-${esc.dollar}NOW.zip ${esc.dollar}DEV_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/restoreIndex

${esc.hash} Activate the new indicies
curl ${esc.dollar}DEV_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/activateIndex/indexName/live_${esc.dollar}NOW
curl ${esc.dollar}DEV_HOST/${esc.dollar}BASE_URL/${esc.dollar}CREDENTIALS/cmd/activateIndex/indexName/working_${esc.dollar}NOW