Mesibo Backup and Data Migration APIs

Estimated reading time: 3 minutes

Mesibo backup and data migration APIs allow you to regularly backup your users’ data (messages, call history, profiles, settings, etc) and then restore it when needed, for example, when the user moves to another device.

In addition to backup and restore, mesibo provides APIs to know when the last backup was taken, and the age of the database so that you can decide when to initiate the next backup as required by your app or organization policies.

Once you take a backup, you can upload the backup file to your servers so that you can download it when needed. Once the backup data is uploaded, you should delete them so that they do not occupy space on users’ devices.

Backup and Data Migration APIs are currently only available for Android, iOS, C++, and Python, and not for Javascript.

Initiating a Backup

You can initiate a backup by calling backupDatabase API with the file name or the complete path of the file. If you do not supply any file name (null), API will use the default name backup.db. If the backup is successful, the backupDatabase will return the fully qualified path of the file where the backup is stored. If not, it will return null.

Not that the destination file will be overwritten and all the previous content will be lost. mesibo offers online backup and hence you can initiate a backup even when the app is running. While the backup process is usually fast, it is important to note that the database will be locked and it will stall all the write operations. Hence, it is recommended to initiate a backup after calling setDatabase API but before calling start API.

String Mesibo.backupDatabase(String filePath);

backupDatabase takes the following parameters:

Parameter Description
filePath fully qualified path or null for using the default path

For example,

Mesibo.setDatabase('myapp.db');
String backupFile = Mesibo.backupDatabase(null);
Mesibo.start();

Restoring from a Backup

You can restore the user data from a backup by calling restoreDatabase with the complete path of the backup file. The restoreDatabase will return 0 for success or the negative value (error code) for any error. The restoreDatabase checks if the backup belongs to the same user as currently configured and restores only if they match.

Note, if you need to restore a backup, you MUST restore after calling setDatabase API but before calling start API. Do not restore after calling start API.

int Mesibo.restoreDatabase(String filePath);

restoreDatabase takes the following parameters:

Parameter Description
filePath fully qualified path of the backup file

For example,

Mesibo.setDatabase('myapp.db');
int result = Mesibo.restoreDatabase(backupfile);
Mesibo.start();

Scheduling Regular Backups

You can schedule backups at the regular interval by knowing when the last backup was taken. You can know about the last backup by calling backupAge API. It returns the number of seconds since the last backup or -1 if the backup was not initiated so far.

For example,

int age = Mesibo.backupAge();

In addition, you can also use the age of the database, that is when the database was first initialized, to avoid taking backup the very first time.

For example,

int age = Mesibo.databaseAge();

Note that the databaseAge was not available in the older APIs and hence it will return the database age since using the new APIs.

message backup, restore, migration