[SCM]源碼管理 – perforce的備份和最佳化指令碼

來源:互聯網
上載者:User
一 perforce server的備份

perforce server擁有checkpoint機制用來備份server的database。checkpoint,versioned files,journal(只從上次checkpoint後對server的操作)是恢複perforce server的所有的東西。

我們每天晚上建立checkpoint,然後備份versioned files。以防萬一我們需要儲存幾個checkpoints。下面是在Linux上備份perforce server的checkpoint和journal的指令碼:

#!/bin/bash
BACKUP_DIR=/home/p4/backup
DEPOT_DIR=/home/p4/srvroot
P4=/opt/p4/p4
HOST=p4:1666
USER=root
PASSWORD=password
DAYS_TO_KEEP=3

# Verify the depot
$P4 -p $HOST -u $USER -P $PASSWORD verify -q //… > /dev/null
$P4 -p $HOST -u $USER -P $PASSWORD verify -u -q //… > /dev/null 2> /dev/null

# Take a checkpoint
$P4 -p $HOST -u $USER -P $PASSWORD admin checkpoint > /dev/null

# Move all journal and checkpoint files to the backup folder
mv $DEPOT_DIR/journal.* $BACKUP_DIR
mv $DEPOT_DIR/checkpoint.* $BACKUP_DIR

# Remove old checkpoint and journal files
find $BACKUP_DIR/journal.* -mtime +$DAYS_TO_KEEP -exec rm -f {} \; > /dev/null 2> /dev/null
find $BACKUP_DIR/checkpoint.* -mtime +$DAYS_TO_KEEP -exec rm -f {} \; > /dev/null 2> /dev/null

二 perforce server的最佳化

perforce server在運行一段時間後段變慢,可以通過重新匯入checkpoint來最佳化。

為了完成最佳化perforce server。需要建立checkpoint,停止server,使用checkpoint恢複,然後再啟動server。

下列的指令碼用來最佳化perforce server:# This script describes a way of optimizing and cleaning the metadata for a Perforce server

# The following steps are copied from the following URL:
# ? <http://blog.perforce.com/blog/?p=187>

# ? Stop your server
# ? Take a checkpoint
# ? Move your existing db files to a save directory
# ? Recover from the checkpoint
# ? Check for errors during restore
# ? Restart your server
# ? Delete the files from the save directory

# Instead of deleting the old database files immediately after the process, we
# delete them during the next run instead.

BACKUP_DIR=/home/p4/backup
DEPOT_DIR=/home/p4/srvroot
P4D=/opt/p4/p4d
LOG_FILE=/var/log/p4d-error

# ? Take a checkpoint
echo "Taking a checkpoint…"
/opt/scripts/p4d/makecheckpoint.sh

# ? Stop your server
echo "Stopping the Perforce server…"
/etc/init.d/p4d stop

# ? Delete the files from the save directory
echo "Backing up current database…"
rm -R $BACKUP_DIR/db

# ? Move your existing db files to a save directory
mkdir $BACKUP_DIR/db
mv $DEPOT_DIR/db.* $BACKUP_DIR/db/

# ? Recover from the checkpoint
CHECKPOINT_FILE=`ls -h –sort=time $BACKUP_DIR/checkpoint* | head -1`

echo "Do you wish to restore from checkpoint '$CHECKPOINT_FILE'?"
select yn in "Yes" "No"; do
  case $yn in
    Yes ) echo "Restoring checkpoint…"; su p4 -c "$P4D -r $DEPOT_DIR -L $LOG_FILE -jr $CHECKPOINT_FILE"; break;;
    No ) echo "Optimization aborted; restoring previous database…"; mv $BACKUP_DIR/db/db.* $DEPOT_DIR/; break;;
  esac
done

# ? Restart your server
/etc/init.d/p4d start

三 使用off-line perforce server作備份,來減少main server的停機時間

1)手動建立off-line perforce server
cd C:\P4ROOT
p4d -r C:\P4ROOT -jc
copy C:\P4ROOT\checkpoint.NNN D:\Offline_P4ROOT\checkpoint.NNN
p4d -r D:\Offline_P4ROOT -jr checkpoint.NNN

2)每天對main server進行journal,將老的journal應用到off-line perforce server,然後對off-line perforce server建立checkpoint,最後備份此checkpoint,從而達到對main server備份的作用。
p4d -r C:\P4ROOT -jj D:\Offline_P4ROOT\truncated\journal
p4d -r D:\Offline_P4ROOT -jr .\truncated\journal.jnl.XXX
p4d -r D:\Offline_P4ROOT -jd checkpoint.mmddyyyy

注意: 此時journal使用-jj參數(不能用-jr),表示不建立checkpoint,只是將當前的journal,儲存為journal.xxx,然後建立新的journal檔案來記錄新的操作。 因為不建立checkpoint,所以mainserver此時也不需要lock了。

3)從2010.2 後的版本,我們可以建立replicated server(包含replicated database[metadata]和 versioned files)來作為off-line的server用作備份,從而減少對main server的lock時間。同時replicated server還可以用來作為唯讀server減少main server的負載,或作為main server的熱備份當main server停機後直接啟動replicated server。

參考:

http://blogs.encodo.ch/news/view_folder.php?id=14http://kb.perforce.com/article/126/offline-checkpoints

完!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.