Skip to content
Permalink
Browse files
AMBARI-23945. Infra Solr Migration - add --keep-backup to automation …
…script + use elapsed time as well
  • Loading branch information
oleewere committed Jun 25, 2018
1 parent 9ec08c0 commit 30afdcc6f80f1defdf24cfd0016c056b870c6d39
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
@@ -704,7 +704,7 @@ For doing a backup + cleanup, then later migrate + restore, use the following co
/usr/lib/ambari-infra-solr-client/ambariSolrMigration.sh --ini-file $CONFIG_INI_LOCATION --mode backup
/usr/lib/ambari-infra-solr-client/ambariSolrMigration.sh --ini-file $CONFIG_INI_LOCATION --mode delete --skip-solr-client-upgrade
# go ahead with HDP upgrade or anything else, then if you have resource / time:
/usr/lib/ambari-infra-solr-client/ambariSolrMigration.sh --ini-file $CONFIG_INI_LOCATION --mode migrate-restore
/usr/lib/ambari-infra-solr-client/ambariSolrMigration.sh --ini-file $CONFIG_INI_LOCATION --mode migrate-restore # you can use --keep-backup option, it will keep the backup data, it's more safe but you need enough pace for that
```

Or you can execute these commands together (if you won't go with HDP upgrade after backup):
@@ -1020,6 +1020,7 @@ Usage: /usr/lib/ambari-infra-solr-client/ambariSolrMigration.sh --mode <MODE> --
-w, --wait-between-steps <seconds> wait between different migration steps in seconds (default: 15)
-p, --python-path python location, default: /usr/bin/python
-b, --batch-interval seconds between batch tasks for rolling restart solr at last step (default: 60)
-k, --keep-backup keep backup data (more secure, useful if you have enough space for that)
--skip-solr-client-upgrade skip ambari-infra-solr-client package upgrades
--skip-solr-server-upgrade skip ambari-infra-solr package upgrades
--skip-logsearch-upgrade skip ambari-logsearch-portal and ambari-logsearch-logfeeder package upgrades
@@ -1774,6 +1774,8 @@ def check_docs(options, accessor, parser, config):
config = ConfigParser.RawConfigParser()
config.read(options.ini_file)

command_start_time = time.time()

service_filter=options.service_filter.upper().split(',') if options.service_filter is not None else ['LOGSEARCH', 'ATLAS', 'RANGER']

if options.action is None:
@@ -1887,5 +1889,9 @@ def check_docs(options, accessor, parser, config):
' upgrade-logfeeders | stop-logsearch | restart-solr |' \
' restart-logsearch | restart-ranger | restart-atlas)'
sys.exit(1)

command_elapsed_time = time.time() - command_start_time
time_to_print = time.strftime("%H:%M:%S", time.gmtime(command_elapsed_time))
print 30 * "-"
print "Command elapsed time: {0}".format(time_to_print)
print 30 * "-"
print "Migration helper command {0}FINISHED{1}".format(colors.OKGREEN, colors.ENDC)
@@ -24,6 +24,7 @@ function print_help() {
-w, --wait-between-steps <seconds> wait between different migration steps in seconds (default: 15)
-p, --python-path python location, default: /usr/bin/python
-b, --batch-interval seconds between batch tasks for rolling restart solr at last step (default: 60)
-k, --keep-backup keep backup data (more secure, useful if you have enough space for that)
--skip-solr-client-upgrade skip ambari-infra-solr-client package upgrades
--skip-solr-server-upgrade skip ambari-infra-solr package upgrades
--skip-logsearch-upgrade skip ambari-logsearch-portal and ambari-logsearch-logfeeder package upgrades
@@ -35,8 +36,13 @@ EOF
function handle_result() {
local result_code=${1:?"usage: <last_command_result>"}
local step=${2:?"usage: <step_context"}
local python_location=${3:?"usage: <python_location>"}
local start_date=${4:?"usage: <date>"}
if [[ "$result_code" != "0" ]] ; then
echo "$step command failed. Stop migration commands ..."
end_date=$(date +%s)
runtime=$($python_location -c "print '%02u:%02u:%02u' % ((${end_date} - ${start_date})/3600, ((${end_date} - ${start_date})/60)%60, (${end_date} - ${start_date})%60)")
echo "Total Runtime: $runtime"
echo "$step command FAILED. Stop migration commands ..."
exit 1
fi
}
@@ -63,7 +69,8 @@ function run_migrate_commands() {
local skip_logsearch_upgrade=${8:?"usage <true|false>"}
local skip_warnings=${9:?"usage <true|false>"}
local batch_interval=${10:?"usage <seconds>"}
local verbose=${11:?"usage <true|false>"}
local keep_backup=${11:?"usage <true|false>"}
local verbose=${12:?"usage <true|false>"}

local verbose_val=""
if [[ "$verbose" == "true" ]]; then
@@ -75,97 +82,108 @@ function run_migrate_commands() {
skip_warnings_val="--skip-warnings"
fi

local keep_backup_val=""
if [[ "$verbose" == "true" ]]; then
keep_backup_val="--keep-backup"
fi

start_date=$(date +%s)

# execute on: backup - all
if [[ "$mode" == "backup" || "$mode" == "all" ]] ; then
log_command "$python_location $script_location --ini-file $ini_file --action check-shards $verbose_val $skip_warnings_val"
$python_location $script_location --ini-file $ini_file --action check-shards $verbose_val $skip_warnings_val
handle_result "$?" "Check Shards"
handle_result "$?" "Check Shards" "$python_location" "$start_date"
fi

# execute on: backup - delete - all
if [[ "$mode" != "migrate-restore" ]] ; then
if [[ "$skip_solr_client_upgrade" != "true" ]]; then
log_command "$python_location $script_location --ini-file $ini_file --action upgrade-solr-clients $verbose_val"
$python_location $script_location --ini-file $ini_file --action upgrade-solr-clients $verbose_val
handle_result "$?" "Upgrade Solr Clients"
handle_result "$?" "Upgrade Solr Clients" "$python_location" "$start_date"
fi
log_command "$python_location $script_location --ini-file $ini_file --action check-docs $verbose_val"
$python_location $script_location --ini-file $ini_file --action check-docs $verbose_val
handle_result "$?" "Check Documents"
handle_result "$?" "Check Documents" "$python_location" "$start_date"
fi

# ececute on: backup - all
if [[ "$mode" == "backup" || "$mode" == "all" ]] ; then
log_command "$python_location $script_location --ini-file $ini_file --action backup $verbose_val"
$python_location $script_location --ini-file $ini_file --action backup $verbose_val
handle_result "$?" "Backup"
handle_result "$?" "Backup" "$python_location" "$start_date"
fi

# execute on: delete - all
if [[ "$mode" == "delete" || "$mode" == "all" ]] ; then
log_command "$python_location $script_location --ini-file $ini_file --action delete-collections $verbose_val"
$python_location $script_location --ini-file $ini_file --action delete-collections $verbose_val
handle_result "$?" "Delete collections"
handle_result "$?" "Delete collections" "$python_location" "$start_date"
fi

# execute on: delete - all
if [[ "$mode" == "delete" || "$mode" == "all" ]] ; then
if [[ "$skip_solr_server_upgrade" != "true" ]]; then
log_command "$python_location $script_location --ini-file $ini_file --action upgrade-solr-instances $verbose_val"
$python_location $script_location --ini-file $ini_file --action upgrade-solr-instances $verbose_val
handle_result "$?" "Upgrade Solr Instances"
handle_result "$?" "Upgrade Solr Instances" "$python_location" "$start_date"
fi
fi

# execute on: delete - all
if [[ "$mode" == "delete" || "$mode" == "all" ]] ; then
log_command "$python_location $script_location --ini-file $ini_file --action restart-solr $verbose_val"
$python_location $script_location --ini-file $ini_file --action restart-solr $verbose_val
handle_result "$?" "Restart Solr Instances"
handle_result "$?" "Restart Solr Instances" "$python_location" "$start_date"
wait $time_sleep

log_command "$python_location $script_location --ini-file $ini_file --action restart-ranger $verbose_val"
$python_location $script_location --ini-file $ini_file --action restart-ranger $verbose_val
handle_result "$?" "Restart Ranger Admins"
handle_result "$?" "Restart Ranger Admins" "$python_location" "$start_date"
wait $time_sleep
if [[ "$skip_logsearch_upgrade" != "true" ]]; then
log_command "$python_location $script_location --ini-file $ini_file --action upgrade-logsearch-portal $verbose_val"
$python_location $script_location --ini-file $ini_file --action upgrade-logsearch-portal $verbose_val
handle_result "$?" "Upgrade Log Search Portal"
handle_result "$?" "Upgrade Log Search Portal" "$python_location" "$start_date"

log_command "$python_location $script_location --ini-file $ini_file --action upgrade-logfeeders $verbose_val"
$python_location $script_location --ini-file $ini_file --action upgrade-logfeeders $verbose_val
handle_result "$?" "Upgrade Log Feeders"
handle_result "$?" "Upgrade Log Feeders" "$python_location" "$start_date"
fi
log_command "$python_location $script_location --ini-file $ini_file --action restart-logsearch $verbose_val"
$python_location $script_location --ini-file $ini_file --action restart-logsearch $verbose_val
handle_result "$?" "Restart Log Search"
handle_result "$?" "Restart Log Search" "$python_location" "$start_date"
wait $time_sleep

log_command "$python_location $script_location --ini-file $ini_file --action restart-atlas $verbose_val"
$python_location $script_location --ini-file $ini_file --action restart-atlas $verbose_val
handle_result "$?" "Restart Atlas Servers"
handle_result "$?" "Restart Atlas Servers" "$python_location" "$start_date"
wait $time_sleep
fi

# execute on migrate-restore - all
if [[ "$mode" == "migrate-restore" || "$mode" == "all" ]] ; then
log_command "$python_location $script_location --ini-file $ini_file --action check-docs $verbose_val"
$python_location $script_location --ini-file $ini_file --action check-docs $verbose_val
handle_result "$?" "Check Documents"
handle_result "$?" "Check Documents" "$python_location" "$start_date"

log_command "$python_location $script_location --ini-file $ini_file --action migrate $verbose_val"
$python_location $script_location --ini-file $ini_file --action migrate $verbose_val
handle_result "$?" "Migrate Index"
handle_result "$?" "Migrate Index" "$python_location" "$start_date"

log_command "$python_location $script_location --ini-file $ini_file --action restore $verbose_val"
log_command "$python_location $script_location --ini-file $ini_file --action restore $keep_backup_val $verbose_val"
$python_location $script_location --ini-file $ini_file --action restore $verbose_val
handle_result "$?" "Restore"
handle_result "$?" "Restore" "$python_location" "$start_date"

log_command "$python_location $script_location --ini-file $ini_file --action rolling-restart-solr $verbose_val --batch-interval $batch_interval"
$python_location $script_location --ini-file $ini_file --action rolling-restart-solr $verbose_val --batch-interval $batch_interval
handle_result "$?" "Rolling Restart Solr"
handle_result "$?" "Rolling Restart Solr" "$python_location" "$start_date"
fi

end_date=$(date +%s)
runtime=$($python_location -c "print '%02u:%02u:%02u' % ((${end_date} - ${start_date})/3600, ((${end_date} - ${start_date})/60)%60, (${end_date} - ${start_date})%60)")
echo "Total Runtime: $runtime"
}

function main() {
@@ -197,6 +215,10 @@ function main() {
local BATCH_INTERVAL="$2"
shift 2
;;
-k|--keep-backup)
local KEEP_BACKUP="true"
shift 1
;;
--skip-solr-client-upgrade)
local SKIP_SOLR_CLIENT_UPGRADE="true"
shift 1
@@ -265,6 +287,10 @@ function main() {
SKIP_LOGSEARCH_UPGRADE="false"
fi

if [[ -z "$KEEP_BACKUP" ]] ; then
KEEP_BACKUP="false"
fi

if [[ -z "$INI_FILE" ]] ; then
echo "ini-file argument is required (-i or --ini-file)."
print_help
@@ -277,7 +303,7 @@ function main() {
exit 1
else
if [[ "$MODE" == "delete" || "$MODE" == "backup" || "$MODE" == "migrate-restore" || "$MODE" == "all" ]]; then
run_migrate_commands "$MODE" "$SCRIPT_LOCATION" "$PYTHON_PATH_FOR_MIGRATION" "$INI_FILE" "$WAIT" "$SKIP_SOLR_CLIENT_UPGRADE" "$SKIP_SOLR_SERVER_UPGRADE" "$SKIP_LOGSEARCH_UPGRADE" "$SKIP_WARNINGS" "$BATCH_INTERVAL" "$VERBOSE"
run_migrate_commands "$MODE" "$SCRIPT_LOCATION" "$PYTHON_PATH_FOR_MIGRATION" "$INI_FILE" "$WAIT" "$SKIP_SOLR_CLIENT_UPGRADE" "$SKIP_SOLR_SERVER_UPGRADE" "$SKIP_LOGSEARCH_UPGRADE" "$SKIP_WARNINGS" "$BATCH_INTERVAL" "$KEEP_BACKUP" "$VERBOSE"
else
echo "mode '$MODE' is not supported"
print_help

0 comments on commit 30afdcc

Please sign in to comment.