[opencms-dev] cron job to backup a project

Rafael Diaz Valdes Rafael.Diaz.Valdes at cern.ch
Thu Apr 7 19:36:09 CEST 2005


Hi Christian 
 I have some problems to compile the class, 
I import com.opencms.flex.jsp, com.opencms.file and com.opencms.workplace  using opencms.jar ut there are some class that I can find
       1- I_CmsScheduledJob
       2-ExtendedProperties
       3 CmsModuleManager
       4  CmsModule
      5 CmsModuleImportExportHandler
      6 CmsExportThread
I'm using opencms 5.0.1 fat distribution do you know where could I find the jar for these class
 
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: 10214 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20050407/9d0f6699/attachment.bin>


More information about the opencms-dev mailing list