Topic: [Script] Automatic backup database

In the folder "backup" creates a backup copy of the database "backup_data_[TIME].db" when entering\exit the program, and every three hours.


var
   Timer: TTimer;
   iSeconds: integer;

procedure Form1_OnShow (Sender: string; Action: string);
begin
     CopyFile('sqlite.db', 'backup/backup '+ FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.db');

     Timer := TTimer.Create (Form1);
     Timer.Interval := 1000;
     Timer.Enabled := True;
     Timer.OnTimer := @OnTimer;
end;

procedure Form1_OnClose (Sender: string; Action: string);
begin
     CopyFile('sqlite.db', 'backup/backup '+ FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.db');
     Timer.Free;
end;


procedure OnTimer;
begin
     iSeconds := iSeconds + 1;
     if iSeconds > 10800 then // backup every 3 hours (10800 seconds)
     begin
          iSeconds := 0;
          CopyFile('sqlite.db', 'backup/backup '+ FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.db');
     end;
end;


begin
end.


Download project:
http://myvisualdatabase.com/forum/misc. … download=1

Dmitry.

Re: [Script] Automatic backup database

Thank you very much.Even If I don't know a lot from programming it is almost very helpful with the example that sent me.
Could you please if this Line is common wih all programs? "(Sender: string; Action: string);"
And if I would like to restore the database from back up,how I should do that?
Thank you again for helping me with this.

Re: [Script] Automatic backup database

voukefalas76 wrote:

Thank you very much.Even If I don't know a lot from programming it is almost very helpful with the example that sent me.
Could you please if this Line is common wih all programs? "(Sender: string; Action: string);"
And if I would like to restore the database from back up,how I should do that?
Thank you again for helping me with this.

(Sender: string; Action: string)
It's not use in this example, here you can get more info about events OnShow and OnClose
http://myvisualdatabase.com/help_en/script/form.html


Database is just one file. To restore the database, you should copy database file from backup folder to the current folder of your project and rename it to "sqlite.db"

Dmitry.

Re: [Script] Automatic backup database

Thank you very much my friend!
You really help me!!!
smile

Re: [Script] Automatic backup database

Hi
I used this script but it does not work for me. I guess it's because I use version 1.45 which does not have copyTo command.
is there any other script to make a backup using version 1.45?
thanks

Re: [Script] Automatic backup database

identity wrote:

Hi
I used this script but it does not work for me. I guess it's because I use version 1.45 which does not have copyTo command.
is there any other script to make a backup using version 1.45?
thanks

Hello,


This script should be work for you, please attach you project (zip file without exe and dll)
I'll check it.

Dmitry.

7 (edited by identity 2016-01-28 11:54:21)

Re: [Script] Automatic backup database

hi
I made a backup folder in the same folder as my project and then I insert this script and it works fine.
is there any way that the script make a backup somewhere other than the project folder? for example :
D:\new\backup

Re: [Script] Automatic backup database

identity wrote:

hi
I made a backup folder in the same folder as my project and then I insert this script and it works fine.
is there any way that the script make a backup somewhere other than the project folder? for example :
D:\new\backup

Yes, change this line

CopyFile('sqlite.db', 'backup/backup '+ FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.db');

to

CopyFile('sqlite.db', 'D:\new\backup\backup'+ FormatDateTime('dd-mm-yyyy hh-nn-ss', now)+'.db');
Dmitry.

Re: [Script] Automatic backup database

thank you so much for your help
can I use the CopyTo command for images as well?
I don't want the pictures to be saved in the database but my version does not have LinkFile for the images.

Re: [Script] Automatic backup database

identity wrote:

thank you so much for your help
can I use the CopyTo command for images as well?
I don't want the pictures to be saved in the database but my version does not have LinkFile for the images.

Unfortunately no.

Dmitry.

11

Re: [Script] Automatic backup database

Hi @ All,

is there a way to overwrite an existing backup-file by "copy" or another command ??

best regards Marc

12 (edited by derek 2019-01-05 17:21:51)

Re: [Script] Automatic backup database

Hello Marc,
My understanding is that if you use 'copyfile' (for individual files) or 'directorycopy' (for entire directories (and sub-directories)) -
1)   if the destination file or directory doesn't exist, it will be created.
2)   if the destination file of directory already exists, it will, by default, be overwritten.
Please have a look at the attachment (1 example of 'copyfile' and 1 example of 'directorycopy').
I appreciate that these ways of performing back-ups probably won't suit more complex applications, but it does the job for my simple requirements (why buy a ferrari if you only go shopping!).
Hope this helps.
Regards,
Derek.

Post's attachments

Attachment icon onloan.zip 339.58 kb, 556 downloads since 2019-01-05 

Re: [Script] Automatic backup database

Sorry - forgot the second attachment - here it is
Derek.

Post's attachments

Attachment icon onloan2.zip 339.58 kb, 660 downloads since 2019-01-05