Pages

Bài đăng phổ biến

Showing posts with label backup mssql. Show all posts
Showing posts with label backup mssql. Show all posts

Tuesday, December 27, 2011

Backup Mssql while Mssql server is running

Script to backup all database mssql  :

DECLARE @name VARCHAR(50)
DECLARE @path VARCHAR(256)
DECLARE @fileName VARCHAR(256)
DECLARE @fileDate VARCHAR(20)

SET @path = 'C:\backup'

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)

DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName with noinit

FETCH NEXT FROM db_cursor INTO @name
END

CLOSE db_cursor
DEALLOCATE db_cursor

 To backup daily or schedule to backup all database you should our script :
http://download.0937686468.com/sqlvn/backupdatabases.rar
(This app is written by my friend http://sqlvn.com )


How to use above application ? 
You just extract this file and edit file MrNhanApp.exe.config that I set the red color :
    <add key="ConnectionStr" value="server=1.1.1.1;database=master;uid=sa;pwd=1111"/>


Nguyen Si Nhan