keep_offline_db_current.sh #1

  • //
  • guest/
  • russell_jackson/
  • sdp/
  • Server/
  • Unix/
  • p4/
  • common/
  • bin/
  • keep_offline_db_current.sh
  • View
  • Commits
  • Open Download .zip Download (4 KB)
#!/bin/bash
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
#------------------------------------------------------------------------------

# This script is for use only on a standby replica. It will not run on any
# other type of server.
#
# It ensures the offline_db has the most current rotated journals replayed,
# WITHOUT doing a full checkpoint operation. It is intended as a lighter-weight
# alternative to sync_replica.sh / replica_cleanup.sh on a standby, e.g. in an
# environment where the commit server's checkpoints/journals folder is shared
# (e.g. via NFS) with this standby.
#
# This uses checkpoint.log as its primary log. Run it ONLY on a machine where
# other checkpoint.log-writing scripts (daily_checkpoint.sh, live_checkpoint.sh,
# rotate_journal.sh) do NOT also run, to avoid interleaved logging.
#
# FORK NOTE (russell_jackson): The upstream SDP version replays journals using
# the *target* (commit) server's journalPrefix. This fork's
# replay_journals_to_offline_db() replays from this server's local CHECKPOINTS
# and JOURNALS directories. For an NFS-shared-checkpoints setup, ensure the
# shared journals are reachable via this instance's local CHECKPOINTS/JOURNALS
# paths (e.g. via mount or symlink) so they are picked up here.

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

# If defined in the environment, used as the default when the CLI arg is absent.
export P4SUPPRESSINFOEMAIL=${P4SUPPRESSINFOEMAIL:-false}
export P4SUPPRESSINFOEMAIL=${2:-$P4SUPPRESSINFOEMAIL}

# shellcheck disable=SC1091
source /p4/common/bin/p4_vars "$SDP_INSTANCE"
# shellcheck disable=SC1091
source /p4/common/bin/backup_functions.sh
# shellcheck disable=SC2034
LOGFILE="$LOGS/checkpoint.log"

######### Start of Script ##########

check_vars
set_vars

if [[ "$(is_standby "$SERVERID")" != YES ]]; then
   die "Error: Run this only on a standby replica."
fi

rotate_last_run_logs
log "Start $P4SERVER Keep offline_db current"

# Verify the SDP/offline_db state before replaying, if verify_sdp.sh is present.
# It is skippable per-test via VERIFY_SDP_SKIP_TEST_LIST. If verify_sdp.sh is not
# installed (or not yet tuned for this fork's layout), we warn and continue
# rather than hard-fail, since this operation only updates the offline_db.
if [[ -x "$P4CBIN/verify_sdp.sh" ]]; then
   VerifyCmd="$P4CBIN/verify_sdp.sh $SDP_INSTANCE -skip ${VERIFY_SDP_SKIP_TEST_LIST:-},crontab,excess,init,license,masterid,version -L off"
   log "Calling 'verify_sdp.sh' before replaying journal to offline_db:\\n$VerifyCmd"
   $VerifyCmd >> "$LOGFILE" 2>&1 ||\
      die "Error: Cannot confirm all is well with $P4CBIN/verify_sdp.sh. Aborting."
else
   log "Note: $P4CBIN/verify_sdp.sh not found; skipping pre-replay verification."
fi

check_uid
check_dirs
check_offline_db_usable
ckp_running
get_journalnum
get_offline_journal_num

# Replay any unreplayed rotated journals into the offline_db.
replay_journals_to_offline_db

# Remove excess rotated journals/checkpoints and old logs.
remove_old_checkpoints_and_journals
check_disk_space
remove_old_logs
log "End $P4SERVER Keep offline_db current"
if [[ "${P4SUPPRESSINFOEMAIL,,}" == "false" ]]; then
   mail_log_file "$HOSTNAME $P4SERVER Daily maintenance log."
fi
ckp_complete
# Change User Description Committed
#1 32803 Russell C. Jackson (Rusty) Modernize russell_jackson SDP fork from upstream 2025.2.

- Port modern p4d features: partitioned/readonly clients, upgrade-safety (p4
  storage -w / p4 upgrades polling), checkpoint/replica/edge tooling, proxy &
  broker SSL trust, modern p4login, dir-ownership preflight.
- Add scripts: get_p4_binaries.sh (renamed from helix), ccheck.sh, verify_sdp.sh,
  sdp_health_check.sh, journal_watch.sh, load_checkpoint.sh, refresh_P4ROOT,
  request_replica_checkpoint.sh, keep_offline_db_current.sh, gen_sudoers.sh, etc.
- Migrate configurables to configurables.cfg applied via ccheck.sh -fix; slim
  configure_new_server.sh to setup-only.
- upgrade.sh: dry-run default, verified clean rollback point.
- Fixes from multi-agent review (rsync byte/KB+comma, cfg field counts, version
  thresholds, etc.).

See SDP_PORT_SCOPE.md for the full manifest.