Run SQL script automatically

  • Hi guys,

    Here is a useful script which can be used for an automated backup in sql express, it is much more simplistic I believe.

    A question regarding this though, does anyone think its possible to redirect the backup to an ftp site which would be awesome.

    USE [master]

    GO

    /****** Object: StoredProcedure [dbo].[usp_demo] Script Date: 03/09/2012 12:19:11 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    ALTER PROCEDURE [dbo].[usp_demo]

    AS

    BEGIN

    BACKUP DATABASE [testDB] TO DISK = N'C:\WINDOWS\TEMP\testDB.bak' WITH NOFORMAT, NOINIT, NAME = N'testDB-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10

    END

  • you couldnt backup to ftp site (i dont think) but you could couple it with something like xcopy, roboxopy or filezilla.

    When you say ftp, is that remote? If the backup file name stayed static and was always available at xx:xx you could just batch and FTP command from dos and just schedule it.

    Adam Zacks-------------------------------------------Be Nice, Or Leave

  • I have to send a data extract every 15 minutes to an FTP site. Here is how I do it.

    (Note: File name, then ====== line, then the actual contents of the file)

    FTPExample_BatchRunner.bat

    =========================

    C:

    cd cd FTP_Generic_Example

    ftp -s:GenericFTPParam.txt http://ftp.somecompanyname.com

    ftp -s:GenericFTPParam.txt 111.111.111.111

    GenericFTPParam.txt

    =========================

    username

    password

    bin

    put C:\SomeFile.bak SomeFile.bak

    quit

    Notes:

    Assumes both files are in C:\FTP_Generic_Example\ folder (from the line cd FTP_Generic_Example) . Can modify these when put in different directory/disk drive.

    The two ftp lines in the batch file really only needs to be done once. I just showed the two different ways to do it. One with a website name, the other using a specific IP address.

    The invocation of the ftp command sends the GenericFTPParam.txt file as the parameter file, which contains the username, password, and the actual ftp commands that copy a file.

    The line put C:\SomeFile.bak SomeFile.bak:

    C:\SomeFile.bak = the directory and file name on your system.

    SomeFile.bak = how to name it on their system.

    Since it uses the parameter file, you could get real fancy and use some sort of program to create a new parameter file each day, in case the file names change (such as changing time stamp, etc.).

    Hope this helps.

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply