#!/bin/bash #------------------------------------------------------------------------------ # Copyright (c) Perforce Software, Inc., 2007-2014. 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. #------------------------------------------------------------------------------ # This pair of scripts provide a sample of automation to reseed a # filtered forwarding replica of a master Perforce server. It need # not be run routinely, but can be run on occasion as needed to # reseed the filtered forwarding replica. This is needed whenever # the scope of the filter for the forwarding replica changes. That # scope is defined by the 'RevisionDataFilter:' field, defined in # the server spec for the filtered forwarding replica. # Assumptions: # Perforce SDP is used, and we're replicating for Instance 1. # Port 1666 is used on both hosts. # p4d-01 is the master server. # p4d-02 is a filtered forwarding replica, with service user svc_p4d-02, # and a password file /p4/common/bin/.p4passwd.svc_p4d-02. # The server spec pfd-02 defines the 'RevisionDataFilter:' field that # defines the scope of the filtering. # Perforce runs as the 'perforce' user. # This script starts the process of reseeding the filtered forwarding # replica, and then calls another script that runs on the replica host # (p4d-02) to finish the job. Operating this way maintains optimal data # security and performance, since only the data required on p4d-02 actually # goes to p4d-02. # This script requires SSH keys to be properly set up so that the # 'perforce' user can do an 'ssh' from 'p4d-01' to 'p4d-02' without # a password (but not necessarily the other way around). # To test SSH keys, try this: # Login as perforce@p4d-01 # ssh p4d-02 ls # ssh p4d-02 hostname # # If that doesn't work, it needs to be made to work before this script # will run. Note that SSH keys need only be configured in one direction, # from the master server machine to the filtered replica server machine. # SSH keys do not need to be configured in the other direction (e.g. # from the filtered replica to the master), and should not be if security # is a concern. # NOTE: This script assumes the databases sitting in /p4/1/offline_db # will be available for the duration of this scripts processing (about # the time it takes to create a normal checkpoint), and also that the # databases in /p4/1/offline_db were generated from the latest checkpoint # file in /p4/1/checkpoints. This should always be true during normal # business hours and if the routine SDP scripts (i.e. daily_backup.sh # and/or weekly_backup.sh) has been operating normally. # BE CAREFUL NOT TO RUN THIS at a time when it might conflict with # normal SDP cron jobs, daily_backup.sh, weekly_backup.sh, or # live_checkpoint.sh. # Run like this: # cd /p4/1/bin # nohup /p4/1/bin/reseed_ffr-run_on_p4-01.sh > /p4/1/logs/reseed_ffr.$(date +'%Y%m%d-%H%M%S').log 2>&1 & if [[ ${HOSTNAME%%.*} == "p4d-01" ]]; then echo "Verified: Operating on ${HOSTNAME%%.*}" else echo "Error: Run only on p4d-01." exit 1 fi LastCkp=$(ls -1t /p4/1/checkpoints/p4_1.ckp.*.gz|grep -v filtered|head -1) LastCkpNum=${LastCkp##*p4_1.ckp.} LastCkpNum=${LastCkpNum%.gz} FilteredCkp="/p4/1/checkpoints/p4_1.ckp.$LastCkpNum.filtered.p4d-02.gz" echo -e "\nCreating filtered checkpoint from offline_db. Generating [$FilteredCkp].\n" echo "Running: /p4/1/bin/p4d_1 -r /p4/1/offline_db -J off -P p4d-02 -z -jd $FilteredCkp" /p4/1/bin/p4d_1 -r /p4/1/offline_db -J off -P p4d-02 -z -jd $FilteredCkp echo "Running: scp -p $FilteredCkp p4d-02:/p4/1/checkpoints/." scp -p $FilteredCkp p4d-02:/p4/1/checkpoints/. echo "Running: ssh p4d-02 /p4/1/bin/reseed_ffr-run_on_p4d-02.sh" ssh p4d-02 /p4/1/bin/reseed_ffr-run_on_p4d-02.sh
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 16513 | C. Thomas Tyler |
Refactored ffr_reseed to the new Workshop stanard for personal projects. |
||
#1 | 11495 | C. Thomas Tyler |
Added sample filtered forwarding replica reseed script. While a proper README file is needed, these scripts have lots of internal documentation. |