#!/bin/bash #------------------------------------------------------------------------------ # Copyright (c) Perforce Software, Inc., 2007-2015. All rights reserved # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1 Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE # SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. #------------------------------------------------------------------------------ export P4INSTANCE=${P4INSTANCE:-Undefined} export P4INSTANCE=${1:-$P4INSTANCE} if [[ $P4INSTANCE == Undefined ]]; then echo "Instance parameter not supplied." echo "You must supply the Perforce instance as a parameter to this script." exit 1 fi . /p4/common/bin/p4_vars $P4INSTANCE . /p4/common/bin/backup_functions.sh LOGFILE=$LOGS/p4verify.log STATUS="OK: All scanned depots verified OK." declare -i EXIT_CODE=0 P4="$P4BIN -p $P4PORT -u $P4USER" /p4/common/bin/p4login echo If there are errors in this log, contact support@perforce.com > $LOGFILE # Verify all depots of all types except 'remote' and 'archive'. for d in `$P4 -s depots|grep "^info: Depot " |\ grep -v --perl-regexp "^info: Depot \S+ \d{4}\/\d{2}\/\d{2} (remote|archive|unload) " |\ cut -d ' ' -f 3`; do echo === Started verify of //$d/... at $(date). >> $LOGFILE if [[ "${P4REPLICA}" == "FALSE" ]]; then echo $P4 -s verify -qz //$d/... >> $LOGFILE $P4 -s verify -qz //$d/... >> $LOGFILE 2>&1 else echo $P4 -s verify -qz -t //$d/... >> $LOGFILE $P4 -s verify -qz -t //$d/... >> $LOGFILE 2>&1 $P4 changes -s shelved //$d/... | cut -d " " -f 2 | while read cl;do $P4 print //$d/...@=$cl > /dev/null 2>&1 done fi if [[ $? -ne 0 ]]; then STATUS="Error: Verify attempt failed. Review the log [$LOGFILE]." EXIT_CODE=1 fi done for d in `$P4 -s depots| grep "^info: Depot " | grep --perl-regexp "^info: Depot \S+ \d{4}\/\d{2}\/\d{2} unload" | cut -d " " -f 3 `; do echo === Started verify of //$d/... at $(date). >> $LOGFILE if [[ "${P4REPLICA}" == "FALSE" ]]; then echo $P4 -s verify -U -q //$d/... >> $LOGFILE $P4 -s verify -U -q //$d/... >> $LOGFILE 2>&1 else echo $P4 -s verify -U -q -t //$d/... >> $LOGFILE $P4 -s verify -U -q -t //$d/... >> $LOGFILE 2>&1 fi if [[ $? -ne 0 ]]; then STATUS="Error: Verify attempt failed. Review the log [$LOGFILE]." EXIT_CODE=1 fi done if [[ $EXIT_CODE -eq 0 ]]; then if [[ -n "$(grep BAD! $LOGFILE)" || -n "$(grep MISSING! $LOGFILE)" || -n "$(grep p4\ help\ max $LOGFILE)" ]]; then STATUS="Warning: Verify errors detected. Review the log [$LOGFILE]." EXIT_CODE=1 fi fi echo Completed verifications at $(date). >> $LOGFILE mail_log_file "$HOSTNAME $P4SERVER P4Verify Log ($STATUS)" exit $EXIT_CODE
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#64 | 30344 | C. Thomas Tyler | Fixed typo in usage synopsis. | ||
#63 | 30272 | C. Thomas Tyler |
Added '-p4config' option to verify an arbitrary p4d server, maybe non-SDP and non-Linux. Changed mechansim for checking P4D_VERSION to use 'p4 info' rather than 'p4d -V' output, so as to work for local and remote servers. Added warnings for short-duration tickets. Added early abort if user does not have admin or better access (as is required for running 'p4 verify'). |
||
#62 | 30261 | C. Thomas Tyler |
p4verify.sh: Fixed bug that caused duplicate emails to be sent. #review-30262 |
||
#61 | 30255 | C. Thomas Tyler |
Added '-a' to all grep commands. #review-30256 |
||
#60 | 30251 | C. Thomas Tyler |
p4verify.sh: Added '-no_z' option to verify without '-z'. Removed restriction on using '-recent' with '-nr'. It is useful to verify recent shelves. #review-30252 |
||
#59 | 30156 | C. Thomas Tyler |
p4verify.sh v5.16.2: Doc fixes, no functional change. Thanks, Andrei! |
||
#58 | 30141 | C. Thomas Tyler | p4verify.sh: For shelved files that fail verify, show the command line that generated the error. | ||
#57 | 29992 | C. Thomas Tyler |
p4verify.sh: Added support for handling the 'trait' depot (new in 2023.2). Refactored get_old_log_timestamp() function, moving it from backup_functions.sh into new log_functions.sh file. #review-29993 |
||
#56 | 29861 | C. Thomas Tyler |
p4verify.sh v5.15: * The '-paths' and '-recent' options can now be used together, so recent files in specified paths can be verified. Particularly useful for edge servers and failover scenarios where earlier and more thorough vetting has been done. * The '-recent' now sports an optional '-recent=N' syntax to specify # of revs. * Doc updates for above. * Fixed minor ShellCheck compliance issues. #review-29862 |
||
#55 | 29827 | C. Thomas Tyler |
Added support for verifying the Extensions depot. #review-29828 @robert_cowham |
||
#54 | 29717 | C. Thomas Tyler | p4verify.sh: Cosmetic issue in 'Time:' output in p4verify.log. | ||
#53 | 29689 | C. Thomas Tyler |
Slight tweak to new '-ignores' option introduced in @29655. Added concept of a standard ignores file; if it exists in expected path, '-ignores' option is not needed. Can use '-ignores none' to avoid processing any ignores. Ignores output clearly indicates whether errors were ignored. Improved docs for ignores as well. #review-29690 |
||
#52 | 29655 | C. Thomas Tyler |
p4verify.sh v5.13.0: * Added '-ignores <regex_file_pattern>' option to ignore known errors. * Corrected issues with summary of messages in summary log file. * Changed call_p4verify() function name to call_p4_verify() to more clearly indicate that the underlying 'p4' command line is called. * Fixed cosmet tab/space errors. #review-29656 |
||
#51 | 29633 | C. Thomas Tyler |
Added '-paths' option to specify a file containing a list of paths to verify. Can be combined with '-chunks' or used independently. Enhanced timing detail, and made it easier to extract timing detail with soemthing like: grep ^Time: /p4/1/logs/p4verify.log Added docs for above, and also did some general cleanup of docs. #review-29634 |
||
#50 | 29586 | C. Thomas Tyler |
Added safety feature to avoid processing cache mode replica. Added '-Ocache' override option to bypass the safety feature. Added relevant docs. |
||
#49 | 29580 | C. Thomas Tyler | Added check for bash v4+. | ||
#48 | 29578 | C. Thomas Tyler |
Fixed issue with log rotation login on some platforms. #review-29579 @Domenic |
||
#47 | 29577 | C. Thomas Tyler | Added usage exmple for archive loading with delay. | ||
#46 | 29570 | Andy Boutte |
Enhance p4verify to utilize die() function which will allow user to leverage AWS SNS or PagerDuty. Added '-N' option to notify only in event of failure. |
||
#45 | 29559 | C. Thomas Tyler |
Added '-Q <MaxTotalPullQueueSize>' option. Fixed bugs from earlier review, 29555. #review-29560 @robert_cowham |
||
#44 | 29554 | C. Thomas Tyler |
Added '-w <Wait>' and '-q <MaxActivePullQueueSize>' options to p4verify.sh. #review-29555 |
||
#43 | 29106 | C. Thomas Tyler |
Split p4verify.log into full and summary logs, with summary sent to AWS SNS if configured. Summary is always sent via email, referencing log on host. Added rough counts of verify errors of various types to summary. Docs: Added more examples with more complete information. Enhanced general log file handling. Fixed a minor bug in suppression of 'no such file' errors. Enhanced internal code comments. Bypassing pre-commit review to engage test suite. #review-29025 @andy_boutte |
||
#42 | 28977 | C. Thomas Tyler |
Fixed bug found in review. #review-28975 |
||
#41 | 28974 | C. Thomas Tyler |
Fixed bug with P4D_VERSION unbound variable if '-o MISSING' is used and SDP shell environment has not been sourced. The script sourced p4_vars to set P4D_VERSION, but too late, after P4D_VERSION was referenced. This has been fixed. Moved cmd() function to be in the 'Local Functions' section of the file. #review-28975 |
||
#40 | 28835 | C. Thomas Tyler |
p4verify.sh v5.6.2: * Added '-dlf <depot_list_file>' option to specify prioritized list of depots to process. * Added '-chunks', useful for avoiding RAM exhaustion. Uses the depot_verify_chunks.py option to verify depots in chunks. Testing indicates this may be much slower than a standard verify, but can be a useful option if RAM is scarce. If used, this introduces a dependency on the perforce-p4python3 package. * Optimized options to 'p4 verify' on a per-depot basis, e.g. not applying '-z' in depot types that can't have lazy copies. * Eliminated the "on replica" portion of a message displayed on some verify commands, as it had become potentially inaccurate with introduction of the '-nt' option. * Added 'Processing N depots' message. To Do: The verify_depot_chunks.py sometimes lists empty paths, e.g. //MyDepot/Binaries/*, which could be eliminated if empty. This is mostly harmless but results in some cruft in the log. |
||
#39 | 28771 | C. Thomas Tyler |
Changed email address for Perforce Support. #review-28772 @amo @robert_cowham |
||
#38 | 28211 | C. Thomas Tyler |
p4verify.sh v5.4.0: * Added '-o BAD|MISSING' to expose the p4d '--only BAD|MISSING' option. * Fix: Completed implementation of documented '-a' option. * Added '-nt' option to avoid passing '-t' to 'p4 verify' on replicas. * Reduced excess noise from change-by-change verification of shelves. Bypassing pre-commit to engage test suite. #review-28212 |
||
#37 | 28143 | C. Thomas Tyler |
Fixed issue operating in environments where the shell USER variable is not defined. The current USER is now determined with 'id -n -u'. Also silenced a harmless ShellCheck warning. #review-28144 |
||
#36 | 27722 | C. Thomas Tyler |
Refinements to @27712: * Resolved one out-of-date file (verify_sdp.sh). * Added missing adoc file for which HTML file had a change (WorkflowEnforcementTriggers.adoc). * Updated revdate/revnumber in *.adoc files. * Additional content updates in Server/Unix/p4/common/etc/cron.d/ReadMe.md. * Bumped version numbers on scripts with Version= def'n. * Generated HTML, PDF, and doc/gen files: - Most HTML and all PDF are generated using Makefiles that call an AsciiDoc utility. - HTML for Perl scripts is generated with pod2html. - doc/gen/*.man.txt files are generated with .../tools/gen_script_man_pages.sh. #review-27712 |
||
#35 | 27616 | C. Thomas Tyler |
Corrected p4verify.sh doc error implying multiple instances can be processed in a single invocation. Also fixed a shellcheck warning. Non-functional change. |
||
#34 | 27216 | C. Thomas Tyler |
Non-functional change: Fixed a common doc type: paramter -> parameter |
||
#33 | 27107 | C. Thomas Tyler |
Reworked how shelved files are verified. If shelved files are to be verified, shelved changelists are processed rather than verifying by association with depots. This now complies with documented restriction per 'p4 help verify' that only the @= revision specifier is valid when the '-S' flag is used. If '-recent' is specifed, only the most recent N shelved changelists are verified. #review-27108 |
||
#32 | 26847 | Robert Cowham | Put back the include tags for AsciiDoc | ||
#31 | 26815 | C. Thomas Tyler | Patch: Fixed bug in '-recent' flag to p4verify.sh. | ||
#30 | 26755 | Robert Cowham | Include p4verify.sh man page in SDP Guide automatically for usage section. | ||
#29 | 25547 | C. Thomas Tyler |
p4verify.sh v5.2.0: Added targeting flags: -nu - No Unload -nr - No Regular archived files. -ns - No Spec Depot -nS - No Shelved -a - Archive Depot verify. Verification of archive depots with '-A' is now supported, though not enabled by default as archive depots are typically in cold storage. Also made doc tweaks, enhanced description of '-L' flag and correcting '-h' usage. Added warning message if an unknown depot type is encountered. Unknown depot types are ignored, as new depot types typically require new logic to handle. More updates for shellcheck compliance. |
||
#28 | 25452 | C. Thomas Tyler | Bumped Version ID for change @25451. | ||
#27 | 25451 | Robert Cowham | Fix failing test - local cmd function was being overwritten by sourcing backup_functions.sh | ||
#26 | 25238 | C. Thomas Tyler |
Replaced references to /tmp with P4TMP (e.g. /p4/N/tmp) to avoid issues with SELinux incompatibility. For p4verify.sh, enhanced: * Minor performance enhancement: Added '-m1' flag to egrep that determines whether to exit code with non-zero, as we only need to detect one occurence. * Changed 'Warning:' to 'Error:' if verify errors are detected. * Removed redundant check that SDP_INSTANCE is set. * Added total time info. * Adjusted to pass 'shellcheck.sh' check. #review-25239 |
||
#25 | 24967 | C. Thomas Tyler | Merged patch fix from Karl in main to dev. | ||
#24 | 24218 | C. Thomas Tyler |
Enhanced performance of "p4 verify.sh -recent" by lowering default changelists to scan per depot, and skipping shelves. Also fixed indentation/style issues. |
||
#23 | 23750 | C. Thomas Tyler |
In p4verify.sh, fixed handling of unload and spec depots. Unload depots were not being identified correctly, and so special flags needed for unload-type depots were not applied. For spec-type depots, 'p4 verify -qS' was run, which isn't necessary or helpful since it is not possible to shelve files in the spec depot. The fix included replacing parsing logic with optimized p4 commands that don't require parsing. |
||
#22 | 22074 | Russell C. Jackson (Rusty) |
Corrected the name of the variable. Already reviewed with Tom. |
||
#21 | 22066 | Russell C. Jackson (Rusty) | Added rotate for p4verify.log instead of just deleting the prior one. | ||
#20 | 21233 | Russell C. Jackson (Rusty) | Review 21010 from Adrian commit. | ||
#19 | 21007 | adrian_waters | Fix specification of depot path in get_verify_rev_range when -recent used | ||
#18 | 20995 | C. Thomas Tyler |
Style tweak; using double-square brakets rather than single-square brackets. |
||
#17 | 20994 | adrian_waters |
Refactor around changes to support -recent arg - had broken code even where -recent not used because of unbounded variable ($d); use of the -recent option also fails as 'verify -S' not valid for shelved files (only @= is supported) ; stripping out archive,unload+remote depots also not working + get_verify_rev_range used depot name incorrectly in changes (eg, changed -m 1 depot/... rather than //depot/...) Raised job000634 for changes. Further aim is to modify script for depots with no shelved files does not result in an 'error' line being written to p4verify.log - it confuses clients - will do that as a separate change. |
||
#16 | 20909 | Russell C. Jackson (Rusty) | Fixed missing LOGFILE variable issue. | ||
#15 | 20879 | Robert Cowham | Fix typo in variable name. | ||
#14 | 20868 | C. Thomas Tyler |
Add '-recent' flag to p4verify.sh to verify only recent changes. Usage info is added with '-h' and '-man' flags. This change involved changing the command line parsing to accept the <instance> positional parameter and '-recent' flag, as well as standard '-v' and '-D' flags. This change also should reduce memory requirement in cases where there are a large number of verify errors. This was done by combining greps and tossing 'grep' output to /dev/null, using only the grep exit code to determine if BAD/MISSING (etc.) appear in the log. Added a Version id. (Need to avoid +k due to the way SDP files move around from server to server). This must be updated manually. |
||
#13 | 20086 | Russell C. Jackson (Rusty) | Added -t to verify of shelves on a replica, and added verify of shelves on the master. | ||
#12 | 20083 | Russell C. Jackson (Rusty) | Added missing echo of command into log file. | ||
#11 | 19314 | Russell C. Jackson (Rusty) |
Change p4verify.sh to use -S to verify shelves on a replica instead of printing the files on the shelf. Removed the HOST_IP settings from mkdirs and instance_vars since it causes problems in a shared depotdata environment, and it was a temporary fix to work around a bug with auth.id that is being fixed. |
||
#10 | 19102 | Russell C. Jackson (Rusty) |
Added check for SHAREDDATA to avoid using -t on a shared data volume replica. Allows running verify on the replica instead of the master. |
||
#9 | 16029 | C. Thomas Tyler |
Routine merge to dev from main using: p4 merge -b perforce_software-sdp-dev |
||
#8 | 15778 | C. Thomas Tyler | Routine Merge Down to dev from main. | ||
#7 | 13906 | C. Thomas Tyler |
Normalized P4INSTANCE to SDP_INSTANCE to get Unix/Windows implementations in sync. Reasons: 1. Things that interact with SDP in both Unix and Windows environments shoudn't have to account for this obscure SDP difference between Unix and Windows. (I came across this doing CBD work). 2. The Windows and Unix scripts have different variable names for defining the same concept, the SDP instance. Unix uses P4INSTANCE, while Windows uses SDP_INSTANCE. 3. This instance tag, a data set identifier, is an SDP concept. I prefer the SDP_INSTANCE name over P4INSTANCE, so I prpose to normalize to SDP_INSTANCE. 4. The P4INSTANCE name makes it look like a setting that might be recognized by the p4d itself, which it is not. (There are other such things such as P4SERVER that could perhaps be renamed as a separate task; but I'm not sure we want to totally disallow the P4 prefix for variable names. It looks too right to be wrong in same cases, like P4BIN and P4DBIN. That's a discussion for another day, outside the scope of this task). Meanwhile: * Fixed a bug in the Windows 2013.3 upgrade script that was referencing undefined P4INSTANCE, as the Windows environment defined only SDP_INSTANCE. * Had P4INSTANCE been removed completely, this change would likely cause trouble for users doing updates for existing SDP installations. So, though it involves slight technical debt, I opted to keep a redundant definition of P4INSTANCE in p4_vars.template, with comments indicating SDP_INSTANCE should be used in favor of P4INSTANCE, with a warning that P4INSTANCE may go away in a future release. This should avoid unnecessary upgrade pain. * In mkdirs.sh, the varialbe name was INSTANCE rather than SDP_INSTANCE. I changed that as well. That required manual change rather than sub/replace to avoid corrupting other similar varialbe names (e.g. MASTERINSTANCE). This is a trivial change technically (a substitute/replace, plus tweaks in p4_vars.template), but impacts many files. |
||
#6 | 13586 | C. Thomas Tyler |
Routine merge down from main -> dev. Trivial merges, all resolved with 'p4 resolve -as.' |
||
#5 | 12169 | Russell C. Jackson (Rusty) |
Updated copyright date to 2015 Updated shell scripts to require an instance parameter to eliminate the need for calling p4master_run. Python and Perl still need it since you have to set the environment for them to run in. Incorporated comments from reviewers. Left the . instead of source as that seems more common in the field and has the same functionality. |
||
#4 | 12028 | C. Thomas Tyler | Refreshed SDP dev branch, merging down from main. | ||
#3 | 11485 | Russell C. Jackson (Rusty) |
Brought over changes from RCJ sdp to properly handle Edge servers and to properly replicate shelves when replicating from Windows to Linux |
||
#2 | 11476 | Russell C. Jackson (Rusty) | Fixed echo command to match the actual command run. | ||
#1 | 10638 | C. Thomas Tyler | Populate perforce_software-sdp-dev. | ||
//guest/perforce_software/sdp/main/Server/Unix/p4/common/bin/p4verify.sh | |||||
#1 | 10148 | C. Thomas Tyler | Promoted the Perforce Server Deployment Package to The Workshop. |