[opencms-dev] cron job to backup a project

Rafael Diaz Valdes Rafael.Diaz.Valdes at cern.ch
Thu Apr 7 15:02:19 CEST 2005


thanks a lot Christian 

I'll try

regards
Rafael


-----Original Message-----
From:	opencms-dev-bounces at opencms.org on behalf of Christian Schmidt
Sent:	Thu 4/7/2005 2:38 PM
To:	opencms-dev at opencms.org
Cc:	
Subject:	Re: [opencms-dev] cron job to backup a project
Hi,

 >  I have to create a cron job to backup a project and a module in
 > opencms, do you know how to do it?

what I did to backup a module through a cron job:
(we're using ocms 5.3.6)
- create a scheduler-entry in config/opencms-system.xml:
e.g.
   <scheduler>
     <job>
       <name>Module Export Job</name>
       <class>your.package.YourClass</class>
       <reuseinstance>false</reuseinstance>
       <cronexpression><![CDATA[0 20 02 * * ?]]></cronexpression>
       <context>
         <user>Admin</user>
         <project>Online</project>
         <siteroot>/sites/default/</siteroot>
         <requesteduri/>
         <locale>de</locale>
         <encoding>UTF-8</encoding>
         <remoteaddr>127.0.0.1</remoteaddr>
       </context>
       <parameters>
         <param name="someParameter">someValue</param>
     </job>
     ...
   </scheduler>
- create a class that implements I_CmsScheduledJob, e.g.

public class YourClass implements I_CmsScheduledJob {

   public String launch(CmsObject cms, ExtendedProperties parameters) 
throws Exception {
     if (OpenCms.getLog(this).isDebugEnabled()) {
       OpenCms.getLog(this).debug("Starting module export DUMMY (dummy 
coz we're in debug-mode)");
     } else {
       OpenCms.getLog(this).error("Starting module export...");
       CmsModuleManager moduleManager = OpenCms.getModuleManager();
       CmsModule cmsModule = moduleManager.getModule( "some.module.name" );
       if( moduleManager.hasModule( "some.module.name" ) && cmsModule != 
null ) {
         String filename = "some.module.name.zip";
         OpenCms.getLog(this).info("... exporting module 
some.module.name to "+filename+"...");
         CmsModuleImportExportHandler moduleExportHandler = new 
CmsModuleImportExportHandler();
         moduleExportHandler.setModuleName( "some.module.name" );
         StringTokenizer st = new StringTokenizer( 
cmsModule.getParameter( "additionalresources" ), ";" );
         String[] additionalResources = new String[ st.countTokens() ];
         int j = 0;
         while( st.hasMoreTokens() ) {
           additionalResources[j++] = (String)st.nextToken();
         }
         moduleExportHandler.setAdditionalResources( additionalResources );
         moduleExportHandler.setFileName( filename );
         synchronized( this ) {
           try {
             CmsExportThread moduleExportThread = new CmsExportThread( 
cms, moduleExportHandler );
             moduleExportThread.run();
             while( moduleExportThread.isAlive() ) {
               // do nothing
               wait(2000);
             }
           } catch( Exception e ) {
             OpenCms.getLog(this).error( "Exception during module 
export: "+e.getMessage() );
             e.printStackTrace();
           }
         }
         OpenCms.getLog(this).info("finished exporting module.");
       }
     }
     return null;
   }
}
- deploy your class, restart your tomcat and have fun :)

hth,
regards,
Christian



_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://mail.opencms.org/mailman/listinfo/opencms-dev



-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 4067 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20050407/8c9a08d8/attachment.bin>


More information about the opencms-dev mailing list