Mesibo Backup and Data Migration APIs
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.
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
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
String Mesibo.backupDatabase(String filePath);
backupDatabase takes the following parameters:
|fully qualified path or null for using the default path
String backupFile = Mesibo.backupDatabase(null);
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
int Mesibo.restoreDatabase(String filePath);
restoreDatabase takes the following parameters:
|fully qualified path of the backup file
int result = Mesibo.restoreDatabase(backupfile);
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.
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.
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.
Although you don't need to perform anything additional to restore files from rich messages (images, videos, audio, docs, etc.), it is worth noting that these files may be automatically re-downloaded on reading messages if they do not exist locally. If you have too many rich messages with files, it may result in a large number of downloads. This is especially true if you have freshly installed your app on a new device and then restored the mesibo database.
mesibo APIs have an internal rate limit mechanism to restrict the number of simultaneous downloads. However, it is a good practice to implement a mesibo file transfer handler so that your app can decide which files need to be downloaded automatically and which files can be downloaded later. Your file transfer handler can decide based on message age, priority, user interaction, etc. Refer to the file transfer document to learn more.