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 allString 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 allSourced 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 allString 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 allSourced 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 allimport 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!");