[opencms-dev] backup-edits.jsp

Michael Emmerich m.emmerich at alkacon.com
Tue May 31 15:44:40 CEST 2011


Marko,

as Eska wrote, there are the Scheduled Jobs in OpenCms which work more 
or less like a cron job. You can start a Java-Class (implementing the 
I_CmsScheduledJob) interface like a cron job.

There are several pre-defined jobs in OpenCms already, but none for 
doing a backup so far.

Kind regards,
Michael


Am 31.05.2011 15:33, schrieb Marko Riedel:
>
> Hello again,
>
> that was exactly what I was looking for. I have not had a course on OpenCMS or else the teacher would have told me about this feature. I tried it just now and it does exactly what I want. Thanks!
>
> Too bad that OpenCMS does not have a cron mechanism, or a mechanism whereby a login by the administrator triggers certain scripts. That way I wouldn't have to do the backups manually. Or do you have a solution for that as well? Like submitting the form data with a script instead of the HTML GUI?
>
> Best regards,
>
> Marko
>
> +---------------------------------------------------+
> | Marko Riedel, markoriedelde at yahoo.de              |
> | http://www.mathematik.uni-stuttgart.de/~riedelmo/ |
> +---------------------------------------------------+
>
>
> --- Michael Emmerich<m.emmerich at alkacon.com>  schrieb am Mo, 30.5.2011:
>
>> Von: Michael Emmerich<m.emmerich at alkacon.com>
>> Betreff: Re: [opencms-dev] backup-edits.jsp
>> An: "The OpenCms mailing list"<opencms-dev at opencms.org>
>> Datum: Montag, 30. Mai, 2011 10:28 Uhr
>> 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
>>
>> _______________________________________________
>> 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
>>
>
> _______________________________________________
> 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