SQL Server 2000General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
How can I perform backup of SQL server database by just specifying parameters (like the database name and media etc) dynamically in either a batchfile / command line ?
If the User is not willing to use EM or TSQL, is it possible to automate the process using scripts where just the database name is changed and the backup is performed (by running a batch file or the script).
How to create a database backup (Transact-SQL)
To create a database backup
Execute the BACKUP DATABASE statement to create the database backup, specifying:
The name of the database to back up.
The backup device where the database backup will be written.
Optionally, specify:
The INIT clause to overwrite the backup media, and write the backup as the first file on the backup media. If no existing media header exists, one is automatically written.
The SKIP and INIT clauses to overwrite the backup media even if there are either backups on the backup media that have not yet expired, or the media name does not match the name on the backup media.
The FORMAT clause when using media for the first time to completely initialize the backup media and rewrite any existing media header.
The INIT clause is not required if the FORMAT clause is specified.
Important Use extreme caution when using the FORMAT or INIT clauses of the BACKUP statement, as this will destroy any backups previously stored on the backup media.
Examples
This example backs up the entire MyNwind database to tape:
USE MyNwind
GO
BACKUP DATABASE MyNwind
TO TAPE = '\\.\Tape0'
WITH FORMAT,
NAME = 'Full Backup of MyNwind'
GO
This example creates a logical backup device in which a full backup of the MyNwind database is placed.
-- Create a logical backup device for the full MyNwind backup.
USE master
EXEC sp_addumpdevice 'disk', 'MyNwind_1',
DISK ='c:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\MyNwind_1.dat'
-- Back up the full MyNwind database.
BACKUP DATABASE MyNwind TO MyNwind_1
You can copy this into a .sql file and run from the command prompt using isql commands.