LiCongMingDeShujuku / Backup-All-Databases-To-Share-Location

备份所有数据库以共享位置

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLEVER DATA GIT REPO

备份所有数据库以共享位置

Backup All Databases To Share Location

发布-日期: 2014年04月15日 (评论)

Contents

中文

这是一个可以将所有数据库备份到网络上来共享位置的快速脚本。数据库备份文件的标题如下:MyDatabaseName.bak。另外还有些逻辑可以替换数据库名称中的撇号。我不知道为什么会有它们,但我发现了一个盒子,所以我把它包含在那里。另外,这不会备份系统数据库,仅备份用户数据库。

English

Here’s a quick script that will backup all databases to a shared location on the network. The database backup files will be titled like this: MyDatabaseName.bak There is some extra logic to replace apostrophe’s in the database name in case you have any. I don’t know why you would have them, but I just found a box that does, so I included that in there. Additionally; this will not backup the system databases. Only user databases are backed up.


Logic

use master;
set nocount on
declare @backup_all_databases varchar(max)
set @backup_all_databases = ''
select @backup_all_databases = @backup_all_databases +
'backup database [' + name + '] to disk = ''\\MyShareName\' + replace(name, '', '''') + '.bak'' with format;' + char(10)
from sys.databases where name not in ('tempdb') 
order by name asc
exec (@backup_all_databases)

WorksEveryTime

Build-Info

Build Quality Build History
Build-Status
Coverage
Nuget
Build history

Author

  • 李聪明的数据库 Lee's Clever Data
  • Mike的数据库宝典 Mikes Database Collection
  • 李聪明的数据库 "Lee Songming"

Gist Twitter Wordpress


License

LicenseCCSA

Lee Songming

About

备份所有数据库以共享位置


Languages

Language:TSQL 100.0%