Backing up SQL table at the end of month

Hi All,
      I need to backup a table in an sqlite database and I want to do this at the end every month. How would I get delphi to check it is the end of the month and back up the table (ie DUMP data_backup).
lloydie-tAsked:
Who is Participating?
 
shaneholmesConnect With a Mentor Commented:
Here is a link to backuping up SQL database or tables

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20691981.html?query=sql+backup&searchType=topic


here is a function to test for End Of Month:

Function Eom(Dt:TDateTime):Boolean;
VAR Y,M,D:Word;
Begin
  DecodeDate(Dt,Y,M,D);
  D := 1;
  Inc(M);
  If M > 12 then
    Begin
    Inc(Y);
    M := 1
    End;
Result := Trunc(Dt) = Trunc(EncodeDate(Y,M,D)-1);  
End;

example

if EOM then
begin
 //run backup query here
end;

Hope this helps!

SHane
0
 
lloydie-tAuthor Commented:
Hi shane,
            that looks great. Does the above code automaically test for end of the month. If not how would I? Some sort of timer?
0
 
shaneholmesCommented:
You need to call it as i described above - like this

if EOM then
begin
 //run backup query here
end;

You could use a timer to test the time, if its a certain time of day say 1:00 pm,
test for EOM

set the interval for 60000 - to test every minute (or whatever you like)


Shane

0
 
Ivanov_GCommented:

   make it in stand alone excutable and put it in scheduled task for Windows or in cron daemon for Unix/Linux. Your application should be aware of the backup routines ....
0
 
lloydie-tAuthor Commented:
Ivanov, I had thought of that, but I need to stop some processes in the main application before backing up the database. So therefore I prefered to do the backup in the main application.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.