Showing posts with label Backup and Recovery. Show all posts
Showing posts with label Backup and Recovery. Show all posts

Sunday, March 29, 2015

SQL Server: Best practice to Move database from one Location to another location.


Most of  SQL Server professional may know the how to move the database form One location to another location. And most of the professional use the "detach and attach" method but..

"Is it best practice?"   NO!!

WHY? – If your database file size is1TB or around 1TB it is not a best practice. So here is the question how to move the database if the database files size is large.

Why it not good practice because while attaching the database it will create the New database on new location where we are moving the database log files. So in this case the existing user will be removed from the database.

Actually it’s quite easy.

Please find the below steps-
USE master;
GO

-- Return the logical file name.
SELECT * FROM sys.master_files WHERE database_id = DB_ID('MY_test_DB')
    AND type_desc = 'LOG';
GO

-- Offline the database
ALTER DATABASE MY_test_DB SET OFFLINE;
GO


-- Physically move(Copy and Paste) the file to a new location.
-- Now we have to modify the path specified in FILENAME to the new location of the file on your server.

ALTER DATABASE MY_test_DB MODIFY FILE ( NAME = MY_test_DB_Log,
FILENAME = 'D:\NewLocation\MY_test_DB_Log.ldf');
GO

-- Online the Database
ALTER DATABASE MY_test_DB SET ONLINE;
GO

--Verify the new location file location.
SELECT * FROM sys.master_files WHERE database_id = DB_ID('MY_test_DB')
    AND type_desc = 'LOG';


Like and Share to SQL Integrity Blog

Sunday, September 23, 2012

SQL SERVER - How to verify Backup FIle before restoring

Verify backup-   There are some script to check and verify existing database before restoring. SQL Server has provided some Keywords that are mentioning below:-
  1. Verifyonly
  2. Headeronly
  3. Filelistonly
  4. Labelonly
-- - Checks to see that the backup set is complete and that all volumes are readable
restore verifyonly from disk='C:\Bacukup\Test_backup_DB.bak'

 ---Returns a result set containing all the backup header information for all backup sets on a particular backup device
restore headeronly from disk='C:\Bacukup\Test_backup_DB.bak'

 --- Returns a result set containing a list of the database and log files contained in the backup set.
restore filelistonly from disk='C:\bacukup\Test_backup_DB.bak'

 --sample for error message:
restore verifyonly from disk='C:\Test\Test_Error_BackUP.bak'

 --ingormation and software version information
RESTORE LABELONLY FROM DISK='C:\Backup\Full_Test_Error_BackUP.bak'

Like and Share to SQL Integrity Blog

Friday, September 14, 2012

SQL SERVER – How to see how much percent of backup has been completed while taking backup

SQL SERVER – How to see how much percent of backup has been completed while taking backup

There is simple command to get the level of percentage of backup in SQL SERVER.
When we have to take backup of big database at that time we can add the STATS option and can see the percentage of running backup

-- Creating test backup
CREATE DATABASE TESTDB
GO
--creating test table
CREATE TABLE TEST_TABLE (ID INT)
GO
-- Taking bacup with STATS option
BACKUP DATABASE TESTDB  TO DISK= 'C:\TESTDB.BAK' WITH STATS =10
GO


Like and Share to SQL Integrity Blog