OSQL - Making a command line backup

  • Hello

    I want to know if is possible with OSQL commandline using TSQL backup script command to build a batch file for making backups of database, and put this command in a windows shortcut button.

    for example :

    OSQL /U /P /d "databasename" /Q "(BACKUP DATABASE [NorthwindCS] TO DISK = N'C:\Programas\Microsoft SQL Server\MSSQL\BACKUP\fernandobackup.BAK' WITH INIT , NOUNLOAD , NAME = N'fernandobackup', NOSKIP , STATS = 10, NOFORMAT )"

    Thanks for your help

    Luis Santos

  • It is possible. I'd use a .cmd file and make a shortcut to that. Also, better (IMHO) to use Windows Auth with this.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

  • Just put you OSQL command that runs the backup in a .bat file, and then make that file a shortcut on your desktop.

    Oh that is probably what you where asking.

    Now if I knew what the dos command was to create a shortcut based on a file, then I would used the xp_cmdshell command to create the shortcut, having OSQL execte the xp_cmdshell command.

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • Hello again

    Like you said Greg i want to make a batch file in DOS to run The script that i am write but i don´t know how can write correctly them, because with OSQL i am just trying to output SELECT query but i need the command for for example running a script file for example exporting the backup job in my sql database to script file.

    Thank for all yours suggestions

    Luis Santos

  • If all you want is a the osql command to build a dos script file then try this:

    osql -E -S<servername> -Q"print 'backup database northwind to disk=''c:\temp\northwin.bak'''" -o c:\temp\bck.sql

    If all you want is the osql command to execute this dos script file then try this:

    osql -E -S<servername> -i c:\temp\bck.sql

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • What you can do is in notepad write

    OSQL -E -Q"Backup dbName to backup_device" -oc:\Backup.log

    or whatever you want to do, and save the file as .cmd. Then you simple executes the .cmd file and the sentence of the backup will execute adding a log file in c:\.

    If you want you can make a shortcut of that .cmd file.

  • Hello

    I would like to thank you for all your suggestions.

    Best regards

    Luis Santos

Viewing 7 posts - 1 through 6 (of 6 total)

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