DepotObject Last Used Cleanup Script

Version 7
    Share:|

    This script cleans up DepotObjects and Jobs based on the last run time.  For all Deploy Jobs, if the last run time is beyond the specified date the job will be removed and any DepotObjects the Job deploys will be removed, if those DepotObjects do not have any other dependencies.  A property can be set to exclude any Jobs or DepotObjects from the deletion.

     

    There is an option to remove Jobs that have no runs.  The 'keep' property must be defined in the Property Dictionary in the Job and Depot Object classes prior to running the script.

     

    It's advisable to run this as a dry run and review the results before running the actual delete.  It's possible this script could delete objects you want to keep so please verify what is being deleted as a sanity check.  This script is provided with no warranty.

     

    Typical usage would be like:

     

    nsh objectcleanup.nsh -d 0 -t 30 -p KEEP_OBJECT -n true -s false

     

    * Updated 02-JUL-2012

    - added an option to filter the objects by role

    - fixed a problem where you could get into an infinite loop w/ large numbers of objects

    * Updated 21-MAY-2012

    Because the cached SSO creds will likely expire before the script finishes in a larger environment you can write a wrapper sh script like the below to let the objectcleanup.nsh script run until it's done:

     

    #!/bin/sh

    count=0
    while [ ! -f /home/wrobinson/out.csv ]
            do
            if [ ${count} -eq 0 ]
                    then
                    blcred cred -acquire -profile defaultProfile -username BLAdmin -password bladelogic
                    nsh objectcleanup.nsh -d 4 -t 90 -s true -n true -c true -o /home/wrobinson/objclean/out.csv -p KEEP_OBJECT > obj$$.${count} 2>&1
            else
                    resume="`ls -ltr /tmp | grep "oc" | awk '{print $9}' |grep '^[0-9]' | tail -1`"
                    blcred cred -acquire -profile defaultProfile -username BLAdmin -password bladelogic
                    nsh objectcleanup.nsh -d 4 -t 90 -s true -n true -c true -o /home/wrobinson/objclean/out.csv -p KEEP_OBJECT -r /tmp/${resume} > obj$$.${count} 2>&1
            fi
            count=$((${count}+1))
    done