Back

Bash Script to Copy and Index Using the Restful API

  • Created: Oct 03, 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

# Copy and Index Using REST
BASE_URL=DotAjaxDirector/com.dotmarketing.portlets.cmsmaintenance.ajax.IndexAjaxAction
LIVE_HOST=http://localhost
DEV_HOST=http://localhost:8080
CREDENTIALS=u/aaa/p/bbb
NOW=$(date +"%m-%d-%Y")
TEMP_PATH=/temp

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

# Create a new index on the dev server
curl $DEV_HOST/$BASE_URL/$CREDENTIALS/cmd/createIndex/shards/2/live/1/indexName/$NOW
curl $DEV_HOST/$BASE_URL/$CREDENTIALS/cmd/createIndex/shards/2/indexName/$NOW

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

# Activate the new indicies
curl $DEV_HOST/$BASE_URL/$CREDENTIALS/cmd/activateIndex/indexName/live_$NOW
curl $DEV_HOST/$BASE_URL/$CREDENTIALS/cmd/activateIndex/indexName/working_$NOW