#!/bin/bash # # script to seed archive files in a new replica by running 'p4 verify -qt' in small chunks # # the script dumps the entire file list from the given path then chunks them in # pieces and adds those to the queue, trying not to exceed the given limit. # # pass in a path, the size of chunk you want to add to the queue, and the upper limit to maintain # in the queue. 1,000 and 20,000 seem about right. ymmv depending on your environment: # # > ./seed_replica.sh //depot/demo/... 1000 20000 # # so this is obscure and frustrating. bash interprets certain # characters as newlines, in some cases even spaces. let's re-define # the characters it sees as newlines since Perforce paths might have spaces in them. IFS=$'\t\n\0' # sometimes errors prevent the transfer queue from getting down to zero. This sets # a lower limit for the queue size to trigger the next chunk lower_limit=200 # check that something has been passed in if ! [ $3 ]; then echo "We're looking for a path, a chunk size and a max queue size. Try again." exit fi # get list of files echo echo "Scanning files in $1. This could take a while." `p4 files $1 | sed 's/#.*//' > file_list.txt` files_count=`cat file_list.txt | wc -l` counter=0 let chunks=$files_count/$2+1 echo "Processing $files_count files in $chunks chunks ($2 files per chunk.)" # now let's process each file in chunks, pausing for a bit when the queue gets too big while [ $counter -lt $chunks ]; do let start_index=$counter*$2+1 let end_index=$start_index+$2 echo "Queueing files $start_index - $end_index/$files_count" # run files through xargs->p4 verify -qt results=`sed -n "$start_index,$end_index p" file_list.txt | p4 -x - -b 200 verify -qt "{}" > /dev/null 2>&1` # check the size of the queue, pause if it's too big remaining_files=`p4 pull -ls | awk '{ print $4 }' | head -1 | sed 's/active\///'` if [ $remaining_files -gt $3 ]; then echo "Transfer queue too big. Waiting for transfers to finish." while [ $remaining_files -gt $lower_limit ]; do echo "Remaining files in queue: $remaining_files" let remaining_files=`p4 pull -ls | awk '{ print $4 }' | sed 's/active\///'` sleep 5 done fi let counter=counter+1 done
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 20108 | mattyj2001 |
Whoops. Messed up the workspace mapping. You'd think after nearly 15 years of this I'd remember ... |
||
//guest/mattyj2001/guest/mattyj2001/fun_scripts/seed_replica.sh | |||||
#1 | 20107 | mattyj2001 | Script to use p4 verify to concisely build a clean server based on another replica. |