• How to repositoryExport with Script ?

  • 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.
 #40756  by ds2k15
 
Hello,
using the Version 6.3.1
I found one, but it did not work. http://wiki.openkm.com/index.php/Scripting_-_OpenKM_6.2 ( Cron tab exporter )
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.*;

// Configuration parameters
String LOG_FILE_NAME = "CrontabRepositoryExporter";
String repoPath = "/okm:root";
String fsPath = "/var/backups";
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(null, repoPath);
    FileLogger.info(LOG_FILE_NAME, "Files & directories to export:"+(cInfo.getDocuments() + cInfo.getFolders()));
    File dir = new File(fsPath);
    ImpExpStats stats = RepositoryExporter.exportFolder(null, repoPath, dir, metadata, history, fw, new HTMLInfoDecorator((int)
cInfo.getDocuments() + (int) cInfo.getFolders()));
    FileLogger.info("CrontabRepositoryExporter", "Finished");
} catch (Exception e) {
    if (fw!=null) {
        try {
            fw.close();
        } catch (IOException e1) {
        }
    }
}
Error:
Code: Select all
bsh.EvalError: Sourced file: inline evaluation of: ``import com.openkm.core.Config; import com.openkm.servlet.admin.BaseServlet; im . . . '' Token Parsing Error: Lexical error at line 33, column 59. Encountered: "\r" (13), after : "\"Files & directories to" : at Line: 20 : in file: inline evaluation of: ``import com.openkm.core.Config; import com.openkm.servlet.admin.BaseServlet; im . . . '' : FileWriter fw = null
If i comment out the Line:
Code: Select all
// ImpExpStats stats = RepositoryExporter.exportFolder(null, repoPath, dir, metadata, history, fw, new HTMLInfoDecorator((int) cInfo.getDocuments() + (int) cInfo.getFolders()));
then there is no error message, but no export is created

In the Log file: /opt/openkm-6.3.1-community/tomcat/logs/CrontabRepositoryExporter_20151023.log
i find this 2 lines
Code: Select all
2015-10-23 07:57:57,233 INFO  Files & directories to export:68
2015-10-23 07:57:57,233 INFO  Finished
Thanks
Last edited by ds2k15 on Fri Oct 23, 2015 9:21 am, edited 1 time in total.
 #40757  by ds2k15
 
I found another scirpt

http://forum.openkm.com/viewtopic.php?t=9386

And mixed it with the script from:

http://wiki.openkm.com/index.php/Scripting_-_OpenKM_6.2

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.DbSessionManager;
import java.io.StringWriter;
import com.openkm.util.impexp.*;
import java.text.SimpleDateFormat;
import org.apache.commons.io.FileUtils;
import java.util.ArrayList;
import java.util.List;

// Configuration parameters
String systemToken = DbSessionManager.getInstance().getSystemToken();
String okmPath = "/okm:root";
String exportPath = "/var/backups/openkm";
String LOG_FILE_NAME = "CrontabRepositoryExporter";
String repoPath = "/okm:root";
String fsPath = "/var/backups";
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(null,repoPath);
    FileLogger.info(LOG_FILE_NAME, "Files & directories to export:"+(cInfo.getDocuments() + cInfo.getFolders()));
    File dir = new File(fsPath);
    //ImpExpStats stats = RepositoryExporter.exportFolder(null, repoPath,dir, metadata, history, fw, new HTMLInfoDecorator((int)cInfo.getDocuments() +(int) cInfo.getFolders()));
    
    File backupDir = new File(exportPath);
    // Wipe out old backup if it does not work
    if (backupDir.exists()) {
        FileUtils.deleteDirectory(backupDir);
    }
    
    // Make Directories for Backup
    File rootBackupDir = new File(exportPath);
    FileUtils.forceMkdir(rootBackupDir);
    boolean metadata = true;
    boolean history = true;
    StringWriter out = new StringWriter();
    InfoDecorator deco = new DummyInfoDecorator();
    ImpExpStats statsRoot, statsCat;
    
    // Export Root
    print("Root Export\n");
    // print("systemToken: " + systemToken.toString() + "\n");
    print("okmPath: " + okmPath.toString() + "\n");
    print("rootBackupDir: " + rootBackupDir.toString() + "\n");
    print("metadata: " + metadata.toString() + "\n");
    print("history: " + history.toString() + "\n");
    statsRoot = RepositoryExporter.exportDocuments(systemToken, okmPath,rootBackupDir, metadata, history, out, deco);
    print(statsRoot.toString() + "\n");
    //print("Export Finished!");   
        
    FileLogger.info("CrontabRepositoryExporter", "Finished");
} catch (Exception e) {
    if (fw!=null) {
        try {
            fw.close();
        } catch (IOException e1) {
        }
    }
}

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.