[opencms-dev] cron job to backup a project
Christian Schmidt
christian.schmidt at questico.de
Thu Apr 7 14:38:16 CEST 2005
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
More information about the opencms-dev
mailing list