Emergency! Restoring a deleted piece of content


If you delete a folder, all content under that folder gets destroyed - which means in dotCMS lingo that it is removed from the db and the /assets folder system.  One of our developers accidently deleted a folder that had a bunch of new vtls he had been working on and had no way to bring them back.  

Well, the good news is that dotCMS makes an on-disk backup of all deleted content when it is deleted out of the system.  This is an old and little known feature that can come in handy in cases like this. Here is a quick script that can help you recover the deleted contents and the files in them.

This assumes that you have found your content under the directory


using grep or some such tool.




<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="com.dotmarketing.portlets.contentlet.model.ContentletAndBinary"%>
<%@page import="com.dotmarketing.portlets.contentlet.model.Contentlet"%>
<%@page import="com.dotmarketing.util.Config"%>
<%@page import="java.io.File"%>
<%@page import="com.dotcms.repackage.com.thoughtworks.xstream.io.xml.DomDriver"%>
<%@page import="com.dotcms.repackage.com.thoughtworks.xstream.XStream"%>
XStream xstream = new XStream(new DomDriver());

File ff = new File(Config.CONTEXT.getRealPath("/dotsecure/backup/contentlets/b0482d87-b443-4da1-8ece-4fc90fecf866.xml"));

ContentletAndBinary con = (ContentletAndBinary) xstream.fromXML(new FileInputStream(ff));

byte[] myFile = (byte[]) con.BinaryFilesList.get(0).get("banner-designer.vtl");
<%= new String(myFile)%>