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