Page 1 of 1

Possible to export repository using Web Services?

PostPosted:Sun Mar 10, 2013 7:44 pm
by fonnerk
I was going to write a script to export the repository.... I thought that I saw a web services call in the past to export the repository but I don't see it now... Maybe I'm not remembering correctly. It is possible to export the repository with a web services call?

Re: Possible to export repository using Web Services?

PostPosted:Mon Mar 11, 2013 6:20 pm
by jllort
Is not possible, but do you want it ? which is the problem you're trying to solve, if we understand probably we can help you.

Re: Possible to export repository using Web Services?

PostPosted:Mon Mar 11, 2013 7:13 pm
by fonnerk
I am currently figuring out the best way to setup an automatic export for backup purposes (or at least I am considering using an export for document offsite backups). I thought an export would tie into my existing offsite backup system rather easily (especially if it turns out to be practical to do an export nightly).

Thanks for helping!

Re: Possible to export repository using Web Services?

PostPosted:Tue Mar 12, 2013 12:15 pm
by jllort
For execute daily I suggest use crontab -> you can do a simply shell script which executes repository export I think it can solve your problem. Take a look here http://wiki.openkm.com/index.php/Crontab ( you can test your bsh script at http://wiki.openkm.com/index.php/Scripting ).

Remember:
In crontab scenario you should use systemToken not null token.
Code: Select all
import com.openkm.module.db.stuff.DbSessionManager;
import java.io.StringWriter;
import com.openkm.util.impexp.*;
import java.io.File;

String systemToken = DbSessionManager.getInstance().getSystemToken();
String fldPath = "/okm:root";
boolean metadata = true;
boolean history = true;
StringWriter out = new StringWriter();
InfoDecorator deco = new InfoDecorator();
File file = new File("/home/openkm/export");
RepositoryExporter.exportDocuments(String systemToken, String fldPath, File fs, metadata, history, out, deco);
More complex possibility should be implement yourself:
You should use that script as the base http://wiki.openkm.com/index.php/Script ... _traversal

Re: Possible to export repository using Web Services?

PostPosted:Sat Mar 23, 2013 12:49 am
by fonnerk
Thanks... That script got me going down the right path... I have an export script starting to work after tweaking your script a bit. I am still having the following problem.

If I use the line in your script
Code: Select all
String systemToken = DbSessionManager.getInstance().getSystemToken();
I get the following error when I run the script manually (clicking on the lightning bolt in the Cron Tab Panel)...
Code: Select all
Sourced file: inline evaluation of: ``import com.openkm.module.db.stuff.DbSessionManager; import com.openkm.module.jcr . . . '' : Method Invocation RepositoryExporter.exportDocuments : at Line: 62 : in file: inline evaluation of: ``import com.openkm.module.db.stuff.DbSessionManager; import com.openkm.module.jcr . . . '' : RepositoryExporter .exportDocuments ( systemToken , categoryPath , categoryBackupDir , metadata , history , out , deco ) Target exception: com.openkm.core.AccessDeniedException: Sorry, only for admin user
If I switch that line to
Code: Select all
String systemToken = JcrSessionManager.getInstance().getSystemToken();
Than the script works great when I run it manually (clicking on the lightning bolt in the Cron Tab Panel)...

However when the configured time comes for it to run automatically, I get the following error....
Code: Select all
Sourced file: inline evaluation of: ``import com.openkm.module.db.stuff.DbSessionManager; import com.openkm.module.jcr . . . '' : Method Invocation RepositoryExporter.exportDocuments : at Line: 62 : in file: inline evaluation of: ``import com.openkm.module.db.stuff.DbSessionManager; import com.openkm.module.jcr . . . '' : RepositoryExporter .exportDocuments ( systemToken , categoryPath , categoryBackupDir , metadata , history , out , deco ) Target exception: java.lang.NullPointerException
I think this may be caused by the system token but I'm not sure.... The documentation on the two different session managers's is a little light so I am not sure of the differences between the two and which is the appropriate to use or the ramifications of using them. All I know is the DbSessionManager would not work correctly but the JcrSessionManager did when run manually. Below is my complete backup script as it stands currently if you would like to try it out yourself...
Code: Select all
import com.openkm.module.db.stuff.DbSessionManager;
import com.openkm.module.jcr.stuff.JcrSessionManager;
import java.io.StringWriter;
import com.openkm.util.impexp.*;
import java.io.File;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.apache.commons.io.FileUtils;
import java.util.ArrayList;
import java.util.List;

//String systemToken = DbSessionManager.getInstance().getSystemToken();
String systemToken = JcrSessionManager.getInstance().getSystemToken();

Date now = new Date();
SimpleDateFormat simpleDateformat = new SimpleDateFormat("EEEE"); 

String okmPath = "/okm:";
String backupDirPath = "/backup/openkmExport/" + simpleDateformat.format(now) + "/";
String currentSymLinkPath = "/backup/openkmExport/current/";

File backupDir = new File(backupDirPath);
File currentSymLink = new File(currentSymLinkPath);

//Wipe out old backup if it does not work
if (backupDir.exists()) {
    FileUtils.deleteDirectory(backupDir);
}

//Location for Root
String rootPath = okmPath + "root";
File rootBackupDir = new File(backupDirPath + "root/");

//Location for Categories
String categoryPath = okmPath + "categories";
File categoryBackupDir = new File(backupDirPath + "categories/");

//Make Directories for Backup
FileUtils.forceMkdir(rootBackupDir);
FileUtils.forceMkdir(categoryBackupDir);

boolean metadata = true;
boolean history = true;

StringWriter out = new StringWriter();
InfoDecorator deco = new DummyInfoDecorator();
ImpExpStats statsRoot, statsCat;

//Export Categories
print("Category Export\n");
//print("systemToken: " + systemToken.toString() + "\n");
print("categoryPath: " + categoryPath.toString() + "\n");
print("categoryBackupDir: " + categoryBackupDir.toString() + "\n");
print("metadata: " + metadata.toString() + "\n");
print("history: " + history.toString() + "\n");

statsCat = RepositoryExporter.exportDocuments(systemToken, categoryPath, categoryBackupDir, metadata, history, out, deco);
print(statsCat.toString() + "\n");

//Export Root
print("Root Export\n");
//print("systemToken: " + systemToken.toString() + "\n");
print("rootPath: " + rootPath.toString() + "\n");
print("rootBackupDir: " + rootBackupDir.toString() + "\n");
print("metadata: " + metadata.toString() + "\n");
print("history: " + history.toString() + "\n");
//statsRoot = RepositoryExporter.exportDocuments(systemToken, rootPath, rootBackupDir, metadata, history, out, deco);
//print(statsRoot.toString() + "\n");

//remove old symlink if neccesary
if (currentSymLink.exists()) {
    currentSymLink.delete();
}

// create symlink
List args = new ArrayList();
args.add("ln");
args.add("-s");

args.add(backupDir.getAbsolutePath());
args.add(currentSymLink.getAbsolutePath());

Process proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
proc.waitFor();

print("Export Finished!");

Re: Possible to export repository using Web Services?

PostPosted:Sun Mar 24, 2013 5:07 pm
by jllort
Which OpenKM version are you using ? you should not use String systemToken = DbSessionManager.getInstance().getSystemToken(); in version 6.x, and the package import com.openkm.module.jcr.stuff can be deleted.

Re: Possible to export repository using Web Services?

PostPosted:Thu Mar 28, 2013 10:37 am
by pavila
Forget the JcrSessionManager class when using OpenKM 6.2

Re: Possible to export repository using Web Services?

PostPosted:Fri Jul 11, 2014 7:08 am
by cjpitmd
When i use this script
Code: Select all
import com.openkm.module.db.stuff.DbSessionManager;
import Java.io.StringWriter;
import com.openkm.util.impexp.*;
import Java.io.File;

String systemToken = DbSessionManager.getInstance().getSystemToken();
String fldPath = "/okm:root";
boolean metadata = true;
boolean history = true;
StringWriter out = new StringWriter();
InfoDecorator deco = new InfoDecorator();
File file = new File("/home/openkm/export");
RepositoryExporter.exportDocuments(String systemToken, String fldPath, File fs, metadata, history, out, deco);
i get error
Code: Select all
Sourced file: inline evaluation of: ``import com.openkm.module.db.stuff.DbSessionManager; import Java.io.StringWriter . . . '' : Typed variable declaration : Class: StringWriter not found in namespace : at Line: 10 : in file: inline evaluation of: ``import com.openkm.module.db.stuff.DbSessionManager; import Java.io.StringWriter . . . '' : StringWriter 
Any suggestion ? THX

Re: Possible to export repository using Web Services?

PostPosted:Fri Jul 11, 2014 5:35 pm
by pavila
java.io.StringWriter is in Java 7. Which Java version are you using?

Re: Possible to export repository using Web Services?

PostPosted:Tue Jul 15, 2014 8:01 am
by cjpitmd
pavila wrote:Java.io.StringWriter is in Java 7. Which Java version are you using?

i have jre 7 and jdk 1.6.0_33 in my C:\program files\Java

Re: Possible to export repository using Web Services?

PostPosted:Wed Jul 16, 2014 12:25 pm
by pavila
Try with JDK 7

Re: Possible to export repository using Web Services?

PostPosted:Mon Jul 21, 2014 7:55 am
by cjpitmd
pavila wrote:Try with JDK 7

It is very weird that the script can be executed when i change the "j" to lowercase in "java.io.StringWriter;"

Re: Possible to export repository using Web Services?

PostPosted:Wed Jul 30, 2014 4:08 pm
by pavila
Well, Java is case-sensitive.