B4A Library [CLASS] clsSQLiteBackups

Description: A class to manage the backup of SQLite files.
It allows you to manage backup SQLite database files, set the maximum number of backups to keep, create backups at any time and with any name (with a field for an additional note) or set an automatic backup: daily, weekly or monthly.

Depends on: KeyValueStore (which in turn depends on RandomAccessFile).

* Note: you should declare (and initialize) a global variable named KVStore as KeyValueStore in the Process_Globals of the Main activity (or elsewhere, but in this case, you should modify the references in these sub routines: Initialize, LoadBackupMap and SaveBackupMap).


Main methods:

- CreateBackup(BackupName As String, Note As String) As Boolean
Creates a db backup.

- RestoreFromBackup(BackupName As String) As Boolean
Restores the db from a backup.

- DeleteBackup(BackupName As String) As Boolean
Deletes a backup file.

- LoadBackupMap *
Gets the backup map from the KeyValueStore.

- SaveBackupMap *
Puts the backup map in to the KeyValueStore.

- FillListView(lvw As ListView)
Fills the listview passed as a parameter with the descriptive data of the backup files

- ReadSettings
Reads: max number of backups, Automatic state and period

-
SaveSettings
Saves: max number of backups, Automatic state and period

Properties:

- MaxBackups
Sets/Gets max number of backups.

- BkpInfos
Gets a map as follows:
Backup names are the Keys;
Objects of type typBkpInfo are the values.

- Auto
Sets/Gets the periodically automated setting ON/OFF.

- AutoPeriod
Sets/Gets the periodically automated period.
Period can be: AUTO_DAILY, AUTO_WEEKLY, AUTO_MONTHY



Type:

- typBkpInfo(Created As Long, Note As String)
Created: the creation date;
Note: a description for the backup.



[I have not tested the attached sample completely]


Tags: Backup
 

Attachments

  • clsSQLiteBackup.zip
    3.2 KB · Views: 614
  • clsSQLiteBackupsTest.zip
    22.1 KB · Views: 600
Last edited:

rboeck

Well-Known Member
Licensed User
Longtime User
Questions and ideas for backup: how can one choose a location? I think an backup in the same place like the database is only usefull for some situations like database corruption. In an app i enabled database backup to email, usb stick an sd card.
Thanks.
 

LucaMs

Expert
Licensed User
Longtime User
Questions and ideas for backup: how can one choose a location? I think an backup in the same place like the database is only usefull for some situations like database corruption. In an app i enabled database backup to email, usb stick an sd card.
Thanks.

You are right, but you forgot the cases where the user accidentally deletes important data and wants to recover them.
 

incendio

Well-Known Member
Licensed User
Longtime User
Dear LucaMs,

Thanks for this class, it is a great help for me.

I have a few questions about this class :
1) About daily auto backup, when this is triggers? When class is initialized? Can this set to off?
2) Can I backup data from one device and restore it to another device?

Thanks.
 

LucaMs

Expert
Licensed User
Longtime User
1) there is a routine named "ManageAuto" which is called from Inizialize. The class must be initialized at the start of the app.

This routine compares the current date to the date of the last automatic backup made (the name of the automaci backup files are composed of "auto_" + ticks date)


2) This is the main problem.
The class allows the backup into the device but not elsewhere.
This "elsewhere", on the other hand, could be many "things".

I decided I had to think of what to implement for this problem, but then I suspended.

I gladly accept suggestions/changes ;)
 
Last edited:

incendio

Well-Known Member
Licensed User
Longtime User
To restore to other device, maybe, upload backup & log data to the cloud, and then on other device, download from cloud then do the restore.

Just my idea:)
 
Top