backup through command prompt

  • hi,

    i have installed visual studio 2008, so sql server 2005 is by default installed.can you tell me how to back up my database files through command prompt,sqlcmd 🙂

  • Is your SQL Server is a Express edition

  • http://msdn.microsoft.com/en-us/library/ms165702(SQL.90).aspx

    use this link .

    it shows to login and then once you login you write normal backup command

    backup database dbname to disk='c:\db.bak'

  • yes,its sql express edition

  • the link you provided is not so fruitful.it did'nt solved my problem.Also ,you gave the commands for backup:

    backup database databasename to disk='C:\db.bak'.

    But it too gave errors:

    Cannot open backup device 'C:\db.bak' Operating system error 5(Access is denied...).

    BACKUP DATABASE is terminating abnormally.

    THIS IS THE ERROR MESSAGE I GET IN COMMAND PROMPT OF SQLCMD.

    PLZ HELP

  • the link you provided is not so fruitful.it did'nt solved my problem.Also ,you gave the commands for backup:

    backup database databasename to disk='C:\db.bak'.

    But it too gave errors:

    Cannot open backup device 'C:\db.bak' Operating system error 5(Access is denied...).

    BACKUP DATABASE is terminating abnormally.

    THIS IS THE ERROR MESSAGE I GET IN COMMAND PROMPT OF SQLCMD.

    PLZ HELP

  • error says that you do have access on the c drive..

    open cmd

    type sqlcmd -S"servername" -U"username" -P"password"

    after successful login you see

    >1

    1 use master

    2 backup database dbname to disk=N'c:\foldername\db.bak'

    3 go

    the db backed up

    check the link for more details

  • thanks.

  • Hi Shyam,

    Please confirm if the problem is fixed now.

  • hi,

    yes,backup is successfully created.

    now can u help me how to retrieve (or restore) by database to another sql server database?i.e if i send the backup file to another system and there i want to restore the database,then how?

    can u tell me how to get the help menu in sqlcmd command prompt..where i can get a list of commands in sqlcmd?

  • i guess you are new to dba world... i gues you want to restore the backuped database on new server.

    restore database databasename from disk ='filepath'

    syntax might be different check Books online.

  • You can restore the database on other server after moving the backup files.

    The command prompt is run like this:

    "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\OSQL.EXE" -E

    Then write these lines to restore the database:

    RESTORE DATABASE mydbname from DISK = 'C:\xxx\xxx\xxx.bak' WITH MOVE 'database_Data' to 'C:\Database\xxx\database_Data.mdf', MOVE 'database_Log' to 'C:\Database\xxx\database_Log.LDF'

    GO

    You have to write the correct path for file locations to complete the restoration process.

  • To get the list of command line switchs for sqlcmd, do what you do for every other command line tool - type this at a command prompt:

    SQLCMD /?

    As for the commands that you can submit to SQL through SQLCMD, that is the T-SQL language, which is explained in SQL Server help files.

  • hi,

    'sqlcmd /?' command gives the commands that are available in sqlcmd,but there is no any listing of 'backup' command or 'restore' command and its parameters.so how can i get all the available commands in sqlcmd.

  • hi,

    thanks for your valuable post.the command is working fine without any modification.

    can u give me any link that deals with all the available commands in sqlcmd..like how to see in which database i am presently working in,to delete a database, to see description of a table...and so on

    once again thanks..

Viewing 15 posts - 1 through 15 (of 16 total)

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