简体   繁体   English

示例sql脚本以压缩和传输数据库备份文件

[英]Sample sql script to zip and transfer database backup file

I was looking for a sample sql script to zip my database backup file (.bak) and transfer to a remote location. 我正在寻找一个示例sql脚本来压缩我的数据库备份文件(.bak)并转移到远程位置。 Please share if you have it with you. 如果你有它,请分享。

You can use xp_cmdshell to invoke the commands for zipping and copying. 您可以使用xp_cmdshell调用用于压缩和复制的命令。 In the sample here, I am using winzip command line (for zipping/unzipping) and xcopy for transferring files. 在这里的示例中,我使用winzip命令行(用于压缩/解压缩)和xcopy用于传输文件。

EXEC master..xp_cmdshell 'C:\"Program Files"\WinZip\wzzip C:\Database.bak.zip C:\Database.bak';
EXEC master..xp_cmdshell 'C:\"Program Files"\WinZip\wzunzip -o "C:\Database.bak.zip" "C:\Database"';
EXEC master..xp_cmdshell 'xcopy "C:\Database.bak.zip" "\\networkshare\Backups" /Y'

xp_cmdshell is one way, although it isn't ideal since enabling it makes the server less secure. xp_cmdshell是一种方法,虽然它不是理想的,因为启用它会降低服务器的安全性。

My open source project, SQL Server Compressed Backup , does what you are looking for in one step: 我的开源项目SQL Server Compressed Backup ,只需一步即可完成您所需的工作:

msbp.exe backup "db(database=model)" "zip64" "local(path=\\server\share\path\model.full.bak.zip)"

The installation of SQL Server Compressed Backup is just "xcopy" deployment -- there is nothing to install/uninstall, ideal if you just need to do this once. SQL Server Compressed Backup的安装只是“xcopy”部署 - 没有什么可以安装/卸载,如果你只需要这样做一次就很理想。

It uses zip64 since the standard zip format has a 4 GB limit. 它使用zip64,因为标准zip格式有4 GB的限制。 Alternative compression formats available are gzip and bzip2 which have no limits. 可用的替代压缩格式是gzip和bzip2,它们没有限制。

Why not using such simple tools like SqlBackupAndFtp ? 为什么不使用像SqlBackupAndFtp这样的简单工具? They do exactly what you need (sql backup + moving to remote location) with a simple interface and you don't need to write any scripts. 它们通过简单的界面完全满足您的需求(sql备份+移动到远程位置),您无需编写任何脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM