SQL Server job scheduling to establish a method of automatic backup

Source: Internet
Author: User
Tags date getdate modify sql backup
server| Backup 1, into Enterprise Manager-> Management->sql Server Agent-> operations;

2, the new job, the name of the job to take, for example: Data backup, the owner Select SA, of course, you can also choose other users, provided that the user has the right to execute the job;

3, click the Step tab, enter the step panel. To create a new step, the step name can be filled out casually, such as Step 1, type and database defaults, and no modification is required. The following statement is written to the command:

Backup database [DB name] to DISK = n ' F:\data\ database backup ' with Noinit, nounload, NAME = n ' database backup ', NOSKIP, STATS = 10, Noformat

Note: You need to modify the place, database name, disk= (here need to fill in the path and the name of your database backup) name= can be easily filled in.

4, click the schedule tag, into the dispatch panel, new scheduling, name casually fill in, select Recurring, point change can choose you want to perform the task of arbitrary scheduling. such as every day, every 2 days, every week, monthly, etc. Set yourself up according to your needs;

5, make sure, do not forget one thing, in the work you have just established the right button to start work, if your work is no problem, will be prompted to perform successfully, and have a corresponding backup file on your disk appear;

6, another important problem is that your SQL Server Agent server has been started.

If we need to generate a new backup based on the daily date, so that we can distinguish between backup files. At this point, we need to modify the SQL statement just now. Reference Example:

declare @filename nvarchar (100)

Set @filename = ' F:\AddIn\ backup \data ' +convert (char (), GETDATE (), 112)

Print @filename

Backup DATABASE [addin] to DISK = @filename with Noinit, nounload, NAME = N ' addin backup ', noskip, STATS = ten, Noformat

Or as follows:

DECLARE @BACKFILENAME VARCHAR (200)
DECLARE @DATE CHAR (10)
DECLARE @FILENAME VARCHAR (200)
DECLARE @NAME VARCHAR (200)
SET @DATE =convert (CHAR), GETDATE (), 120)
SET @FILENAME = ' F:\SQLServerBackup\DefectStoreDKH_ '
SET @BACKFILENAME = @FILENAME + @DATE
SET @NAME = ' Defectstoredkh backup '
BACKUP DATABASE [Defectstoredkh]
To DISK = @BACKFILENAME with INIT, nounload, NAME = @NAME, noskip, STATS = ten, Noformat



Related Article

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.