How to Recover a Deleted Document in Alfresco

When working with Alfresco, a common issue arises when you need to recover a deleted document, but the original folder where the document resided has also been deleted. In such cases, attempting to restore the document from the trashcan results in an error. This article outlines the steps to resolve this issue and provides two potential solutions.

Scenario

Let's consider the following scenario: a document named "20231204 - Sample PDF.pdf" was created under the site site-01 in the folder fldr-01. Both the document and the folder were subsequently deleted. When trying to recover the document from the trashcan, the following error is encountered:

Figure 1: Site, Folder and file

Figure 2: Deleted file in the User Trashcan

Figure 3: Error: Failed to recover 20231204 - Sample PDF.pdf

Solution 1: Restore the Original Folder

The first option is to restore the original folder where the document was located. Once the folder is restored, you can proceed to recover the document. This method works well if the folder and its contents are still needed.

Steps to Restore the Original Folder:

  1. Access the Trashcan: Navigate to the Alfresco trashcan where deleted items are stored.
  2. Locate the Folder: Find the deleted folder fldr-01 under the site site-01.
  3. Restore the Folder: Restore the folder fldr-01.
  4. Recover the Document: Once the folder is restored, find the document Check 20231204 - Sample PDF.pdf in the trashcan and restore it.

Solution 2: Use the API to Restore the Document to a New Folder

If you prefer not to restore the original folder, you can use the Alfresco REST API to restore the document to a new or different folder. This method provides flexibility to organize your content as needed.

Steps to Restore the Document to a New Folder:

  1. Create a New Folder: Create a new folder in the desired location within Alfresco. For example, you might create a new folder named fldr-02 under site-01.
  2. Get the Node ID of the New Folder: Use the Alfresco Node Browser or API to obtain the node ID of the newly created folder. In the screenshot below, it is 63c17a5f-b609-4f78-b09e-470179cfcc6d.
  3. Figure 4: New Folder to recover the file

  4. Get the Node ID of the deleted file Node ID: 3bfa289e-ba5f-4aec-b43b-7585a6415369
  5. Figure 5: Node ID of the deleted file from Trashcan

  6. Restore the Document Using the API: Use the REST API to restore the document to the new folder by specifying the targetParentId (node ID of the new folder) and the assocType (cm:contains).

REST API Request:

API reference: Alfresco Content Services REST API Explorer

Assuming the node ID of the deleted document is 3bfa289e-ba5f-4aec-b43b-7585a6415369 and the node ID of the new folder is 63c17a5f-b609-4f78-b09e-470179cfcc6d, the API request would be as follows:


Figure 6: Sample request to restore deleted nodes

Figure 7: Recovered file

Conclusion

When a document is deleted in Alfresco and the original folder is missing, you have two options to recover the document. You can either restore the original folder first and then recover the document, or you can use the Alfresco REST API to restore the document to a new folder. By following the steps outlined above, you can effectively manage and recover your content in Alfresco.

Post a comment