#!/usr/bin/perl -w #******************************************************************************* # Name : rename_depot.pl # Author : Tony Smith # Date : 8 September 2000 # Description : This script allows a system administrator to rename a # Perforce depot whilst preserving all of it's history. # This is acheived through careful editing of a # checkpoint file. The steps needed to run it successfully # are: # # 1. Shut down your Perforce server # 2. Checkpoint your database # 3. Backup database and checkpoint # 4. Run rename depot: # # rename_depot.pl oldname newname \ # checkpoint_file > newckpfile # # 5. Delete your existing database (db.*) files # 6. Use p4d -jr to restore the new checkpoint file. # # Supported Versions # ------------------ # # So far, this script has only been tested on 99.2 # databases, so use with caution on other versions. # #******************************************************************************* use Carp; use strict; sub croaksyntax() { print("\n"); print("Usage: rename_depot.pl oldname newname [checkpoint] > newcheckpoint\n"); print("\n"); print(" If no checkpoint file is supplied as input, data is read\n"); print(" from standard input. Output is always written to stdout.\n"); print("\n"); exit(0); } my $oldname = shift or croaksyntax(); my $newname = shift or croaksyntax(); my @fields; while ( <> ) { s/\/\/$oldname\//\/\/$newname\//g; # Rename the domain record providing it has not already been used. if ( /\@db\.domain\@/ ) { @fields = split; if ( $fields[3] eq "\@$oldname\@" ) { if ( $fields[4] != 100 ) { croak("$newname is already in use as a label, " . "clientspec or branchspec. Can't rename."); } $fields[3] = "\@$newname\@"; $_ = join(' ', @fields, "\n"); } } # Rename the depot record. if ( /\@db\.depot\@/ ) { @fields = split; if ( $fields[3] eq "\@$oldname\@" ) { $fields[3] = "\@$newname\@"; $_ = join(' ', @fields, "\n"); } } print; }