Page 1 of 1

How to repositoryExport with Script ?

PostPosted:Fri Oct 23, 2015 5:15 am
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

[solved] Re: How to repositoryExport with Scirpt ?

PostPosted:Fri Oct 23, 2015 7:13 am
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) {
        }
    }
}

Re: How to repositoryExport with Script ?

PostPosted:Sat Oct 24, 2015 6:30 pm
by jllort
It goes right now for you ?