How to backup a sqlite3 database lazarus / 16-Databases ---------------------------------------------------------------------- pedro756901 · 2015-12-08 02:27 Hi All I am trying to backup a sqlite3 db, below is code snippet but it can't work. The problem is that the output backup file size is zero. Attached is a mini-project Thank you for your help. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button3Click(Sender: TObject);var  backup:TSQLite3Backup;begin  if (Edit1.Text<>'') and (Edit2.Text<>'') then  begin    backup:=TSQLite3Backup.Create ;    backup.OnBackupProgress:=@OnBackupProgress ;    backup.Backup(SQLite3ConnSource,Edit2.Text,false,Edit1.Text);  //  backup.Free ;  end;end; procedure TForm1.OnBackupProgress(Sender: TObject; Remaining, PageCount: integer  );begin  Label3.Caption:=IntToStr(Remaining);  Label4.Caption:=IntToStr(PageCount);end; ---------------------------------------------------------------------- LacaK · 2015-12-08 06:13 What do you write in Edit1.Text and Edit2.Text ? Edit1.Text should be name of dababase to backup i.e. 'main' Edit2.Text should be name of file to which backup ---------------------------------------------------------------------- pedro756901 · 2015-12-08 07:46 I have selected "ImageTest.db3" in Edit1.Text and inputed "backup.db" in Edit2.Text ---------------------------------------------------------------------- mirce.vladimirov · 2015-12-08 11:48 What exectly does this TSQLite3Backup do ? SQLite databases are stored in one physical file, my backup of SQLite db's is simple, i just copy the file. Or even send it via emails attachment or via FTP or SSH's scp... ---------------------------------------------------------------------- rvk · 2015-12-08 12:39 Quote from: mirce.vladimirov on December 08, 2015, 12:48:34 pmWhat exectly does this TSQLite3Backup do ? It can copy/replicate a sqlite3 database while it is in use. It will create a current snapshot. (it uses the sqlite3_backup api) You can't do that with a physical copy. Although note the warning: Quote    //The backup process will restart when another process writes to the database.     //Pro: the backup is a correct snapshot     //Contra: the backup can take a very long time when a lot of writes to the database are made during backup More info: https://www.sqlite.org/backup.html ---------------------------------------------------------------------- LacaK · 2015-12-08 17:48 Quote from: pedro756901 on December 08, 2015, 08:46:52 amI have selected "ImageTest.db3" in Edit1.Text and inputed "backup.db" in Edit2.Text IMO it is not good. Try write in 1st edit: main 2nd edit: backup.db ---------------------------------------------------------------------- rvk · 2015-12-09 08:43 Quote from: LacaK on December 08, 2015, 06:48:39 pmQuote from: pedro756901 on December 08, 2015, 08:46:52 amI have selected "ImageTest.db3" in Edit1.Text and inputed "backup.db" in Edit2.Text IMO it is not good. Try write in 1st edit: main 2nd edit: backup.db Confirmed. The SourceDB-name should be "main". You've already connected the SQLite3ConnSource to ImageTest.db3 so you don't need to provide that name again. In fact... The SourceDBName parameter in the Backup-call has a default "main" so all you need is this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button3Click(Sender: TObject);var  backup: TSQLite3Backup;begin  SQLite3ConnSource.DatabaseName := 'ImageTest.db3'; // connect to source-db  SQLite3ConnSource.Open;  backup := TSQLite3Backup.Create;  try    backup.OnBackupProgress := @OnBackupProgress;    backup.Backup(SQLite3ConnSource, 'backup.db', False);  finally    backup.Free;  end;end; ---------------------------------------------------------------------- pedro756901 · 2015-12-10 02:10 It works successfully, thank you all for the help, specially, thanks to rvk for the code snippet. Quote from: rvk on December 09, 2015, 09:43:55 amQuote from: LacaK on December 08, 2015, 06:48:39 pmQuote from: pedro756901 on December 08, 2015, 08:46:52 amI have selected "ImageTest.db3" in Edit1.Text and inputed "backup.db" in Edit2.Text IMO it is not good. Try write in 1st edit: main 2nd edit: backup.db Confirmed. The SourceDB-name should be "main". You've already connected the SQLite3ConnSource to ImageTest.db3 so you don't need to provide that name again. In fact... The SourceDBName parameter in the Backup-call has a default "main" so all you need is this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button3Click(Sender: TObject);var  backup: TSQLite3Backup;begin  SQLite3ConnSource.DatabaseName := 'ImageTest.db3'; // connect to source-db  SQLite3ConnSource.Open;  backup := TSQLite3Backup.Create;  try    backup.OnBackupProgress := @OnBackupProgress;    backup.Backup(SQLite3ConnSource, 'backup.db', False);  finally    backup.Free;  end;end;