• Automate "Export to ZIP"

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
OpenKM has many interesting features, but requires some configuration process to show its full potential.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #21713  by mariot
 
I would like to perform a daily backup of all documents into a zip file so that the document directory structure and the document names are the same as what is displayed in the OpenKM application (taxonomy tab). The only way I can achieve this is by executing the "Export to ZIP" option in the OpenKM application. Is there any way to automate this export rather than relying on someone to issue the command with in the application? Although the export does not extract user/role information, my main concern is that just backing up the repository directory only provides a backup of folders and documents in a cryptic format. Should there be a disaster (eg. database becomes corrupted) and a document needs to extracted quickly then the last exported zip file can be used rather than waiting for someone to restore the entire database from the last backup.

I am running the Windows version of OpenKM 6.2.2 community and using mySQL as the backend database.
 #21734  by jllort
 
I think you have not take a look export utility with pacience because you can export all contents and metadata in a human format. If you go to export utility http://wiki.openkm.com/index.php/Repository_export you have two aditional checkbox to export metadata and history. By default will be exported the same structure ( folder / documents ) as you see in OpenKM to some server folder. Aditional if you check metadata will be generated .okm files which have grants, and other metadata information. If you check history then will be exported all document versions like document_name_version.doc otherside you'll get exported only the actual document version.

I think a crontab based on export utility will be better than .zip, we'll be waiting your feedback.
 #42291  by silverspr
 
HI jllort
Can you provide instructions on how to do this: set up a scheduled cron job to export the repository as per your recommendation below. I'm using the openkm community version.
thanks
 #42330  by silverspr
 
Hi jllort
Ok this portable version is not the easiest to configure and seems like a lot of work for what I perceive to be a simple script (if I knew how to write it!!). Isn't there a script you can point me to?

Having said that, I found a script here:
http://wiki.openkm.com/index.php/Script ... b_exporter

The instructions are lacking, can this script be used? I tried pasting it into the Administration, Scripting utility in OpenKM but it throws errors....
could it be as simple changing the export folder path in the script and saving as a .bsh script on a Linux server then upload to the crontab scheduler internal to OpenKM?? oh please let it be so!

thanks
 #42338  by jllort
 
The script can be saved as bsh and imported into crontab. But before if the script is raising some error should be corrected. We are actually at the end of finishing the 6.3 documentation at docs.openkm.com there all the scripts will be reviewed and checked again.
 #42342  by silverspr
 
HI, thanks
I've taken the script as is, only changing the backup location to "\mnt\mylocation"
uploaded to Crontab through the administration module. these are the errors from the error log when I try execute:
Code: Select all
2016-10-01 19:16:23,398 [http-bio-0.0.0.0-8080-exec-6] WARN  com.openkm.core.Cron- Error executing crontab task 'repository backup': bsh.EvalError: Sourced file: inline evaluation of: ``import com.openkm.util.FileLogger;  import com.openkm.bean.ContentInfo;  import  . . . '' : Typed variable declaration : Error in method invocation: Static method exportFolder(null, java.lang.String, java.io.File, boolean, boolean, java.io.FileWriter, com.openkm.util.impexp.HTMLInfoDecorator) not found in class'com.openkm.util.impexp.RepositoryExporter' : at Line: 31 : in file: inline evaluation of: ``import com.openkm.util.FileLogger;  import com.openkm.bean.ContentInfo;  import  . . . '' : RepositoryExporter .exportFolder ( null , repoPath , dir , metadata , history , fw , new HTMLInfoDecorator ( ( int ) cInfo .getDocuments ( ) + ( int ) cInfo .getFolders ( ) ) ) 

2016-10-01 19:16:23,402 [http-bio-0.0.0.0-8080-exec-6] WARN  com.openkm.core.Cron- Error sending mail: Sourced file: inline evaluation of: ``import com.openkm.util.FileLogger;  import com.openkm.bean.ContentInfo;  import  . . . '' : Typed variable declaration : Error in method invocation: Static method exportFolder(null, java.lang.String, java.io.File, boolean, boolean, java.io.FileWriter, com.openkm.util.impexp.HTMLInfoDecorator) not found in class'com.openkm.util.impexp.RepositoryExporter' : at Line: 31 : in file: inline evaluation of: ``import com.openkm.util.FileLogger;  import com.openkm.bean.ContentInfo;  import  . . . '' : RepositoryExporter .exportFolder ( null , repoPath , dir , metadata , history , fw , new HTMLInfoDecorator ( ( int ) cInfo .getDocuments ( ) + ( int ) cInfo .getFolders ( ) ) ) 
Its all greek to me...is there something else I'm to upload ? filewriter
thanks
 #42343  by jllort
 
Try with it, I just updated on what will be new documentation:
Code: Select all
import com.openkm.util.FileLogger;
import com.openkm.bean.ContentInfo;
import com.openkm.api.*;
import com.openkm.util.impexp.*;
import java.io.*;
import java.text.*;
import com.openkm.core.Config;
import java.util.*;
import com.openkm.module.db.stuff.*;
 
// Configuration parameters
String token = DbSessionManager.getInstance().getSystemToken();
String LOG_FILE_NAME = "CrontabRepositoryExporter";
String repoPath = "/okm:root";
String fsPath = "F:\\Restore_OKM";
boolean metadata = false;
boolean history = false;
 
// Start
FileWriter fw = null;
try {
    FileLogger.info(LOG_FILE_NAME, "Started");
    // Open outputstream
    String fileDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
    String fileName = Config.LOG_DIR + File.separator + LOG_FILE_NAME + "_" + fileDate + ".log";
    File file = new File(fileName); 
    fw = new FileWriter(file);
    // Starting the process
    ContentInfo cInfo = OKMFolder.getInstance().getContentInfo(token, repoPath);
    FileLogger.info(LOG_FILE_NAME, "Files & directories to export:"+(cInfo.getDocuments() + cInfo.getFolders()));
    File dir = new File(fsPath);
    ImpExpStats stats = RepositoryExporter.exportDocuments(token, repoPath, dir, metadata, history, fw, new HTMLInfoDecorator((int) cInfo.getDocuments() + (int) cInfo.getFolders()));
    FileLogger.info("CrontabRepositoryExporter", "Finished");
} catch (Exception e) {
    try {        if (fw != null) {
            fw.close();        }
    } catch (IOException e1) {        // Ignore
    }
}
 #42344  by silverspr
 
HI jllort
Sweet, it works, you can cross this procedure off your list of to do's!
I think I know the answer to this however here goes: will this cron job run only if OpenKM is open/running, or can it run in the background as long as tomcat/catalina service is running? I guess I'll schedule it and see what happens without connecting directly to OpenKM via localhost:8080.
Thanks again for all your help

Ok it works with the service running only...all good excellent. Thanks again. This issue is solved...
ss
 #42347  by jllort
 
Althought you are not accessing to OpenKM with localhost:8080 or ip etc... the OpenKM is running and crontab is a service executed from tomcat view ( is not necessary to being logged for it be executed ).
 #45908  by cherifmad
 
jllort wrote: Sun Oct 02, 2016 5:13 pm Try with it, I just updated on what will be new documentation:
Code: Select all
import com.openkm.util.FileLogger;
import com.openkm.bean.ContentInfo;
import com.openkm.api.*;
import com.openkm.util.impexp.*;
import java.io.*;
import java.text.*;
import com.openkm.core.Config;
import java.util.*;
import com.openkm.module.db.stuff.*;
 
// Configuration parameters
String token = DbSessionManager.getInstance().getSystemToken();
String LOG_FILE_NAME = "CrontabRepositoryExporter";
String repoPath = "/okm:root";
String fsPath = "F:\\Restore_OKM";
boolean metadata = false;
boolean history = false;
 
// Start
FileWriter fw = null;
try {
    FileLogger.info(LOG_FILE_NAME, "Started");
    // Open outputstream
    String fileDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
    String fileName = Config.LOG_DIR + File.separator + LOG_FILE_NAME + "_" + fileDate + ".log";
    File file = new File(fileName); 
    fw = new FileWriter(file);
    // Starting the process
    ContentInfo cInfo = OKMFolder.getInstance().getContentInfo(token, repoPath);
    FileLogger.info(LOG_FILE_NAME, "Files & directories to export:"+(cInfo.getDocuments() + cInfo.getFolders()));
    File dir = new File(fsPath);
    ImpExpStats stats = RepositoryExporter.exportDocuments(token, repoPath, dir, metadata, history, fw, new HTMLInfoDecorator((int) cInfo.getDocuments() + (int) cInfo.getFolders()));
    FileLogger.info("CrontabRepositoryExporter", "Finished");
} catch (Exception e) {
    try {        if (fw != null) {
            fw.close();        }
    } catch (IOException e1) {        // Ignore
    }
}
Please I would like to Know if it is a beanshell code? And in this script ["String fsPath = F:\\Restore_OKM";] represent the location ( the path) where the backup will do it ?
Can I create a folder path if I want ?
 #45927  by jllort
 
Confirmed, is a BeanShell code. The variable fsPath might be File System Path ( destination ).
 #45937  by cherifmad
 
jllort wrote: Thu May 24, 2018 7:20 am Confirmed, is a BeanShell code. The variable fsPath might be File System Path ( destination ).
Thank you
I would like to know if this code should be executed in the OpenKM community version's Script tools or if this script should be saved in a bsh file to be executed in crontab?
 #45959  by jllort
 
Can be executed from both sides.
 #45969  by cherifmad
 
jllort wrote: Sun Oct 02, 2016 5:13 pm Try with it, I just updated on what will be new documentation:
Code: Select all
import com.openkm.util.FileLogger;
import com.openkm.bean.ContentInfo;
import com.openkm.api.*;
import com.openkm.util.impexp.*;
import java.io.*;
import java.text.*;
import com.openkm.core.Config;
import java.util.*;
import com.openkm.module.db.stuff.*;
 
// Configuration parameters
String token = DbSessionManager.getInstance().getSystemToken();
String LOG_FILE_NAME = "CrontabRepositoryExporter";
String repoPath = "/okm:root";
String fsPath = ",F:\\Restore_OKM";
boolean metadata = false;
boolean history = false;
 
// Start
FileWriter fw = null;
try {
    FileLogger.info(LOG_FILE_NAME, "Started");
    // Open outputstream
    String fileDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
    String fileName = Config.LOG_DIR + File.separator + LOG_FILE_NAME + "_" + fileDate + ".log";
    File file = new File(fileName); 
    fw = new FileWriter(file);
    // Starting the process
    ContentInfo cInfo = OKMFolder.getInstance().getContentInfo(token, repoPath);
    FileLogger.info(LOG_FILE_NAME, "Files & directories to export:"+(cInfo.getDocuments() + cInfo.getFolders()));
    File dir = new File(fsPath);
    ImpExpStats stats = RepositoryExporter.exportDocuments(token, repoPath, dir, metadata, history, fw, new HTMLInfoDecorator((int) cInfo.getDocuments() + (int) cInfo.getFolders()));
    FileLogger.info("CrontabRepositoryExporter", "Finished");
} catch (Exception e) {
    try {        if (fw != null) {
            fw.close();        }
    } catch (IOException e1) {        // Ignore
    }
}
Thanks @Jlort.
This script is good. But it does not compress all files (File, folders and metadata) into Zip files.
How can I do that?

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.