Manual task of daily backup

Source: Internet
Author: User

Today, I helped my friend set up an automatic SQL 2005 backup. I couldn't even set it up. When I added the maintenance plan, I reported the generation plan error. I had to manually write a task and record it here.

It is mainly used to obtain the location of the last backup record from the relevant system table in MSDB, that is, the number of existing backup sets in this backup set. If there are more than 7 backup sets, all backups are cleared and backed up again, otherwise, differential backup is performed.

If you want to implement weekly backup, monthly backup, and so on, the Code is the same, just change the task execution time.

  1. Use [www-bpjd]
  2. Declare @ cc as int
  3. Set @ cc = (select top 1 position from MSDB. DBO. backupset where media_set_id in (
  4. Select media_set_id from MSDB. DBO. backupmediafamily where logical_device_name = 'daily backup'
  5. ) Order by backup_set_id DESC)
  6. -- Select @ CC
  7. If isnull (@ CC, 0)> 7
  8. Backup database [www-bpjd] to daily backup with init
  9. Else
  10. Backup database [www-bpjd] to daily backup with differential

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.