Automate "Export to ZIP"

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.
mariot
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: Fri Mar 01, 2013 3:42 am

Automate "Export to ZIP"

Post by mariot » Thu Mar 14, 2013 1:35 pm

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.

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Automate "Export to ZIP"

Post by jllort » Sat Mar 16, 2013 8:33 am

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.

silverspr
Expert Boarder
Expert Boarder
Posts: 80
Joined: Thu Aug 21, 2014 12:58 pm

Re: Automate "Export to ZIP"

Post by silverspr » Sun Sep 18, 2016 2:32 pm

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

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Automate "Export to ZIP"

Post by jllort » Tue Sep 20, 2016 3:09 pm

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.

silverspr
Expert Boarder
Expert Boarder
Posts: 80
Joined: Thu Aug 21, 2014 12:58 pm

Re: Automate "Export to ZIP"

Post by silverspr » Fri Sep 30, 2016 1:40 am

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

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Automate "Export to ZIP"

Post by jllort » Sat Oct 01, 2016 8:19 am

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.

silverspr
Expert Boarder
Expert Boarder
Posts: 80
Joined: Thu Aug 21, 2014 12:58 pm

Re: Automate "Export to ZIP"

Post by silverspr » Sun Oct 02, 2016 1:30 am

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

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Automate "Export to ZIP"

Post by jllort » 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
    }
}

silverspr
Expert Boarder
Expert Boarder
Posts: 80
Joined: Thu Aug 21, 2014 12:58 pm

SOLVED: Automate "Export to ZIP"

Post by silverspr » Sun Oct 02, 2016 6:57 pm

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

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Automate "Export to ZIP"

Post by jllort » Tue Oct 04, 2016 7:15 am

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 ).

cherifmad
Junior Boarder
Junior Boarder
Posts: 37
Joined: Tue Apr 03, 2018 6:22 pm

Re: Automate "Export to ZIP"

Post by cherifmad » Tue May 22, 2018 10:56 pm

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 ?

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Automate "Export to ZIP"

Post by jllort » Thu May 24, 2018 7:20 am

Confirmed, is a BeanShell code. The variable fsPath might be File System Path ( destination ).

cherifmad
Junior Boarder
Junior Boarder
Posts: 37
Joined: Tue Apr 03, 2018 6:22 pm

Re: Automate "Export to ZIP"

Post by cherifmad » Thu May 24, 2018 10:47 am

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?

jllort
Moderator
Moderator
Posts: 10830
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: Automate "Export to ZIP"

Post by jllort » Sat May 26, 2018 7:22 am

Can be executed from both sides.

cherifmad
Junior Boarder
Junior Boarder
Posts: 37
Joined: Tue Apr 03, 2018 6:22 pm

Re: Automate "Export to ZIP"

Post by cherifmad » Sat May 26, 2018 4:22 pm

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?

Post Reply