add reboot v1.2.4 table backup function
parent
36462a8b3c
commit
e2aa4f8af2
|
@ -62,6 +62,8 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
typedef short int sint;
|
typedef short int sint;
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
|
|
92
src/func.c
92
src/func.c
|
@ -19,12 +19,14 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include "tvm.h"
|
#include "tvm.h"
|
||||||
|
|
||||||
/************************************************************************************************
|
/************************************************************************************************
|
||||||
function
|
function
|
||||||
************************************************************************************************/
|
************************************************************************************************/
|
||||||
extern void vCondInsInit(FdCond *pstCond, TABLE t);
|
extern void vCondInsInit(FdCond *pstCond, TABLE t);
|
||||||
|
extern long _lDumpTable(SATvm *pstSavm, TABLE t, char *pszFile);
|
||||||
|
|
||||||
/*************************************************************************************************
|
/*************************************************************************************************
|
||||||
description:dump the unused
|
description:dump the unused
|
||||||
|
@ -100,6 +102,96 @@ long lUnuseDump(SATvm *pstSavm, TABLE t)
|
||||||
return RC_SUCC;
|
return RC_SUCC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************************************************************************************************
|
||||||
|
description:exit and backup tables
|
||||||
|
parameters:
|
||||||
|
pstSavm --stvm handle
|
||||||
|
return:
|
||||||
|
RC_SUCC --success
|
||||||
|
RC_FAIL --failure
|
||||||
|
*************************************************************************************************/
|
||||||
|
long lBackupTables(SATvm *pstSavm)
|
||||||
|
{
|
||||||
|
size_t lOut = 0, i;
|
||||||
|
char szFile[512];
|
||||||
|
TIndex *pstIndex = NULL;
|
||||||
|
|
||||||
|
memset(szFile, 0, sizeof(szFile));
|
||||||
|
if(RC_SUCC != lExportTable(SYS_TVM_INDEX, &lOut, (void *)&pstIndex))
|
||||||
|
return RC_FAIL;
|
||||||
|
|
||||||
|
snprintf(szFile, sizeof(szFile), "%s/backup", getenv("TVMDBD"));
|
||||||
|
if(0 != mkdir(szFile, S_IRWXU | S_IRGRP))
|
||||||
|
{
|
||||||
|
if(EEXIST != errno)
|
||||||
|
{
|
||||||
|
vRedeError(pstSavm->m_lErrno = 127, strerror(errno));
|
||||||
|
return RC_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < lOut; i ++)
|
||||||
|
{
|
||||||
|
if((TYPE_SYSTEM == pstIndex[i].m_lType || TYPE_INCORE == pstIndex[i].m_lType) &&
|
||||||
|
SYS_TVM_SEQUE != pstIndex[i].m_table)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
memset(szFile, 0, sizeof(szFile));
|
||||||
|
snprintf(szFile, sizeof(szFile), "%s/backup/%d.sdb", getenv("TVMDBD"),
|
||||||
|
pstIndex[i].m_table);
|
||||||
|
_lDumpTable(pstSavm, pstIndex[i].m_table, szFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
TFree(pstIndex);
|
||||||
|
|
||||||
|
return RC_SUCC;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************************************
|
||||||
|
description:boot and restore tables
|
||||||
|
parameters:
|
||||||
|
pstSavm --stvm handle
|
||||||
|
return:
|
||||||
|
RC_SUCC --success
|
||||||
|
RC_FAIL --failure
|
||||||
|
*************************************************************************************************/
|
||||||
|
long lRestoreTables(SATvm *pstSavm)
|
||||||
|
{
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *pr;
|
||||||
|
char szPath[512], szFile[128];
|
||||||
|
|
||||||
|
memset(szPath, 0, sizeof(szPath));
|
||||||
|
memset(szFile, 0, sizeof(szFile));
|
||||||
|
snprintf(szPath, sizeof(szPath), "%s/backup", getenv("TVMDBD"));
|
||||||
|
if ((NULL == (dir = opendir(szPath))))
|
||||||
|
{
|
||||||
|
vRedeError(pstSavm->m_lErrno = 127, strerror(errno));
|
||||||
|
return RC_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(pr = readdir(dir))
|
||||||
|
{
|
||||||
|
if (NULL == strcasestr(pr->d_name, ".sdb"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(DT_REG != pr->d_type)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
memset(szFile, 0, sizeof(szFile));
|
||||||
|
snprintf(szFile, sizeof(szFile), "%s/%s", szPath, pr->d_name);
|
||||||
|
if(RC_SUCC != lMountTable(pstSavm, szFile))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Warning:restore table failed, %s",
|
||||||
|
sGetTError(pstSavm->m_lErrno));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
return RC_SUCC;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
code end
|
code end
|
||||||
|
|
63
src/stvm.c
63
src/stvm.c
|
@ -38,6 +38,8 @@ extern char **environ;
|
||||||
extern long lShutdownTvm();
|
extern long lShutdownTvm();
|
||||||
extern void vSetNode(char *s);
|
extern void vSetNode(char *s);
|
||||||
extern long lStartupTvm(TBoot *pstBoot);
|
extern long lStartupTvm(TBoot *pstBoot);
|
||||||
|
extern long lBackupTables(SATvm *pstSavm);
|
||||||
|
extern long lRestoreTables(SATvm *pstSavm);
|
||||||
extern long lMountTable(SATvm *pstSavm, char *pszFile);
|
extern long lMountTable(SATvm *pstSavm, char *pszFile);
|
||||||
extern long lUnuseDump(SATvm *pstSavm, TABLE t);
|
extern long lUnuseDump(SATvm *pstSavm, TABLE t);
|
||||||
|
|
||||||
|
@ -4019,7 +4021,8 @@ long lExecuteTvm(SATvm *pstSavm, char *pszSQL)
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
long lStartSystem(TBoot *pstBoot, char *pszMode)
|
long lStartSystem(TBoot *pstBoot, char *pszMode)
|
||||||
{
|
{
|
||||||
Benum eMode = 0;
|
long i, n;
|
||||||
|
Benum eMode = 0, eRestore = 0;
|
||||||
SATvm *pstSavm = (SATvm *)pGetSATvm();
|
SATvm *pstSavm = (SATvm *)pGetSATvm();
|
||||||
|
|
||||||
if(0 != access(getenv("TVMCFG"), R_OK))
|
if(0 != access(getenv("TVMCFG"), R_OK))
|
||||||
|
@ -4029,26 +4032,50 @@ long lStartSystem(TBoot *pstBoot, char *pszMode)
|
||||||
return RC_FAIL;
|
return RC_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pszMode && !strcmp(pszMode, "o")) // offline
|
for(i = 0, n = NULL == pszMode ? 0 : strlen(pszMode); i < n; i ++)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "Warning:TVM will start offline\n");
|
switch(pszMode[i])
|
||||||
fflush(stdout);
|
{
|
||||||
eMode = 1;
|
case 'o': // offline
|
||||||
|
fprintf(stdout, "Warning:STVM will start offline ...\n");
|
||||||
|
eMode = 1;
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
fprintf(stdout, "STVM will do not restore tables ...\n");
|
||||||
|
eRestore = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!bIsTvmBoot())
|
if(!bIsTvmBoot())
|
||||||
{
|
{
|
||||||
if(RC_SUCC != lStartupTvm(pstBoot))
|
if(RC_SUCC != lStartupTvm(pstBoot))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "failed to boot TVM, %s\n", sGetTError(pstSavm->m_lErrno));
|
fprintf(stderr, "failed to boot TVM, %s\n", sGetTError(pstSavm->m_lErrno));
|
||||||
return RC_FAIL;
|
return RC_FAIL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(RC_SUCC != lBootLocal(pstSavm, pstBoot, eMode))
|
if(RC_SUCC != lBootLocal(pstSavm, pstBoot, eMode))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "failed to boot LIS, %s\n", sGetTError(pstSavm->m_lErrno));
|
||||||
|
return RC_SUCC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(0 == eRestore && lRestoreTables(pstSavm))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "restore tables failed, %s\n", sGetTError(pstSavm->m_lErrno));
|
||||||
|
return RC_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "failed to boot LIS, %s\n", sGetTError(pstSavm->m_lErrno));
|
if(RC_SUCC != lBootLocal(pstSavm, pstBoot, eMode))
|
||||||
return RC_SUCC;
|
{
|
||||||
|
fprintf(stderr, "failed to boot LIS, %s\n", sGetTError(pstSavm->m_lErrno));
|
||||||
|
return RC_SUCC;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "start TVM : (%s)\n", sGetTError(pstSavm->m_lErrno));
|
fprintf(stderr, "start TVM : (%s)\n", sGetTError(pstSavm->m_lErrno));
|
||||||
|
@ -4105,6 +4132,12 @@ long lStopSystem(TBoot *pstBoot, char *pszApp)
|
||||||
|
|
||||||
if(!bIsTvmBoot()) return RC_SUCC;
|
if(!bIsTvmBoot()) return RC_SUCC;
|
||||||
|
|
||||||
|
if(RC_SUCC != lBackupTables(pstSavm))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "backup tables failed, %s\n", sGetTError(pstSavm->m_lErrno));
|
||||||
|
return RC_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
if(RC_SUCC != lShutdownTvm())
|
if(RC_SUCC != lShutdownTvm())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "showdown node failed, %s\n", sGetTError(pstSavm->m_lErrno));
|
fprintf(stderr, "showdown node failed, %s\n", sGetTError(pstSavm->m_lErrno));
|
||||||
|
|
25
src/tree.c
25
src/tree.c
|
@ -11084,10 +11084,9 @@ void _vDumpQueue(SATvm *pstSavm, void *pvAddr, FILE *fp)
|
||||||
RC_SUCC --success
|
RC_SUCC --success
|
||||||
RC_FAIL --failure
|
RC_FAIL --failure
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
long lDumpTable(SATvm *pstSavm, TABLE t)
|
long _lDumpTable(SATvm *pstSavm, TABLE t, char *pszFile)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
char szFile[512];
|
|
||||||
RunTime *pstRun = NULL;
|
RunTime *pstRun = NULL;
|
||||||
|
|
||||||
if(!pstSavm)
|
if(!pstSavm)
|
||||||
|
@ -11096,7 +11095,6 @@ long lDumpTable(SATvm *pstSavm, TABLE t)
|
||||||
return RC_FAIL;
|
return RC_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(szFile, 0, sizeof(szFile));
|
|
||||||
if(RC_SUCC != lInitSATvm(pstSavm, t))
|
if(RC_SUCC != lInitSATvm(pstSavm, t))
|
||||||
return RC_FAIL;
|
return RC_FAIL;
|
||||||
|
|
||||||
|
@ -11109,8 +11107,7 @@ long lDumpTable(SATvm *pstSavm, TABLE t)
|
||||||
return RC_FAIL;
|
return RC_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(szFile, sizeof(szFile), "%s/%d.sdb", getenv("TVMDBD"), t);
|
if(NULL == (fp = fopen(pszFile, "wb")))
|
||||||
if(NULL == (fp = fopen(szFile, "wb")))
|
|
||||||
{
|
{
|
||||||
pstSavm->m_lErrno = FILE_NOT_RSET;
|
pstSavm->m_lErrno = FILE_NOT_RSET;
|
||||||
return RC_FAIL;
|
return RC_FAIL;
|
||||||
|
@ -11131,6 +11128,24 @@ long lDumpTable(SATvm *pstSavm, TABLE t)
|
||||||
return RC_SUCC;
|
return RC_SUCC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*************************************************************************************************
|
||||||
|
description:Dump table
|
||||||
|
parameters:
|
||||||
|
pstSavm --stvm handle
|
||||||
|
t --table
|
||||||
|
return:
|
||||||
|
RC_SUCC --success
|
||||||
|
RC_FAIL --failure
|
||||||
|
*************************************************************************************************/
|
||||||
|
long lDumpTable(SATvm *pstSavm, TABLE t)
|
||||||
|
{
|
||||||
|
char szFile[512];
|
||||||
|
|
||||||
|
memset(szFile, 0, sizeof(szFile));
|
||||||
|
snprintf(szFile, sizeof(szFile), "%s/%d.sdb", getenv("TVMDBD"), t);
|
||||||
|
return _lDumpTable(pstSavm, t, szFile);
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************************************
|
/*************************************************************************************************
|
||||||
description:lMountTable
|
description:lMountTable
|
||||||
parameters:
|
parameters:
|
||||||
|
|
Loading…
Reference in New Issue