Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Easy way to backup a C/S installation ?
Wed, Jan 27 2010 5:34 PMPermanent Link

Nenad
Hallo,

right now we just copy the DB-Files from the directory during the night while the C/S-Server is running,
this seems to work when nobody is accessing the DB,
but i am always wondering if there is a safer way to do this ?

I read some posts about customizing the DB-Server with some own copy-code but this seems to be quite work intensive ..
Is there some finished working code to copy all tables at a defined time to another directory ?

Nenad
Wed, Jan 27 2010 7:03 PMPermanent Link

"Robert"

"Nenad" <nenad.steric@chello.at> wrote in message
news:2E8D21E7-C32C-4853-8AF8-BB73D7DBC546@news.elevatesoft.com...
> Hallo,
>
> right now we just copy the DB-Files from the directory during the night
> while the C/S-Server is running,
> this seems to work when nobody is accessing the DB,
> but i am always wondering if there is a safer way to do this ?
>
> I read some posts about customizing the DB-Server with some own copy-code
> but this seems to be quite work intensive ..
> Is there some finished working code to copy all tables at a defined time
> to another directory ?
>
> Nenad


Just do a regular DBISAM backup. You can run it off a workstation or the
server itself, with some little process that wakes up at a predetmined time.

Robert

Thu, Jan 28 2010 7:47 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Nenad,

<< I read some posts about customizing the DB-Server with some own copy-code
but this seems to be quite work intensive .. Is there some finished working
code to copy all tables at a defined time to another directory ? >>

It's not too bad.  This is the code that we use in our customized database
server (main.pas in the dbsrvr.dpr project that we ship with DBISAM) for our
backups:

  TSessionContext = class(TObject)
     private
        FSupportModule: TSupportDataModule;
        FElevateModule: TElevateDataModule;
        FSession: TDBISAMSession;
        FStatus: string;
        FProgress: Integer;
        procedure DoProgress(Percent: Integer);
        procedure DoStatus(const Msg: String);
        procedure DoError(const Msg: String);
     public
        constructor Create;
        destructor Destroy; override;
        property SupportModule: TSupportDataModule read FSupportModule
                                                   write FSupportModule;
        property ElevateModule: TElevateDataModule read FElevateModule
                                                   write FElevateModule;
        property Session: TDBISAMSession read FSession write FSession;
     end;



implementation

constructor TSessionContext.Create;
var
  TempDescription: string;
  TempPath: string;
begin
  inherited Create;
  Engine.GetServerDatabase('Support',TempDescription,TempPath);
  FSupportModule:=TSupportDataModule.Create(nil);
  with FSupportModule do
     begin
     SupportDatabase.Directory:=TempPath;
     OpenTables;
     end;
  Engine.GetServerDatabase('Elevate',TempDescription,TempPath);
  FElevateModule:=TElevateDataModule.Create(nil);
  with FElevateModule do
     begin
     SupportModule:=FSupportModule;
     ElevateDatabase.Directory:=TempPath;
     OpenTables;
     end;
end;

destructor TSessionContext.Destroy;
begin
  FElevateModule.CloseTables;
  FSupportModule.CloseTables;
  FreeAndNil(FElevateModule);
  FreeAndNil(FSupportModule);
  inherited Destroy;
end;

procedure TSessionContext.DoProgress(Percent: Integer);
var
  TempAbort: Boolean;
begin
  FProgress:=Percent;
  FSession.SendProcedureProgress(FStatus,FProgress,TempAbort);
end;

procedure TSessionContext.DoStatus(const Msg: String);
var
  TempAbort: Boolean;
begin
  FStatus:=Msg+'...';
  FSession.SendProcedureProgress(FStatus,FProgress,TempAbort);
end;

procedure TSessionContext.DoError(const Msg: String);
var
  TempAbort: Boolean;
begin
  FStatus:=Msg;
  FSession.SendProcedureProgress(FStatus,FProgress,TempAbort);
end;

procedure TMainForm.ServerEngineServerScheduledEvent(Sender: TObject;
 const EventName: String; var Completed: Boolean);
var
  SessionContext: TSessionContext;
  TempDocumentGenerator: TDocumentGenerator;
  TempProductTypes: TStrings;
  I: Integer;
  BackupFiles: TStrings;
  TempBackupName: string;
begin
  if (AnsiCompareText(EventName,'DailyBackup')=0) then
     begin
     SessionContext:=TSessionContext.Create;
     try
        with SessionContext do
           begin
           BackupFiles:=TStringList.Create;
           try
              SupportModule.SupportSession.GetTableNames('Support',BackupFiles);
              { Remove the stuff that we don't backup every day
                because of the size, or the stuff that we don't backup
                at all }
              if (DayOfWeek(Date) <> 7) then
                 begin
                 RemoveFromTStrings('article',BackupFiles);
                 RemoveFromTStrings('downfail',BackupFiles);
                 RemoveFromTStrings('downlog',BackupFiles);
                 RemoveFromTStrings('groups',BackupFiles);
                 RemoveFromTStrings('errorlog',BackupFiles);
                 end;
              RemoveFromTStrings('mail',BackupFiles);
              RemoveFromTStrings('outbox',BackupFiles);
              RemoveFromTStrings('pendmail',BackupFiles);
              RemoveFromTStrings('weblog',BackupFiles);
              RemoveFromTStrings('blklog',BackupFiles);
              with SupportModule.SupportDatabase do
                 begin
                 TempBackupName:='support'+StringReplace(DateToStr(Date),'/','',[rfReplaceAll])+'.bkp';
                 Completed:=Backup(AddBS(Directory)+'backup\'+TempBackupName,
                                   'Daily Support Backup for
'+DateToStr(Date),6,BackupFiles);
                 if Completed then
                    begin
                    Completed:=CopyFile(PChar(AddBS(Directory)+'backup\'+TempBackupName),
                                        PChar('h:\'+TempBackupName),False);
                    if Completed then
                       Completed:=DeleteFile(PChar(AddBS(Directory)+'backup\'+TempBackupName));
                    end;
                 end;
              ElevateModule.ElevateSession.GetTableNames('Elevate',BackupFiles);
              with ElevateModule.ElevateDatabase do
                 begin
                 TempBackupName:='elevate'+StringReplace(DateToStr(Date),'/','',[rfReplaceAll])+'.bkp';
                 Completed:=Backup(AddBS(Directory)+'backup\'+TempBackupName,
                                   'Daily Elevate Software Backup for
'+DateToStr(Date),6,BackupFiles);
                 if Completed then
                    begin
                    Completed:=CopyFile(PChar(AddBS(Directory)+'backup\'+TempBackupName),
                                        PChar('h:\'+TempBackupName),False);
                    if Completed then
                       Completed:=DeleteFile(PChar(AddBS(Directory)+'backup\'+TempBackupName));
                    end;
                 end;
           finally
              BackupFiles.Free;
           end;
           end;
     finally
        FreeAndNil(SessionContext);
     end;
     end
  else
     Completed:=True;
end;

We just set up a scheduled event called DailyBackup using the Server
Administration Utility, and set it to run every day after midnight.

--
Tim Young
Elevate Software
www.elevatesoft.com

Fri, Jan 29 2010 12:12 PMPermanent Link

Nenad
Hallo Tim,

thanks for the example-code,
could this be a feature which would make sense to integrate into the default CS-binary ?

The low-tech solution could also be just to use "net stop/start" to stop the service
and the copy the files to some other dir - of course incurring a downtime.

Nenad

On 28.01.2010 13:47, Tim Young [Elevate Software] wrote:
> Nenad,
>
> <<  I read some posts about customizing the DB-Server with some own copy-code
> but this seems to be quite work intensive .. Is there some finished working
> code to copy all tables at a defined time to another directory ?>>
>
> It's not too bad.  This is the code that we use in our customized database
> server (main.pas in the dbsrvr.dpr project that we ship with DBISAM) for our
> backups:
>
>     TSessionContext = class(TObject)
>        private
>           FSupportModule: TSupportDataModule;
>           FElevateModule: TElevateDataModule;
>           FSession: TDBISAMSession;
>           FStatus: string;
>           FProgress: Integer;
>           procedure DoProgress(Percent: Integer);
>           procedure DoStatus(const Msg: String);
>           procedure DoError(const Msg: String);
>        public
>           constructor Create;
>           destructor Destroy; override;
>           property SupportModule: TSupportDataModule read FSupportModule
>                                                      write FSupportModule;
>           property ElevateModule: TElevateDataModule read FElevateModule
>                                                      write FElevateModule;
>           property Session: TDBISAMSession read FSession write FSession;
>        end;
>
>
>
> implementation
>
> constructor TSessionContext.Create;
> var
>     TempDescription: string;
>     TempPath: string;
> begin
>     inherited Create;
>     Engine.GetServerDatabase('Support',TempDescription,TempPath);
>     FSupportModule:=TSupportDataModule.Create(nil);
>     with FSupportModule do
>        begin
>        SupportDatabase.Directory:=TempPath;
>        OpenTables;
>        end;
>     Engine.GetServerDatabase('Elevate',TempDescription,TempPath);
>     FElevateModule:=TElevateDataModule.Create(nil);
>     with FElevateModule do
>        begin
>        SupportModule:=FSupportModule;
>        ElevateDatabase.Directory:=TempPath;
>        OpenTables;
>        end;
> end;
>
> destructor TSessionContext.Destroy;
> begin
>     FElevateModule.CloseTables;
>     FSupportModule.CloseTables;
>     FreeAndNil(FElevateModule);
>     FreeAndNil(FSupportModule);
>     inherited Destroy;
> end;
>
> procedure TSessionContext.DoProgress(Percent: Integer);
> var
>     TempAbort: Boolean;
> begin
>     FProgress:=Percent;
>     FSession.SendProcedureProgress(FStatus,FProgress,TempAbort);
> end;
>
> procedure TSessionContext.DoStatus(const Msg: String);
> var
>     TempAbort: Boolean;
> begin
>     FStatus:=Msg+'...';
>     FSession.SendProcedureProgress(FStatus,FProgress,TempAbort);
> end;
>
> procedure TSessionContext.DoError(const Msg: String);
> var
>     TempAbort: Boolean;
> begin
>     FStatus:=Msg;
>     FSession.SendProcedureProgress(FStatus,FProgress,TempAbort);
> end;
>
> procedure TMainForm.ServerEngineServerScheduledEvent(Sender: TObject;
>    const EventName: String; var Completed: Boolean);
> var
>     SessionContext: TSessionContext;
>     TempDocumentGenerator: TDocumentGenerator;
>     TempProductTypes: TStrings;
>     I: Integer;
>     BackupFiles: TStrings;
>     TempBackupName: string;
> begin
>     if (AnsiCompareText(EventName,'DailyBackup')=0) then
>        begin
>        SessionContext:=TSessionContext.Create;
>        try
>           with SessionContext do
>              begin
>              BackupFiles:=TStringList.Create;
>              try
>                 SupportModule.SupportSession.GetTableNames('Support',BackupFiles);
>                 { Remove the stuff that we don't backup every day
>                   because of the size, or the stuff that we don't backup
>                   at all }
>                 if (DayOfWeek(Date)<>  7) then
>                    begin
>                    RemoveFromTStrings('article',BackupFiles);
>                    RemoveFromTStrings('downfail',BackupFiles);
>                    RemoveFromTStrings('downlog',BackupFiles);
>                    RemoveFromTStrings('groups',BackupFiles);
>                    RemoveFromTStrings('errorlog',BackupFiles);
>                    end;
>                 RemoveFromTStrings('mail',BackupFiles);
>                 RemoveFromTStrings('outbox',BackupFiles);
>                 RemoveFromTStrings('pendmail',BackupFiles);
>                 RemoveFromTStrings('weblog',BackupFiles);
>                 RemoveFromTStrings('blklog',BackupFiles);
>                 with SupportModule.SupportDatabase do
>                    begin
>                    TempBackupName:='support'+StringReplace(DateToStr(Date),'/','',[rfReplaceAll])+'.bkp';
>                    Completed:=Backup(AddBS(Directory)+'backup\'+TempBackupName,
>                                      'Daily Support Backup for
> '+DateToStr(Date),6,BackupFiles);
>                    if Completed then
>                       begin
>                       Completed:=CopyFile(PChar(AddBS(Directory)+'backup\'+TempBackupName),
>                                           PChar('h:\'+TempBackupName),False);
>                       if Completed then
>                          Completed:=DeleteFile(PChar(AddBS(Directory)+'backup\'+TempBackupName));
>                       end;
>                    end;
>                 ElevateModule.ElevateSession.GetTableNames('Elevate',BackupFiles);
>                 with ElevateModule.ElevateDatabase do
>                    begin
>                    TempBackupName:='elevate'+StringReplace(DateToStr(Date),'/','',[rfReplaceAll])+'.bkp';
>                    Completed:=Backup(AddBS(Directory)+'backup\'+TempBackupName,
>                                      'Daily Elevate Software Backup for
> '+DateToStr(Date),6,BackupFiles);
>                    if Completed then
>                       begin
>                       Completed:=CopyFile(PChar(AddBS(Directory)+'backup\'+TempBackupName),
>                                           PChar('h:\'+TempBackupName),False);
>                       if Completed then
>                          Completed:=DeleteFile(PChar(AddBS(Directory)+'backup\'+TempBackupName));
>                       end;
>                    end;
>              finally
>                 BackupFiles.Free;
>              end;
>              end;
>        finally
>           FreeAndNil(SessionContext);
>        end;
>        end
>     else
>        Completed:=True;
> end;
>
> We just set up a scheduled event called DailyBackup using the Server
> Administration Utility, and set it to run every day after midnight.
>
Sat, Jan 30 2010 10:04 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Nenad,

<< could this be a feature which would make sense to integrate into the
default CS-binary ? >>

It makes sense, but it isn't likely to happen.  The scheduled events are
simply something, like several other things in DBISAM, that need to be coded
directly into the server.  It's why we ship the source code to the
dbsrvr.dpr project.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image