Perforce Public Knowledge Base - Recovering A Deleted Workspace
Reset Search
 

 

Article

Recovering A Deleted Workspace

« Go Back

Information

 
Problem
To restore a deleted workspace and preserve its state, you typically need to do the following:
  1. Restore the clientspec (workspace) form with its associated View mapping.
  2. Restore the workspace "have" list (using p4 sync, or restoring journal records).
  3. Re-open workspace files for add/edit/delete/integrate (as needed).
If you only need to restore the workspace form and view mapping (ignoring workspace file state), then the task is simplified to item #1 below. 
Solution

1. Restoring the Workspace View

You can restore the client specification of a workspace by either:

  • Using a saved text copy of the workspace.
  • Restoring a saved copy from a "spec"-type depot
  • Restoring metadata from a checkpoint or journal.

If you saved the contents of your workspace to a file, then you could restore the "myclient" workspace by reading the saved clientspec from that saved file. For example,saves the client specification to the file "myclient.txt":
p4 client -o myclient > myclient.txt

By contrast,  the following command reads the contents of "myclient.txt" and creates a new client worskspace, or updates an existing one.
p4 client -i < myclient.txt

If you have a Perforce depot of type "spec", edits to client workspaces (and all other Perforce forms) are automatically version controlled. In this case, you can use p4 print -q to output a versioned workspace specification, then pipe it to p4 client -i. For example:

p4 files //spec/client/...
//spec/client/myclient.p4s#2 - delete default change (ctext)

p4 print -q //spec/client/myclient.p4s#1 | p4 client -i
Client local saved.

If you do not have a saved copy of your workspace in a text file or in a spec depot, then you have to recover the associated records from an old checkpoint or journal. See the Restoring workspace information from checkpoint or journal section at the bottom of this article.

2. Restoring the Workspace "have" List

The "have" list consists of files present in your client workspace as tracked by the Perforce Server. This file list is stored in the db.have table in the Perforce Server. The "have" list is synonymous with the "sync state" of your workspace. Restoring your workspace "have" list entails either re-syncing your workspace, or recovering records from checkpoint and journals.

The quick and easy method to restore your workspace "have" list is to run the p4 sync command. For example:

p4 sync -f

The sync command re-populates your workspace with files, and updates the "have" list.

If you want to restore the "have" list to a specific time, getting this revision list requires recovering records from either a checkpoint or a journal. For example, use:

grep @db.have@ checkpoint.123 | grep //clientname > workspace.have

to gather the relevant db.have records from checkpoint.123. Then, you could read the "workspace.have" journal records into the server. For more details, see Restoring workspace information from checkpoint or journal below. Again, performing a p4 sync is generally much safer and quicker than restoring checkpoint records.

3. Restoring the Workspace File "check-out" State

As with restoring the workspace View and the workspace "have" list, it is possible to recover file check-out information for a given workspace. However, the process for finding opened file records is somewhat difficult, particularly if there were pending integrations or resolve operations. In general, it is often much safer to manually re-open files for add, edit, delete or integrate.

Restoring the current workspace check-out state is analogous to reconciling your workspace after working "offline". Steps to automate this process are discussed in Working Disconnected From The Perforce Server.


ADDENDUM: Recovering workspace information from checkpoint or journal

In general, if you need to restore records from checkpoints or journals, you should contact Perforce Support.

The following steps would recover the workspace "test-local" from the last checkpoint created, "checkpoint.86". This example is for a typical Unix based system.

1. Use the grep utility to find the client workspace:

cd $P4ROOT
grep -A1 "@db.domain@ @test-local@" checkpoint.86 | grep "@db.domain@ @test-local@\|^@" | tee test-local.txt
@pv@ 6 @db.domain@ @test-local@ 99 @bliss@ @/home/bruno/p4work/TEST/local@ @@ @@ @bruno@ 1089308159 1110422676 0 @Created by bruno.
@ @@ @@ 0

2. Next, you must extract the db.view mappings from the checkpoint using the same technique. Using the tee utility, you can write the results to a file while displaying them on standard output:
 
grep db.view checkpoint.86 | grep //test-local | tee -a test-local.txt
@pv@ 1 @db.view@ @test-local@ 0 0 @//test-local/...@ @//depot/...@ 

3. Next, extract the db.have records (this step is optional as mentioned in the "2. Restoring the Workspace have List" section):

 grep "@db.have@ @//test-local/" checkpoint.86 | tee -a test-local.txt
 @pv@ 3 @db.have@ @//test-local/test.cpp@ @//depot/test.cpp@ 1 0 1467884778

The end result should look something like the following:

cat test-local.txt 
@pv@ 6 @db.domain@ @test-local@ 99 @bliss@ @/home/bruno/p4work/TEST/local@ @@ @@ @bruno@ 1089308159 1110422676 0 @Created by bruno.
@ @@ @@ 0
@pv@ 1 @db.view@ @test-local@ 0 0 @//test-local/...@ @//depot/...@
@pv@ 3 @db.have@ @//test-local/test.cpp@ @//depot/test.cpp@ 1 0 1467884778

4. After consulting with Perforce Support, you play this journal back into your Perforce server:

p4d -r p4root -jr test-local.txt

Note: Checkpoint records only have "put" records (@pv@). Journal files have both "put", "update" (@rv@), and "delete" (@dv@) records. Extracting metadata records from journal records is more complicated than extracting records from a checkpoint. If you are interested in retrieving information from journal records, please contact Perforce Support.

Note: If you get a "Bad opcode test-local' journal record!" error when replaying the journal it is likely due to the grep command (step 1.) missing extra lines related to the db.domain record. Look at your checkpoint for the missing lines or contact Perforce Support.

Related Links

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255