Options

Need Help from a Batch Script Guru

qwertyiopqwertyiop Member Posts: 725 ■■■□□□□□□□
Back up data – Microsoft SQL Server

To make a backup using the BACKUP command:
1. Open a Command Prompt window.
2. At the prompt, type the following command to start the osql utility, login as sa. (Default Password is empty.)
osql -U sa
3. At the prompt, type the following command, correcting the example parameters as necessary, and hit Enter.
BACKUP DATABASE [Virtis60] TO DISK = N'W:\Virtis\BACKUP\Virtis60Backup.bkp' WITH INIT, NOUNLOAD, NAME = N'Virtis61s Backup', SKIP, STATS = 10, NOFORMAT
· Database name: Virtis60
· Backup file name and location: C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Virtis61sBackup.bkp. You have to create the "BACKUP" folder if it doesn't already exist.
· Backup database set name: Virtis60 Backup
4. At the prompt, type the following command and hit Enter.
GO

Comments

  • Options
    ZaitsZaits Member Posts: 142
    qwertyiop wrote: »
    Back up data – Microsoft SQL Server

    To make a backup using the BACKUP command:
    1. Open a Command Prompt window.
    2. At the prompt, type the following command to start the osql utility, login as sa. (Default Password is empty.)
    osql -U sa
    3. At the prompt, type the following command, correcting the example parameters as necessary, and hit Enter.
    BACKUP DATABASE [Virtis60] TO DISK = N'W:\Virtis\BACKUP\Virtis60Backup.bkp' WITH INIT, NOUNLOAD, NAME = N'Virtis61s Backup', SKIP, STATS = 10, NOFORMAT
    · Database name: Virtis60
    · Backup file name and location: C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Virtis61sBackup.bkp. You have to create the "BACKUP" folder if it doesn't already exist.
    · Backup database set name: Virtis60 Backup
    4. At the prompt, type the following command and hit Enter.
    GO

    You can easily do this with a vbscript. I don't know if you have alot of experience coding in vbscript, but here are a couple key lines if you modify just right should give you the results you are looking for.


    ====================================
    Example code for executing commands in DOS
    ====================================
    Option Explicit

    Dim objShell
    Dim strCmd

    'Robocopy is an application found in the microsoft resource kit used to migrate data.
    'I wrote a script awhile back to insert this string of commands in dos and execute
    'the command.

    strCmd = Robocopy y:\data e:\data_E\Data /MIR /SEC /E

    Set objShell = CreateObject("WScript.Shell")
    objShell.Run "%comspec% /k exit"
    objShell.Run strCmd, 1, TRUE

    =========================================
    Example code for checking if a file folder already exists.
    =========================================
    Option Explicit
    Dim objFSO
    Dim strLogFolder

    strLogfolder = "E:\Archive\Logs\"

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If Not objFSO.FolderExists(strLogFolder) Then
    Set objFolder = objFSO.CreateFolder(strLogfolder)
    end if

    'Basically this script creates the folder "Logs" under E:\Archive if the folder does not
    ' already exist. If you want to look for a file chane objFSO.FolderExists to objFSO.FileExists.

    I hope this helps and if you have any questions feel free to drop me a private message.
Sign In or Register to comment.