[opencms-dev] backup-edits.jsp

Michael Emmerich m.emmerich at alkacon.com
Mon May 30 10:28:54 CEST 2011


Marko,

is there any specific reason why you do not use the DB-Management in the 
Admin View for making a backup?

With this tool, you will create a .zip file of the selected resources 
plus a manifest file which contains all the additional information about 
permission, properties etc . that belong to those resources.

Of course you can import those kind of export files again.

Kind regards,
Michael


Am 28.05.2011 02:42, schrieb Marko Riedel:
> Hello there,
>
> I'd like to share a script and ask for your opinion. Since it's only a couple of weeks that I've been working with OpenCMS I am very slowly mastering its intricacies and learning its structures and ways. It happens to me quite often that I feel the need of having a backup of my files in the file system in addition to the data in the OpenCMS database, just to be on the safe side. We corrupted our MySQL installation some weeks ago and had to redo a lot of work that was lost because there was no other backup. With this in mind I wrote a JSP that takes a directory and some files given by their VFS paths and saves the files to that directory in a folder labeled with the current date. The JSP is included with this message. Feedback is welcome, including of course suggestions of more elegant backup solutions, which I suspect are already out there, like "mysqldump".
>
> Best regards,
>
> Marko Riedel
>
> +---------------------------------------------------+
> | Marko Riedel, markoriedelde at yahoo.de              |
> | http://www.mathematik.uni-stuttgart.de/~riedelmo/ |
> +---------------------------------------------------+
>
>
> <%@ page session="false" %>
>
> <%@ page import="org.apache.commons.io.FileUtils"%>
> <%@ page import="org.opencms.frontend.templateone.CmsTemplateBean"%>
> <%@ page import="org.opencms.i18n.CmsMessages"%>
> <%@ page import="java.util.*,
>                   java.io.*,
>                   java.text.SimpleDateFormat,
>                   org.opencms.jsp.*,
>                   org.opencms.file.*,
>                   org.opencms.util.*"
> %>
> <HTML>
> <HEAD><TITLE>Backup edits</TITLE></HEAD>
> <BODY>
> <%
> String backupDir = "/home/marko/backup-opencms";
> String files[] = {"/sites/default/demo_en/index.html",
>          "/sites/default/backup-edits.jsp",
>          null};
>
>
> CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
> CmsObject cmso = cms.getCmsObject();
>
> cmso.getRequestContext().setSiteRoot("/");
>
>
>
> Locale locale = cmso.getRequestContext().getLocale();
> final String DATE_FORMAT = "yyyy-MM-dd";
> Date today = new Date();
>
> SimpleDateFormat dFormat = new SimpleDateFormat(DATE_FORMAT, locale);
> String backupRoot = backupDir + "/" + dFormat.format(today);
> try {
>          File dirinf = new File(backupRoot);
>          if(!dirinf.exists()&&  !dirinf.mkdirs()){
>                  throw new Exception("failed to create " + backupRoot);
>          }
> %>
> <H1>List of files backed up to<% out.print(backupRoot); %></H1>
> <%
>          int i = 0;
>          while(files[i] != null){
>                  out.println("<H2>" + files[i] +"</H2>\n");
>
>                  File file = new File(backupRoot + files[i]);
>
>                  dirinf = new File(file.getParent());
>                  if(!dirinf.exists()&&  !dirinf.mkdirs()){
>                          throw new Exception("failed to create " + dirinf);
>                  }
>
>                  String data = new String(cmso.readFile(files[i]).getContents());
>                  FileUtils.writeStringToFile(file, data);
>
>                  i++;
>          }
> }
> catch (Exception ex){
>          out.println(ex.getMessage());
> }
> %>
> </BODY>
> </HTML>
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev

-- 
Kind Regards,
Michael.

-------------------
Michael Emmerich

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org



More information about the opencms-dev mailing list