#1 2014-01-23 17:46:05

ebaptistella
Member
From: Santa Catarina
Registered: 2014-01-23
Posts: 9

TSQLRestServerDB backup and restore SQLite

Hi!

I'm testing the backup and restore available in TSQLRestServerDB class and am having some problems, I wonder if I'm using the correct form!
Problem: My support is not restored, this code causes the restoration is canceled:

if (Self=nil) or (DB=nil)  or not IdemPChar(pointer(ContentToRestore),'SQLITE FORMAT 3')  then
    exit; // invalid restore contente

In unit mORMotSQLite3

I use this code to execute the backup:

procedure TForm2.Button6Click(Sender: TObject);
var
  sBackupName: String;
  oFileBackup: TStream;
begin
  sBackupName := '.\database\'+FormatDateTime('yyyymmddHHmmsszzz', Now)+'_' + ExtractFileName(oServer.DB.FileName) + '.bkp';

  oFileBackup := TFileStream.Create(sBackupName,  fmCreate);

  if (oServer.Backup(oFileBackup)) then
    Memo1.Lines.Add('Backup: ' + oServer.DB.FileName + ' -> ' + sBackupName);

  oFileBackup.Free;
end;

And this is the code that execute the restore:

procedure TForm2.Button9Click(Sender: TObject);
begin
  // EdtBackup contains the path to the backup file
  if (oServer.Restore(EdtBackup.Text)) then
    Memo1.Lines.Add('Restore: ' + EdtBackup.Text + ' -> ' + oServer.DB.FileName);
end;

What am I doing wrong?
My database has 110MB...

Thanks...

Offline

#2 2014-01-23 19:12:34

ebaptistella
Member
From: Santa Catarina
Registered: 2014-01-23
Posts: 9

Re: TSQLRestServerDB backup and restore SQLite

I have more problems, now with TSQLRestServerDB.BackupGZ(), we executed four backups:
- Database with 1,05 GB -> Generate Backup file with 106 MB - Is OK
- Database with 2,77 GB -> Generate Backup file with 273 MB - Is OK
- Database with 3,95 GB -> Generate Backup file with 388 MB - Is OK
- Database with 5,13 GB -> Generate Backup file with 502 MB - Is OK

Now the restoration using TSQLRestServerDB.RestoreGZ():
- Backup file with 106 MB -> Generate database file with 1,05 GB - Is OK
- Backup file with 273 MB -> NOT GENERATE DATABASE (not restored)
- Backup file with 388 MB  -> NOT GENERATE DATABASE (not restored)
- Backup file with 502 MB  -> NOT GENERATE DATABASE (not restored)

If I'm debugging the application I get the following notification:
EAssertionFailed with message ‘Assertion failure (d:\mORMot\lib\SynZip.pas, line 1122)’

If I run the demo application (execute .exe) the exception is not presented (reported), but the backup is not restored.
Do you have any suggestions?

Thanks!

Offline

#3 2014-01-23 20:32:56

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,273
Website

Re: TSQLRestServerDB backup and restore SQLite

Backup/restore is not working as expected, due to problems of SQLite3 itself when you use virtual tables (as our mORMot core does).
We reported it several times on the forum.

The easiest is to backup/restore it at file level, before opening and after closing the database.
You can find in our SynZip unit all you need for it.
Or use the SynLZ compression functions available in SynCommons, if you want something faster.

Offline

#4 2014-02-17 13:48:47

dorival
Member
From: Brasil
Registered: 2013-04-17
Posts: 35

Re: TSQLRestServerDB backup and restore SQLite

Hello AB,

Can I use journal or walmode to implement a real-time backup?

I would like to restore a database using a physical backup plus a journal or wal file.

Is it possible (that even with the problems in backup / restore process sqlite already reported)?

Offline

#5 2014-02-17 16:08:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,273
Website

Re: TSQLRestServerDB backup and restore SQLite

Sadly, AFAIK the SQLite3 WAL journal is not meant at all for backup purpose, but for better performance within a transaction scope...

Offline

Board footer

Powered by FluxBB