Page 1 of 2

Automate "Export to ZIP"

PostPosted:Thu Mar 14, 2013 1:35 pm
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.

Re: Automate "Export to ZIP"

PostPosted:Sat Mar 16, 2013 8:33 am
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.

Re: Automate "Export to ZIP"

PostPosted:Sun Sep 18, 2016 2:32 pm
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

Re: Automate "Export to ZIP"

PostPosted:Tue Sep 20, 2016 3:09 pm
by jllort
First of all get openkm portable edition running https://sourceforge.net/projects/openkmportabledev/ there's a crontab example. When you success on get it running, we will continue with other steps.

Re: Automate "Export to ZIP"

PostPosted:Fri Sep 30, 2016 1:40 am
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

Re: Automate "Export to ZIP"

PostPosted:Sat Oct 01, 2016 8:19 am
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.

Re: Automate "Export to ZIP"

PostPosted:Sun Oct 02, 2016 1:30 am
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

Re: Automate "Export to ZIP"

PostPosted:Sun Oct 02, 2016 5:13 pm
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
    }
}

SOLVED: Automate "Export to ZIP"

PostPosted:Sun Oct 02, 2016 6:57 pm
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

Re: Automate "Export to ZIP"

PostPosted:Tue Oct 04, 2016 7:15 am
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 ).

Re: Automate "Export to ZIP"

PostPosted:Tue May 22, 2018 10:56 pm
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 ?

Re: Automate "Export to ZIP"

PostPosted:Thu May 24, 2018 7:20 am
by jllort
Confirmed, is a BeanShell code. The variable fsPath might be File System Path ( destination ).

Re: Automate "Export to ZIP"

PostPosted:Thu May 24, 2018 10:47 am
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?

Re: Automate "Export to ZIP"

PostPosted:Sat May 26, 2018 7:22 am
by jllort
Can be executed from both sides.

Re: Automate "Export to ZIP"

PostPosted:Sat May 26, 2018 4:22 pm
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?