Hallo everyone,
I'm writing a report about create a backup for a selected database via backupDatabase().
Here is my code:
var g_startTime = new Date();
function main()
{
var ADB = ArisData.getActiveDatabase();
var oFile;
var oDbAdmin;
var sPath = "C://Userdata";
var sFile = "WorkDB_"+getTimeStampAsString();
Context.setSelectedPath(sPath);
Context.setSelectedFile(sFile);
oFile = new java.io.File(sPath, sFile);
dbAdmin = Context.getComponent("ServerAdmin");
if(dbAdmin.backupDatabase(ADB,oFile)){
Dialogs.MsgBox("Work DB"+" was backed up on "+new Date());
}else{
Dialogs.MsgBox("Work DB"+" could not be backed up on "+new Date());
}
return;
}
function getTimeStampAsString() {
var date = g_startTime;
return date.getFullYear() + "_" +
((parseInt(date.getMonth())+1)>9 ? '' : '0') + (parseInt(date.getMonth())+1) + "_" +
(date.getDate()>9 ? '' : '0') + date.getDate() + "_" +
(date.getHours()>9 ? '' : '0') + date.getHours() + "_" +
(date.getMinutes()>9 ? '' : '0') + date.getMinutes() + "_" +
(date.getSeconds()>9 ? '' : '0') + date.getSeconds()
}
main();
But somehow the function backupDatabase() always return false. Could anyone give some suggestions?
Thanks a lot.
Hello,
I have exactly the same problem . I run my code on the local server.
If I backup the database manually, the backup can be successfully created. I want to save the backup into this folder "C:\UserData\Documents\ARIS 10", where all the Aris created files (doc, xls) are saved. Aris client should have access to the folder since it can write doc files into this folder.
Thank you very much in advance!
Try the following changed script:
var g_startTime = new Date();
function main()
{
var ADB = ArisData.getActiveDatabase();
var oFile;
var oDbAdmin;
var lOutput = Context.createOutputObject()
var sPath = lOutput.getCurrentPath().getPath();
lOutput.WriteReport()
Context.deleteFile(Context.getSelectedFile())
var sFile = "WorkDB_"+getTimeStampAsString();
//Context.setSelectedPath(sPath);
//Context.setSelectedFile(sFile);
oFile = new java.io.File(sPath, sFile);
dbAdmin = Context.getComponent("ServerAdmin");
if(dbAdmin.backupDatabase(ADB,oFile)){
Dialogs.MsgBox("Work DB"+" was backed up on "+new Date());
Context.addOutputFileName(sFile)
}else{
Dialogs.MsgBox("Work DB"+" could not be backed up on "+new Date());
}
return;
}
function getTimeStampAsString() {
var date = g_startTime;
return date.getFullYear() + "_" +
((parseInt(date.getMonth())+1)>9 ? '' : '0') + (parseInt(date.getMonth())+1) + "_" +
(date.getDate()>9 ? '' : '0') + date.getDate() + "_" +
(date.getHours()>9 ? '' : '0') + date.getHours() + "_" +
(date.getMinutes()>9 ? '' : '0') + date.getMinutes() + "_" +
(date.getSeconds()>9 ? '' : '0') + date.getSeconds()
}
main();
Kind regards, Ariene Kroeze