#!/bin/bash # This script will remove all by the latest file in your /p4/1/depots/ tree. # It is designed to work with servers running with lbr.autocompress=1 set in the configurables. export SDP_INSTANCE=${SDP_INSTANCE:-Undefined} export SDP_INSTANCE=${1:-$SDP_INSTANCE} if [[ $SDP_INSTANCE == Undefined ]]; then echo "Instance parameter not supplied." echo "You must supply the Perforce instance as a parameter to this script." exit 1 fi replication=$($P4BIN configure show $SERVERID | grep lbr.replication | cut -d "=" -f 2) retVal=$? if [[ $retVal -ne 0 ]]; then exit 0 else replication=$(echo $replication) fi if [[ $replication == "shared" ]]; then exit 0 fi if [[ -f /p4/${SDP_INSTANCE}/bin/skip_cache_clean.txt ]]; then exit 0 fi AVAIL=$(df --output=avail /p4/${SDP_INSTANCE}/depots | tail -n 1) # REQAVAIL is ~1TB in bytes REQAVAIL=1000000000 if [[ -f /p4/${SDP_INSTANCE}/bin/cache_clean_reqavail.txt ]]; then REQAVAIL=$(cat /p4/${SDP_INSTANCE}/bin/cache_clean_reqavail.txt) fi if [[ $AVAIL -gt $REQAVAIL ]]; then exit 0 fi ATIME=5 if [[ -f /p4/${SDP_INSTANCE}/bin/cache_clean_atime.txt ]]; then ATIME=$(cat /p4/${SDP_INSTANCE}/bin/cache_clean_atime.txt) fi # Check to make sure that global shelves are enabled. If they are not, this script # would most likely end up deleting someone's shelved files. if [[ ! $(p4 -ztag -F %Value% configure show dm.shelve.promote) ]]; then echo "Global shelves are not enabled, aborting!" exit 1 fi IFS=$'\n' depots=($(ls "/p4/${SDP_INSTANCE}/depots/")) for depot in "${depots[@]}" do if [[ !($depot =~ .*unload.*) && !($depot =~ .*spec.*) ]]; then find /p4/${SDP_INSTANCE}/depots/$depot/ -atime +${ATIME} -type f -exec rm {} \; & fi done
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#19 | 28916 | Russell C. Jackson (Rusty) | Improved safety checks for shared data and failed commands. | ||
#18 | 28111 | Russell C. Jackson (Rusty) | Added extra safety check to avoid running when the server is using shared storage. | ||
#17 | 28109 | Russell C. Jackson (Rusty) | Added check for SHAREDDATA = true | ||
#16 | 26944 | Russell C. Jackson (Rusty) | Corrected free space and removed hard coding. | ||
#15 | 26941 | Russell C. Jackson (Rusty) |
Added nice to dump and restore of checkpoints. Added check for free space in cache clean. Only run when req. |
||
#14 | 26858 | Russell C. Jackson (Rusty) | Added config file for cache clean atime setting to support different settings for each edge server. | ||
#13 | 26551 | Russell C. Jackson (Rusty) | Changed to only keep revisions accessed in the last 5 days. | ||
#12 | 25510 | Russell C. Jackson (Rusty) | New cacheclean.sh based on find atime for much better performance. | ||
#11 | 25459 | Russell C. Jackson (Rusty) | Add trailing slash on depot path. | ||
#10 | 25440 | Russell C. Jackson (Rusty) | Updated cacheclean to run on each depot in parallel rather on all of the depots at once. | ||
#9 | 25090 | Russell C. Jackson (Rusty) | Added -a to grep to handle non ascii characters, and changed to overwrite the log so it doesn't keep growing. | ||
#8 | 25087 | Russell C. Jackson (Rusty) | Added a check to make sure the array entry is a file before running rm on it. | ||
#7 | 25085 | Russell C. Jackson (Rusty) | Fixed missing fi and change single quote to double quote to allow variable to work in find. | ||
#6 | 25078 | Russell C. Jackson (Rusty) | Corrected P4LOGS to LOGS | ||
#5 | 25073 | Russell C. Jackson (Rusty) | Added check for cache_clean_skip.txt and increased the number of journals to keep to allow for extra rotation. | ||
#4 | 25048 | Russell C. Jackson (Rusty) | Increased number of files to keep to 3 to allow for latest revision and some shelves. | ||
#3 | 25038 | Russell C. Jackson (Rusty) | Added check to make sure global shelves are enabled before running. | ||
#2 | 25036 | Russell C. Jackson (Rusty) | Updated to skip spec and unload directories. | ||
#1 | 25016 | Russell C. Jackson (Rusty) | Shell script to clean all but the latest file from /p4/1/depots/ |