How to create a full database backup in SQL Server 2005, SQL Server 2008 or SQL Server 2012 ?
Note.
- Full database backup take more times to finish and require more storage space.
For the large database you should database backup with differential database backup.
- You can estimate the size of a full database backup by using the sp_spaceused system stored procedure.
- BACKUP DATABASE and BACKUP LOG permissions default to members of the sysadmin fixed server role and the db_owner and db_backupoperator fixed database roles.
DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20), @hhmiss varchar(20) -- used for file name
-- SET @path = 'C:\Backup\'
SET @path = '\\MAPPATH\'
SET @hhmiss = CONVERT(VARCHAR(20),GETDATE(),108);
SET @hhmiss = SUBSTRING(@hhmiss, 1, 2) + SUBSTRING(@hhmiss, 4, 2) + SUBSTRING(@hhmiss, 7, 2);
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + '_' + @hhmiss
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
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor
Thursday, January 17, 2013
SQL Server Backup Database script
Labels: SQL backup, SQL Server 2005, SQL Server 2008, SQL Server 2012
Posted by demo at 2:04 AM 0 comments
Subscribe to:
Posts (Atom)