The database automatically backs up and deletes the backup files 30 days ago.

Source: Internet
Author: User
1. The stored procedure for creating the backup database ---- Createbasicstoredproceduretemplate ---- DropstoredprocedureifitalreadyexistsIFEXISTS (SELECT * FROM

1. Create a stored procedure for the backup database -- ====================================== ===============-- Create basic stored procedure template =============================== ===========================-- Drop stored procedure if it already exists if exists (SELECT * FROM

1. Create a stored procedure for the backup database

-- ===================================================== ======
-- Create basic stored procedure template
-- ===================================================== ======

-- Drop stored procedure if it already exists
If exists (
SELECT *
FROM INFORMATION_SCHEMA.ROUTINES
WHERE SPECIFIC_SCHEMA = N 'dbo'
AND SPECIFIC_NAME = n' SP _ backupportal'
)
Drop procedure dbo. SP_BackUpPortal
GO

Create procedure dbo. SP_BackUpPortal
@ BackFolderPath varchar (256) = 'd:/BackUp/Portal'
As
Declare @ today datetime
Declare @ todayString varchar (50)
Declare @ bakfilePath varchar (256)
Declare @ datenameString varchar (50)
Set @ today = getDate ()
Set @ todayString = convert (varchar (11), @ today, 120)
Select @ datenameString = datename (dw, getdate ())
----- If today is Sunday then do a full backup
If (@ datenameString = 'sunday ')
Begin
Set @ bakfilePath = @ backFolderPath + '/Portal' + @ todayString + 'full. Bak ';
Backup database WSS_Content
To disk = @ bakfilePath
End
------ Else do a increment backup
Else
Begin
Set @ bakfilePath = @ backFolderPath + '/Portal' + @ todayString + 'crement. Bak ';
Backup database WSS_Content
To disk = @ bakfilePath
With DIFFERENTIAL
End
GO


2. Create a call ratio to process a file

Echo Backup database daily, if the day is Sunday do a full back up else do a Increment backup
SQLCMD. EXE-S Server/Instance-d DataBaseName-Q "exec dbo. SP_BackUpPortal"

Echo delte the backfile which generated before 30 days

FORFILES/p d:/BackUp/Portal/D-30/c "cmd/c del @ path"

If % date :~ 0, 3% = Sun goto BackByMossCmd
Exit
: BackByMossCmd
Echo Backup by the mosscmd
Cd C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/BIN
C:
STSADM. EXE-o backup-url http: // mossSite/-filename D:/BackUp/Portal/MossCmdPortalBack % date :~ 10,4%-% date :~ 4,2%-% date :~ 7,2%. bak
Exit


3. Add the backup file script that was deleted 30 days ago to the batch processing.

FORFILES/p d:/BackUp/Portal/D-30/c "cmd/c del @ path"


4. Create a windows scheduled task

You don't have.

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.