SQL express automatic backup

Source: Internet
Author: User

--Step 1

--InMasterCreate a backup database stored procedure in the database.

UseMaster

Go

Create procP

@ db_name sysname , -- database name

@ Bk_pathNvarchar(1024)--Path of the backup file

 As

If isnull(@ Db_name,'') =''

Set@ Db_name =Db_name();

Declare@ DtVarchar(50 );

set @ dt = @ db_name + '_' + convert ( varchar (8 ), getdate (), 112) + '_' ;

set @ dt = @ DT + replace ( convert ( varchar (10 ), getdate (), 108 ), ':' , '' )

If right(@ Bk_path, 1) <>'/'

Set@ Bk_path = @ bk_path +'/';

Exec('Backup database ['+ @ Db_name +'] To disk = '''+ @ Bk_path + @ DT +'. Bak' with format');

Go

 

--Step 2

-- Create two Txt File -- For example D:/batcomand.txt And D:/backupdatabase.txt

--ThenBatcommand.txtThe file content is as follows::

Sqlcmd-smyfend/liangck-e-Ig:/backupdatabase. SQL

Then save.Change the extension. Bat

Note : Here -S Yes Server Name / Instance name -E Yes integration Security

ThenBackupdatabase.txtThe file content is as follows::

UseMaster

Go

ExecP'Name of the database to be backed up', 'G:/backup /'

Then save,Change the extension. SQL

-- step 3

create a task scheduler . select the task to be executed .. Click Browse .. select D:/batcommand. bat

set daily execution .. .

the backup file name is : database name _ date _ time . bak

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.