public class

BackupKit

extends Object
java.lang.Object
   ↳ com.tencent.wcdb.repair.BackupKit

Class Overview

Data backup toolkit based on table traversal.

Summary

Constants
int FLAG_FIX_CORRUPTION Flag indicates when database corruption detected, try to read more data if possible rather than return failure immediately.
int FLAG_INCREMENTAL Flag indicates incremental backup is performed.
int FLAG_NO_CIPHER Flag indicates no encryption is used on backup data.
int FLAG_NO_COMPRESS Flag indicates no compression is used on backup data.
int FLAG_NO_CREATE_TABLE Flag indicates no "CREATE TABLE" statement should be output to backup file.
int RESULT_CANCELED Result code that indicates operation has been cancelled.
int RESULT_FAILED Result code that indicates operation failure.
int RESULT_OK Result code that indicates successful operation.
Public Constructors
BackupKit(SQLiteDatabase db, String outPath, byte[] key, int flags, String[] tableDesc)
Create and initialize a backup task.
Public Methods
void cancel()
Cancel the current running backup operation.
String lastError()
Get the last error message.
void release()
Cleanup and release this backup task.
int run()
Run backup task.
int statementCount()
Retrieve total count of statements had been output during the last time run() was called.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int FLAG_FIX_CORRUPTION

Flag indicates when database corruption detected, try to read more data if possible rather than return failure immediately.

Constant Value: 4 (0x00000004)

public static final int FLAG_INCREMENTAL

Flag indicates incremental backup is performed. Incremental backup appends new data to the end of the backup file instead of overwriting. Use this flag with conditional backup to implement incremental backup.

Constant Value: 16 (0x00000010)

public static final int FLAG_NO_CIPHER

Flag indicates no encryption is used on backup data.

Constant Value: 1 (0x00000001)

public static final int FLAG_NO_COMPRESS

Flag indicates no compression is used on backup data.

Constant Value: 2 (0x00000002)

public static final int FLAG_NO_CREATE_TABLE

Flag indicates no "CREATE TABLE" statement should be output to backup file. When backup file created this way is being recovered, it won't execute "CREATE TABLE" or "CREATE INDEX" statement.

Constant Value: 8 (0x00000008)

public static final int RESULT_CANCELED

Result code that indicates operation has been cancelled.

Constant Value: 1 (0x00000001)

public static final int RESULT_FAILED

Result code that indicates operation failure.

Constant Value: -1 (0xffffffff)

public static final int RESULT_OK

Result code that indicates successful operation.

Constant Value: 0 (0x00000000)

Public Constructors

public BackupKit (SQLiteDatabase db, String outPath, byte[] key, int flags, String[] tableDesc)

Create and initialize a backup task.

Conditional or incremental backup can be implemented by passing non-null to tableDesc argument.

tableDesc should be array with length of a multiple of 2. The elements with even index are table name white-list to be backed up. Tables not listed are ignored. The elements with odd index are condition expression used in WHERE-clause when data to be backed up is selected, which can be null to indicate unconditional selection.

For example, the array listed below tells to backup only the whole contact table and message table with column id greater than 100.


     new String[] {
         "contact", null,
         "message", "id > 100",
     };
 

Parameters
db database to be backed up.
outPath path to the output backup file.
key key for backup file encryption. Pass null to skip encryption.
flags flags to the backup operation.
tableDesc table description for conditional backup.
Throws
SQLiteException when backup operation cannot be initialized.
IllegalArgumentException when outPath is null.

Public Methods

public void cancel ()

Cancel the current running backup operation.

This method can be called on threads other than the one called run() Calling this method causes run() to interrupt as quickly as possible and return RESULT_CANCELED

public String lastError ()

Get the last error message.

Returns
  • last error message, can be null.

public void release ()

Cleanup and release this backup task. No further operations should be done on this object after calling it.

public int run ()

Run backup task.

Note: this method will not return until backup is finished or cancelled. Do not call this method directly on the main thread or it will probably cause ANR.

Returns

public int statementCount ()

Retrieve total count of statements had been output during the last time run() was called.

Returns
  • statement count had been output.