A simple, fully-prepared database script and whether the system database needs to be backed up

Source: Internet
Author: User

A simple, fully-prepared database script, @path parts need to replace the path

1 DECLARE @name VARCHAR( -)--Database name2 DECLARE @path VARCHAR( the)--path for backup files3 DECLARE @fileName VARCHAR( the)--filename for backup4 DECLARE @fileDate VARCHAR( -)--used for file name5  6 --Specify database backup directory7 SET @path = 'C:\Backup\'  8  9 --Specify filename formatTen SELECT @fileDate = CONVERT(VARCHAR( -),GETDATE(), the)  One   A DECLAREDb_cursorCURSOR  for   - SELECTname -  frommaster.dbo.sysdatabases the WHEREName not inch('Master','Model','msdb','tempdb')--Exclude These databases -   - OPENDb_cursor - FETCH NEXT  fromDb_cursor into @name    +   -  while @ @FETCH_STATUS = 0    + BEGIN    A        SET @fileName = @path + @name + '_' + @fileDate + '. BAK'   at        BACKUP DATABASE @name  to DISK = @fileName   -   -        FETCH NEXT  fromDb_cursor into @name    - END    -   - CLOSEDb_cursor in deallocateDb_cursor

Can see does not back up ' master ', ' model ', ' msdb ', ' tempdb ' database
To make it easier to handle orphaned accounts, it is recommended that you back up the master database. Or 2012 of the include database is enabled, but it is also recommended to back up the master database

Although the model database does not have any user data in it, the database in which tempdb needs to be created through the model parameters is also recommended for backup.

MSDB records Some schedule information about the SQL Agent and backup restore information, and it is recommended to back it up, and it is recommended to use the full recovery model in a redundant device.

Tempdb is created when the database starts, so no backup is required.

Reference

http://www.mssqltips.com/sqlservertip/1070/simple-script-to-backup-all-sql-server-databases/

A simple, fully-prepared database script and whether the system database needs to be backed up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.