About database automatic scheduled backups, but each backup with a different name

Source: Internet
Author: User
Tags backup
Backup | timing | data | database

About database automatic scheduled backups, but each backup with a different name
This method may be realized a long time ago, I hope which masters do not mind, =:)


Again, the database is scheduled to be backed up automatically, but each backup is implemented with a different name as follows:

1: Create a job on SQL Server that will allow it to run automatically and regularly;


2: Create a step with the following code:
declare @path nvarchar (100)
declare @name nvarchar (100)
declare @devicename nvarchar (50)

--' F:\backup\DBback ', this is free to replace, the backup name with date as a different name
Set @path = ' F:\backup\DBback ' + convert (nvarchar), GETDATE (), 112) + '. Dat '
--25,28 A number like this, changes with the previous path
Select @name = substring (@path, 25,len (@path)-28)
Select @devicename = @name

EXEC sp_addumpdevice ' disk ', @devicename, @path

--dbname is the database you want to back up.
BACKUP DATABASE dbname to @devicename

Go

3: Then establish a schedule, so that it can be a certain amount of time to back up the different names of the database, and later recovery is also very convenient, want to restore which to restore which. =:)





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.