简单的SQL Server备份脚本代码

时间:2022-06-02 00:21:25

一般的情况下我们会选用SQLServer自带的数据库维护计划来定义备份.

但有些时候,有的机器数据库维护计划不能成功实现备份.

错误原因可能不尽相同,这时我们可以用简单的SQLServer备份脚本来做备份.

生成简单的SQLServer备份脚本的SQL语句:

usemaster

select'backupdatabase'+name+'todisk=''F:\sqlserver_backup\'+name+'.bak''withinit'fromsysdatabases

-------------------------------------------------------------------------------------------------

backupdatabasemastertodisk='F:\sqlserver_backup\master.bak'withinit

backupdatabasemodeltodisk='F:\sqlserver_backup\model.bak'withinit

backupdatabasemsdbtodisk='F:\sqlserver_backup\msdb.bak'withinit

backupdatabasedb_app1todisk='F:\sqlserver_backup\db_app1.bak'withinit

backupdatabasedb_app2todisk=F:\sqlserver_backup\db_app2.bak'withinit