#!/bin/bash # this script will output a listing of every shelved file, with paths # converted to actual/local paths on the server. The output might be # useful for feeding into a tarball or pushing through rsync to make # a backup of just the shelved files on your server. # ################################################################### # # Note! This script only outputs *potential* server paths to shelved # file contents. There are too many edge cases where a shelved # file does not have a physical counterpart on the server: # # * a shelved revision was obliterated # * integrate/copy files merely hold a reference to the source # * integrated files with no merge also only hold a reference # * a shelved file was deleted or moved # # So many edge cases cropped up I was afraid of missing some, so I # decided to take a 'bigger is better' approach and just provide a # list of local server files that have the potential to be shelved # revisions. Perhaps you should run the final list through 'du' # then 'sed' out the zeroes to get an accurate list of exactly which # local files are shelves. # # Note that I couldn't even accurately predict which shelved files # would be compressed, so I put a '.gz' version and a plain version # of each file in the listing. It's up to you to sort it out. # # Once you get your file list, you could do something like this to # get the total size all your shelved files are taking up on the # server: # # > time cat shelved_file_list.txt | xargs -n1 du -k | sort -nr \ # | awk '{sum+=$1} END{print sum}' # # ################################################################### # 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' # remove output file if it exists [[ -f "shelved_file_list.txt" ]] && rm -f "shelved_file_list.txt" # set up your p4 command p4="p4" # get the server root server_root=`p4 info | grep "Server root\:" | awk '{ print $3 }'` # get the list of changes with shelved files changes=`$p4 changes -s shelved | awk '{ print $2 }'` changes_count=`echo "$changes" | wc -l | awk '{ print $1 }'` changes_total=$changes_count # get the list of files that are shelved in each changelist for change in $changes; do # get raw file list of shelved files depot_paths=$(p4 describe -s -S $change | grep '^\.\.\.') # only continue if there are actual shelved files. the commit server will # report shelved changes but not show file lists if [[ ${#depot_paths} > 0 ]]; then number_of_files=$(echo "$depot_paths" | wc -l | awk '{ print $1 }') size_of_files=$(p4 sizes -s @=$change | awk '{ print $4 }') echo "[$changes_count/$changes_total] Processing change: $change ($number_of_files files, total size $size_of_files bytes)" # there may be multilpe shelved files in a change, so we need to append # stuff to all of them for path in $depot_paths; do path=$(echo $path | sed 's/^\.\.\. \(.*\)#.*$/\1/') echo "$path,d/1.$change.gz" >> shelved_file_list.txt echo "$path,d/1.$change" >> shelved_file_list.txt done changes_count=$((changes_count-1)) fi done if [ -f shelved_file_list.txt ]; then echo Processing `cat shelved_file_list.txt | wc -l | awk '{ print $1 }'` files. Please be patient. # we need a depot list now, so we can substitute the depot name with the actual path depot_list=`$p4 depots | grep -v "remote\|archive\|unload\|spec" | awk '{ print $2 }'` # loop through each depot list and replace paths in the shelved file list for depot in $depot_list; do # get the depot root/map directory depot_root=$(p4 -ztag depot -o $depot | grep Map | awk '{ print $3 }' | sed 's#\/\.\.\.$##') # do the magic. combine the server root, depot root and depot path sed -i.bak s#//$depot#$server_root/$depot_root# ./shelved_file_list.txt done # clean up rm shelved_file_list.txt.bak echo Your shelved file list is in shelved_file_list.txt echo NOTE: This file contains *potential* server paths to echo shelved files. Please see comments in this script for details. else echo "No shelved files found!" fi
# | 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/list_shelved_files.sh | |||||
#1 | 20106 | mattyj2001 | Script to find library/archive files of shelves. |