Skip to main content

Posts

Showing posts with the label Backup

Is your SQL Server Database backup good enough? Can it save you during a disaster?

Met a DBA from a company who are in business for ~2 years. During the conversation came to know they have never tested their backup file - not even once. Also, they have very rarely used DBCC CheckDB command. Should I call it as surprised or shocked? It has become common to see Database Administrators to have fancy DB Backup plan, automate it and that's it. Their idea is whenever the need arises (read as disaster strikes) they can make use of it and restore the database. Although theoretically sounds like a good plan it actually isn't. Why? All those efforts to take regular backups would become completely useless if those files can't be used to recover the database. One important question missed by many companies to whom I have consulted for - "Do we regularly make sure that we are able to restore a database from our backups?". Despite backup process has succeeded how do we know it isn't corrupted (or) has some issues which don't allow it to be rest...

Database Backup from Command prompt

We can make use of "SQLCMD" to execute scripts from Command prompt. If you are new to it I would suggest to go over my introductory posts on them here . Example 1: Writing a batch file with the TSQL script to backup a DB. Save the below sample script as a batch file (lets say, DBBackup.Bat). echo off cls set /p DBNAME=Enter database name: set BACKUP=c:\%DBNAME%.bak set SQLSERVERNAME=Enter_Your_SQL_ServerName_here echo. sqlcmd -E -S %SQLSERVERNAME% -d master -Q "BACKUP DATABASE [%DBNAME%] TO DISK = N'%BACKUP%'" echo. pause We can now go to the SQL Command prompt by typing SQLCMD in Start > Run dialogue box. On executing DBBackup.Bat it would prompt us to enter the name of the database which has to be backed up. The backup file would be stored in C:\ drive. This is just a sample which can be modified or extended according to our need. Just in case we have already have a Stored procedure to backup the DB for us. Then we can still make use ...