MAILTO=REPL_MAILTO
MAILFROM=REPL_MAILFROM
PATH=/p4/common/bin:/p4/REPL_INSTANCE/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:
SHELL=/bin/bash

# Times are all preset to times that make sense based on UTC time with most users in PST.

# common tasks

# Commented out since this is only used when the crontab is checked in and updated from Perforce.
# */60 * * * * [ -e /p4/p4.crontab ] && crontab /p4/p4.crontab > /dev/null 2>&1

INSTANCE=REPL_INSTANCE
# Master Verify - Uncomment this line if you do not have any replica servers.
# 5 4 * * 6 [ -e /p4/common/bin ] && /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/common/bin/p4verify.sh ${INSTANCE}

# Run the weekly maintenance script to clean up old users, labels, workspaces and changelists. Be sure to set up the maintenance.cfg file.
0 16 * * * /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/sdp/Maintenance/maintenance ${INSTANCE}
0 16 * * * /p4/common/bin/run_if_edge.sh ${INSTANCE} /p4/sdp/Maintenance/edge_maintenance ${INSTANCE}

# Run p4 unlock -x on edge servers every six hours to remove exclusive locks that shouldn't be there.
0 */6 * * * [ -e /p4/common/bin ] && /p4/common/bin/run_if_master.sh ${INSTANCE} p4 unlock -x > /dev/null 2>&1
0 */6 * * * [ -e /p4/common/bin ] && /p4/common/bin/run_if_edge.sh ${INSTANCE} p4 unlock -x > /dev/null 2>&1

# Update the limits group to make sure all users are listed in it.
*/60 * * * * [ -e /p4/common/bin ] && /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/common/bin/update_limits.py ${INSTANCE}

# Checkpoints
# Run recreate_db_checkpoint.sh on the first Saturday afternoon in Jan. and July.
# 5 5 * * 6 [ $(date +\%d) -le 07 ] && /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/common/bin/rotate_journal.sh ${INSTANCE}
# 5 6 * * 6 [ $(date +\%d) -le 07 ] && /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/common/bin/recreate_db_checkpoint.sh ${INSTANCE}

# If you enable to recreate_db_checkpoint.sh, be sure to change 0-6 to 0-5 below.
5 4 * * 0-6 [ -e /p4/common/bin ] && /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/common/bin/rotate_journal.sh ${INSTANCE}
5 5 * * 0-6 [ -e /p4/common/bin ] && /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/common/bin/daily_checkpoint.sh ${INSTANCE}

# 35 6 * * 6 [ $(date +\%d) -le 07 ] && /p4/common/bin/run_if_edge.sh ${INSTANCE} /p4/common/bin/recreate_db_checkpoint.sh ${INSTANCE}

# If you enable to recreate_db_checkpoint.sh, be sure to change 0-6 to 0-5 below.
35 6 * * 0-6 [ -e /p4/common/bin ] && /p4/common/bin/run_if_edge.sh ${INSTANCE} /p4/common/bin/daily_checkpoint.sh ${INSTANCE}

# p4review daemon - This function is handled by Swarm now.
# */5 * * * * [ -e /p4/common/bin ] && /p4/common/bin/run_if_master.sh ${INSTANCE} /p4/common/bin/p4review.py ${INSTANCE}

# Kill IDLE and Init tasks that sit more than 5 minutes. Use on servers where you are having problems with IDLE connections sitting too long.
# */10 * * * * [ -e /p4/common/bin ] && /p4/common/bin/p4master_run ${INSTANCE} /p4/common/bin/kill_idle.sh ${INSTANCE}

# Replica Tasks

# Verify
# Run the replica verify quarterly.
# Use the -P parameter to run a parallel verify on the replica servers.
5 21 * * 6 /p4/common/bin/run_if_replica.sh ${INSTANCE} /p4/common/bin/p4verify.sh ${INSTANCE} -P 8
# */10 * * * * /p4/common/bin/run_if_replica.sh ${INSTANCE} /p4/common/bin/verify_shelves.sh ${INSTANCE} 50

# Sync checkpoints from master
0 21 * * 1,3,5 [ -e /p4/common/bin ] && /p4/common/bin/run_if_replica.sh ${INSTANCE} /p4/common/bin/sync_replica.sh ${INSTANCE}
# Run recreate_db_checkpoint.sh on the first Saturday afternoon in Jan. and July.
5 22 * * 6 [ $(date +\%d) -le 07 ] && /p4/common/bin/run_if_replica.sh ${INSTANCE} /p4/common/bin/recreate_db_sync_replica.sh ${INSTANCE}

# If you can't run the scripts above due to rsync issues, then run this one instead.
# 0 5 * * 0-5 [ -e /p4/common/bin ] && /p4/common/bin/run_if_replica.sh ${INSTANCE} /p4/common/bin/replica_cleanup.sh ${INSTANCE}

# Replica Status
*/6 * * * * [ -e /p4/common/bin ] && /p4/common/bin/run_if_replica.sh ${INSTANCE} /p4/common/bin/replica_status.sh ${INSTANCE} > /dev/null
*/6 * * * * [ -e /p4/common/bin ] && /p4/common/bin/run_if_edge.sh ${INSTANCE} /p4/common/bin/replica_status.sh ${INSTANCE} > /dev/null

# Cache Purge on Edge servers that use lbr.replication=cache
# Comment out this line if you are not running with that config.
*/60 * * * * /p4/common/bin/run_if_edge.sh ${INSTANCE} /p4/common/bin/cacheclean.sh ${INSTANCE}

# Clean structured logs that aren't rotating
0 1 * * * [ -e /p4/common/bin ] && /p4/common/bin/run_if_replica.sh ${INSTANCE} rm -f /p4/${INSTANCE}/logs/*.csv > /dev/null