From 93db15a01439d48d27eb10550459e3e3b7465415 Mon Sep 17 00:00:00 2001 From: Fred Hamster Date: Mon, 16 Dec 2024 18:41:15 -0500 Subject: [PATCH] super nice approach to doing a bunch of machines uses the host strider, but manages the set pretty well itself and generates the commands it needs to run. ps: the approach where it saves the script file to a temp file? this is how we can do functions too. --- .../fred/scripts/jobby/archie_grabber_uva.sh | 103 ++++++--------- .../fred/scripts/jobby/uva_strider.sh | 121 ++++++++++++++++++ 2 files changed, 159 insertions(+), 65 deletions(-) create mode 100644 scripts/customize/fred/scripts/jobby/uva_strider.sh diff --git a/scripts/customize/fred/scripts/jobby/archie_grabber_uva.sh b/scripts/customize/fred/scripts/jobby/archie_grabber_uva.sh index 3e5c96c6..32bdff83 100644 --- a/scripts/customize/fred/scripts/jobby/archie_grabber_uva.sh +++ b/scripts/customize/fred/scripts/jobby/archie_grabber_uva.sh @@ -1,9 +1,6 @@ #!/usr/bin/env bash -# grabs a set of archives from a set of machines. - -#hmmm: not tuned for re-use very much yet. -# but this idea could be used for our home machines too... given some good parameter management. +# grabs a set of archives from the set of ITS machines. source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh" @@ -13,47 +10,35 @@ if [ -z "$ARCHIVE_DIR_PREFIX" ]; then ARCHIVE_DIR_PREFIX="z_arch" fi -# looks for archive directories within a DNS domain for a set of hosts. -# if any archive dirs are found, they are copied to the local host and -# then moved out of the way on the remote host. -function grab_archies() -{ - local domain_piece="$1"; shift - local host_list="$1"; shift - for host in $host_list; do - mkdir -p ${host}.${domain_piece} - pushd ${host}.${domain_piece} - local cp_outfile="$(mktemp /tmp/archie_grabber.XXXXXX)" - netcp ${host}.${domain_piece}:${ARCHIVE_DIR_PREFIX}* . &> "$cp_outfile" - retval=$? - if [ $retval -ne 0 ]; then - cat "$cp_outfile" - rm "$cp_outfile" - echo "got return value $retval from copying ${ARCHIVE_DIR_PREFIX}* from ${host}.${domain_piece}; skipping it." - popd - continue - fi - rm "$cp_outfile" - - # code below cleans up any archive dirs on the host by hiding them in an - # old junk folder. the junk folder can be cleaned up later as desired. - # the impact is that the archives will only be backed up once, and then - # moved out of the way before the next run. - host_strider $DATA_GRAVE_SHUFFLE_COMMAND ${domain_piece} ${host} - - popd - done -} - ################ -# active part of the script, where we go out to a bunch of machines -# to grab the archive folders. +# go out to a bunch of ITS machines to grab the archive folders. # we'll store the copied archives here. #hmmm: should make that directory selectable... -mkdir -p $HOME/grabbing_archies -pushd $HOME/grabbing_archies +export COPY_TARGET_TOP="$HOME/grabbing_archies" +mkdir -p "$COPY_TARGET_TOP" + +export ARCHIVE_SNAGGER_COMMAND="$(mktemp "$TMP/archive_snagger.sh.XXXXXX")" +echo '\ +#!/usr/bin/env bash +# copies the archives we find in the remote home for the user which start with the expected prefix. +hostname="$1"; shift +ARCHIVE_DIR_PREFIX="'$ARCHIVE_DIR_PREFIX'" +pushd "$COPY_TARGET_TOP" +mkdir -p "${hostname}" +pushd "${hostname}" +cp_outfile="$(mktemp /tmp/archie_grabber_copying.XXXXXX)" +netcp ${hostname}:${ARCHIVE_DIR_PREFIX}* . &> "$cp_outfile" +retval=$? +if [ $retval -ne 0 ]; then + cat "$cp_outfile" +fi +rm "$cp_outfile" +popd +popd +exit $retval +' > $ARCHIVE_SNAGGER_COMMAND # write a script that we'll run remotely to clean up after we get a copy of the archives. export DATA_GRAVE_SHUFFLE_COMMAND="$(mktemp "$TMP/data_engraver.sh.XXXXXX")" @@ -68,36 +53,24 @@ echo "moving old $ARCHIVE_DIR_PREFIX* folders into $DATA_GRAVE" mv $ARCHIVE_DIR_PREFIX* $DATA_GRAVE ' > $DATA_GRAVE_SHUFFLE_COMMAND -################ - -# these hosts are all in the ITS domain... - -domain="its.virginia.edu" -hostlist="idpprod01 idpprod02 idpprod03 idpprod04 idpprod05 " -grab_archies "$domain" "$hostlist" -hostlist="idpdev01 idpdev02 " -grab_archies "$domain" "$hostlist" -hostlist="idptest01 idptest02 " -grab_archies "$domain" "$hostlist" -hostlist="idpsistest01 idpsistest02 " -grab_archies "$domain" "$hostlist" - -hostlist="test-shibboleth-sp02 " -grab_archies "$domain" "$hostlist" - -hostlist="tower " -grab_archies "$domain" "$hostlist" +export LOCAL_CLEANER_COMMAND="$(mktemp "$TMP/post_copy_local_cleaner.sh.XXXXXX")" +echo '\ +#!/usr/bin/env bash +# the last step is to clean up anything for this transfer that we want to dump. +hostname="$1"; shift +ARCHIVE_DIR_PREFIX="'$ARCHIVE_DIR_PREFIX'" +echo "no steps for cleanup yet..." +' > $LOCAL_CLEANER_COMMAND ################ -# these hosts are in the storage domain... - -domain="storage.virginia.edu" -hostlist="admin03 admin-hsz02-s admin-lab nasman02-s " -grab_archies "$domain" "$hostlist" +# do our thing with the uva strider to get any archives... +uva strider "$ARCHIVE_SNAGGER_COMMAND" "$DATA_GRAVE_SHUFFLE_COMMAND" "$LOCAL_CLEANER_COMMAND" ################ -popd +# clean-up for our own script here... +rm "$ARCHIVE_SNAGGER_COMMAND" "$DATA_GRAVE_SHUFFLE_COMMAND" "$LOCAL_CLEANER_COMMAND" +################ diff --git a/scripts/customize/fred/scripts/jobby/uva_strider.sh b/scripts/customize/fred/scripts/jobby/uva_strider.sh new file mode 100644 index 00000000..3b39bfff --- /dev/null +++ b/scripts/customize/fred/scripts/jobby/uva_strider.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash + +# iterates across the set of machines we use in UVa ITS all the time and +# performs a set of actions per host. + +source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh" + +# takes a triplet of script names and runs them on local and remote hosts... +# first the initialization operation is run locally, then the actual remote +# operation is invoked (remotely), then the clean-up operation is run locally. +# the initialization and clean-up operations are expected to take a hostname, +# and they will each be run for each remote host. +function instigate_remote_calls() +{ + local init_op="$1"; shift + local remote_op="$1"; shift + local cleanup_op="$1"; shift + local domain_piece="$1"; shift + local host_list="$1"; shift + # variables used later. + local retval + + for host in $host_list; do + + # first we call our initialization process. + echo "invoking local initialization operation '$init_op'..." + squelch_unless_error bash "$init_op" + retval=$? + if [ $retval -ne 0 ]; then + echo "got return value $retval from initialization script '$init_op' for ${host}.${domain_piece}; skipping it." + continue + fi + + # now we make the remote call by relying on the host strider. + echo "invoking remote action operation '$remote_op'..." + squelch_unless_error host_strider "${remote_op}" "${domain_piece}" "${host}" + retval=$? + if [ $retval -ne 0 ]; then + echo "got return value $retval from remote action script '$remote_op' on ${host}.${domain_piece}; skipping it." + continue + fi + + # then invoke the clean-up call to get things right again on the local host. + echo "invoking local clean-up operation '$cleanup_op'..." + squelch_unless_error bash "$cleanup_op" + retval=$? + if [ $retval -ne 0 ]; then + echo "got return value $retval from clean-up script '$cleanup_op' for ${host}.${domain_piece}; skipping it." + continue + fi + + done +} + +################ + +# active part of the script, where we go out to a bunch of machines to get things done. + +################ + +init_op="$1"; shift +remote_op="$1"; shift +cleanup_op="$1"; shift + +if [ -z "$init_op" -o -z "$remote_op" -o -z "$cleanup_op" ]; then + echo "$0: runs an action on all of our ITS machines. +This script needs three parameters: +1) The initialization script, which will run locally before each host action. +This script must take at least a single parameter, which is the hostname, +although it does not need to do anything with that if it's not useful for +initialization. +2) The actual remote action script, which will run on the remote hosts. +This script needs to be self-contained enough to handle doing its job on the +remote side with a minimum of setup--only what's already configured on the +remote host will be available to the script. +3) The clean-up script, which will run locally after a successful remote +action. This script also needs to accept at least a hostname parameter. +" + exit 1 +fi + +################ + +#while testing, we limit the blast zone... +domain="its.virginia.edu" +hostlist="idpdev01 " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" +echo BAILING +exit 1 + +# these hosts are all in the ITS domain... + +domain="its.virginia.edu" +hostlist="idpprod01 idpprod02 idpprod03 idpprod04 idpprod05 " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" +hostlist="idpdev01 idpdev02 " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" +hostlist="idptest01 idptest02 " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" +hostlist="idpsistest01 idpsistest02 " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" + +hostlist="test-shibboleth-sp02 " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" + +hostlist="tower " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" + +################ + +# these hosts are in the storage domain... + +domain="storage.virginia.edu" +hostlist="admin03 admin-hsz02-s admin-lab nasman02-s " +instigate_remote_calls "$init_op" "$remote_op" "$cleanup_op" "$domain" "$hostlist" + +################ + +popd + + -- 2.34.1