Page 1 of 1

Backup-Management of sqlite-files

Posted: Tue Jul 21, 2009 10:58 pm
by jamirokwai
Dear board,

I needed a backup-procedure for making copies of the SQLite-database used by my Application.

Features for now:
- make up to 9 copies of the current database "database.sqlite"
- put them inside a directory "backup"
- pack each file to save some space

Missing:
- recovery of files (just try yourself :)

Please adjust "Eigene Dateien" for your needs as I do not know the name on non-German Versions of Windows XP.
Please create the database-file and the backup-directory before testing this.

Code: Select all

; Snippet automated SQLite-backup with Packersupport 
; by jamirokwai - 21/July/2009

 BackupFolder$    = GetHomeDirectory() + "Eigene Dateien/backup/"               ; please adjust "Eigene Dateien"
 MyDataBasePlace$ = GetHomeDirectory() + "Eigene Dateien/database.sqlite"   ; for Mac OS X you may replace "Eigene Dateien" with "documents"

 CountBackups = 0
 WhatDate     = Date()                                                                 ; depending on the current date
 Entry$       = ""
 ExamineDirectory(0, BackupFolder$, "*.sqpak")                                         ; we like to check for "*.sqpack"-files
 While NextDirectoryEntry(0)
  CountBackups + 1
  If WhatDate > DirectoryEntryDate(0, #PB_Date_Created)                                ; check if one of the files is older than the current
   WhatDate   = DirectoryEntryDate(0, #PB_Date_Created)                                ; if so, remember the date (for more checks) and filename
   Entry$     = DirectoryEntryName(0)
  EndIf
 Wend
 FinishDirectory(0)
 If CountBackups > 9                                                                   ; Maximum of 9 current backups
  DeleteFile(BackupFolder$ + "/" + Entry$)
 EndIf
 temp$ = BackupFolder$ + "/" + FormatDate("%yyyy-%mm-%dd-%hh-%ii-%ss", Date()) + ".sqpak"  ; use current Date as filename e.g. "2009-07-21-23-47-23.sqpack"
 
 CreatePack(temp$)                                                                     ; now create a packed-file for the latest copy
 AddPackFile(MyDataBasePlace$, 9)
 ClosePack()

Posted: Wed Jul 22, 2009 2:37 am
by ColBoy
"Eigene Dateien" is "My Documents"

Colin

Posted: Wed Jul 22, 2009 8:05 am
by jamirokwai
ColBoy wrote:"Eigene Dateien" is "My Documents"

Colin
Thanks!