I wonder if someone could help me with 'sqlurestore' available in the DB/2 Administrative API? Below is the 'C' code I have written which is compiled into a Windows DLL and called from Java code using JNI. The code is similar to the sample available in \SQLLIB\samples\c\backrest.c. The backup works fine, but when I try to restore the database, the 'sqlca' structure returns with an error code = -1022. This error code appears to me that there is insufficient memory. I have even tried closing all applications, re-booting the machine and checking the memory. There is definitely enough memory.
Operating system : Windows XP Pro
Processor : P4-M 1.6GHz
RAM : 384MB
/*----------------------------------------------
* bkupdll.c - Source file for a C DLL
*----------------------------------------------*/
#include "jni.h"
#include "sqlutil.h"
#include "sqlenv.h"
#include "DbUtil.h"
#include <stdio.h>
#include <string.h>
JNIEXPORT jstring JNICALL Java_com_vdmsystems_util_backup_DbUtil_backup(JNIE nv *env, jobject obj, jstring destPath) {
const char *dbDir = (*env)->GetStringUTFChars(env, destPath, 0);
char errMsg[128];
char dbAlias[] = "TEST";
char userId[] = "DBUSER";
char password[] = "PASSWORD";
unsigned long buff_size = 16;
unsigned long num_buff = 1;
struct sqlu_tablespace_bkrst_list *tablespace_list;
struct sqlca sqlca;
struct sqlu_media_entry media_entry;
struct sqlu_media_list media_list;
char applid[SQLU_APPLID_LEN + 1];
char timestamp[SQLU_TIME_STAMP_LEN + 1];
tablespace_list = NULL;
media_list.media_type = 'L';
media_list.sessions = 1;
strcpy(media_entry.media_entry, dbDir);
media_list.target.media = &media_entry;
sqlubkp(
dbAlias,
buff_size,
SQLUB_OFFLINE,
SQLUB_FULL,
SQLUB_BACKUP,
applid,
timestamp,
num_buff,
tablespace_list,
&media_list,
userId,
password,
NULL,
0,
NULL,
1,
NULL,
NULL,
NULL,
&sqlca);
if (sqlca.sqlcode != SQL_RC_OK) {
sprintf(errMsg, "error = %d", sqlca.sqlcode);
return (*env)->NewStringUTF(env, errMsg);
}
return (*env)->NewStringUTF(env, timestamp);
}
JNIEXPORT jstring JNICALL Java_com_vdmsystems_util_backup_DbUtil_restore(JNI Env *env, jobject obj, jstring path, jstring timestamp) {
const char *dbDir = (*env)->GetStringUTFChars(env, path, 0);
const char *dbTimestamp = (*env)->GetStringUTFChars(env, timestamp, 0);
char restoreTimestamp[SQLU_TIME_STAMP_LEN + 1];
char errMsg[128];
char dbAlias[] = "TEST";
char userId[] = "DBUSER";
char password[] = "PASSWORD";
unsigned long buff_size = 1024;
unsigned long num_buff = 1;
struct sqlu_tablespace_bkrst_list *tablespace_list;
struct sqlca sqlca;
struct sqlu_media_entry media_entry;
struct sqlu_media_list media_list;
char applid[SQLU_APPLID_LEN + 1];
char *target_path;
strcpy(restoreTimestamp, dbTimestamp);
tablespace_list = NULL;
media_list.media_type = 'L';
media_list.sessions = 1;
strcpy(media_entry.media_entry, dbDir);
media_list.target.media = &media_entry;
sqlurestore(
dbAlias,
dbAlias,
buff_size,
SQLUD_NOROLLFWD,
SQLUD_DATALINK,
SQLUD_FULL,
SQLUD_OFFLINE,
SQLUD_NOINTERRUPT, // restore without user interaction
applid,
restoreTimestamp,
target_path,
num_buff,
NULL,
tablespace_list,
&media_list,
userId,
password,
NULL,
0,
NULL,
1,
NULL,
NULL,
NULL,
&sqlca);
// SQLUD_NOINT_WARNINGS occurs with SQLUD_NOINTERRUPT above but database still successfully restores
if ((sqlca.sqlcode != SQL_RC_OK) && (sqlca.sqlcode != SQLUD_NOINT_WARNING)) {
sprintf(errMsg, "error = %d", sqlca.sqlcode);
return (*env)->NewStringUTF(env, errMsg);
} else {
sprintf(errMsg, "");
}
return (*env)->NewStringUTF(env, errMsg);
}