Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1136
  • Last Modified:

Routine to create a SQL Server Backup

I need the code (and the uses clause) to start a SQL Server backup (I will pass the Db and the Path on the server to store the backup file) I have seen the VB DMO example and I can post it here but so far I could not translate it.  It must be a full backup and it must overwrite any existing file if the names match.

One VB code example is here:
http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/9_dmoe01_5.htm

Thanks,
Roberto.

0
rmaranhao
Asked:
rmaranhao
1 Solution
 
mokuleCommented:
This is what I was using for BACKUP SQL Server.

//----------------------------------------------------------------
procedure TFArchiw.Button1Click(Sender: TObject);
var
  Save_Cursor: TCursor;
begin
  if not DirectoryExists(ExtractFileDir(Edit1.Text)) then
    if not CreateDir(ExtractFileDir(Edit1.Text)) then
      begin
      ModalResult := mrNone;
      exit;
      end;
  Update;
  Save_Cursor := Screen.Cursor;
  Screen.Cursor := crHourglass;
  with DM2.ADOCmd do
    begin
    CommandText := 'ArchiwEx';
    Parameters.Refresh;
    Parameters.ParamByName('@fname').Value := Edit1.Text;
    Parameters.ParamByName('@mode').Value := 2;
    Prepared := True;
    Execute;
    end;
  Screen.Cursor := Save_Cursor;
end;


//----------------------------------------------------------------
CREATE PROCEDURE ArchiwEx @fname varchar(260), @mode int  AS
IF @mode = 0
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname
      END
IF @mode = 1
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname  WITH DIFFERENTIAL
      END
IF @mode = 2
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname WITH INIT
      END
IF @mode = 3
      BEGIN
      BACKUP DATABASE yourdbname TO DISK = @fname  WITH DIFFERENTIAL, INIT
      END
GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON
GO
0
 
rmaranhaoAuthor Commented:
Thanks mokule. I had never found the "to disk" clause.....
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now