SQL Server Job Scheduling to create an automatic backup method
1. Choose Enterprise Manager> Manage> SQL Server proxy> job;
2. Create a job and obtain the job name as needed. For example, for data backup, select SA as the owner. You can also select another user, provided that the user has the permission to execute the job;
3. Click the step tab to go to the step panel. Create a step. You can enter the step name as needed, such as step 1. The default type and database do not need to be modified. Write the following statement in the command:
Backup database [database name] to disk = n' F: \ data \ Database Backup 'with noinit, nounload, name = n' Database Backup', noskip, stats = 10, noformat
Note: The Database Name, disk = (here you need to enter the path and the name of your database backup), and the name = can be entered at will.
4. Click the scheduling tab to go to the scheduling panel. Create a scheduling task and enter the name as needed. Click "show" and select "Schedule" for the task to be executed. Such as every day, every 2 days, every week, and every month. Set as needed;
5. Do not forget one thing after you confirm it. Right-click the job you just created and start the job. If there is no problem with your job, a message indicating that the job is successfully executed will be displayed, corresponding backup files appear on your disk;
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, we can differentiate the backup files. At this time, we need to modify the SQL statement just now. Reference instance:
Declare @ filename nvarchar (100)
Set @ filename = 'f: \ addin \ backup \ data' + convert (char (10), getdate (), 112)
Print @ filename
Backup database [addin] to disk = @ filename with noinit, nounload, name = n'addin backup ', noskip, stats = 10, noformat
Or write as follows:
Declare @ backfilename varchar (200)
Declare @ date char (10)
Declare @ filename varchar (200)
Declare @ name varchar (200)
Set @ date = convert (char (10), getdate (), 120)
Set @ filename = 'f: \ sqlserverbackup \ defectstoredkh _'
Set @ backfilename = @ filename + @ date
Set @ name = 'lifectstoredkh backup'
Backup database [defectstoredkh] -- defectstoredkh indicates the name of the backup database.
To disk = @ backfilename with init, nounload, name = @ name, noskip, stats = 10, noformat