Batch backup database

Source: Internet
Author: User

This article briefly introduces how to back up a database using command lines for an instance. This situation occurs mainly when the SQL version does not support maintenance plans and jobs.

Supports daily automatic backup in combination with Windows Task plans.

Sql0000.exe-s Em \ tim2008r2 (1)-U sa (2)-P 123456 (3)-D test (4)-B-c prepare _end-Q

"Declare @ name varchar (250) set @ name = 'd: \ db_test \ test _ '+ convert (varchar (50), getdate (), 112) + '. bak 'backup database test to disk = @ name "(5)

Note:

(1) database connection instance

(2) Login Name
(3) password

(4) Database Name

(5) SQL statement and backup statement.

 

The database backup and restoration syntax is attached:

Declare @ name varchar (250)
Set @ name = 'd: \ db_test \ test _ '+
Convert (varchar (50), getdate (), 112) + '. Bak'
Backup database [test]
Disk = @ name
With noformat, noinit,
Name = n' test _ fullbackup ',
Skip, norewind, nounload

Use master;
Go
Restore filelistonly
From disk = 'd: \ Temp files \ test_20120706.bak'

Restore database test1
From disk = 'd: \ Temp files \ test_20120706.bak'
With recovery,
Move 'test' to 'd: \ Temp files \ test1.mdf ',
Move 'test _ log' to 'd: \ Temp files \ test1_log.ldf ';
Go

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.