• Possible to export repository using Web Services?

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
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.
 #21657  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?
 #21671  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!
 #21681  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
 #21810  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!");
 #21822  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.
 #29232  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

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.