SQL Server 2008 - 如何压缩备份文件并移动到远程服务器
我有 SQL Server 2008 的非企业版。我每晚进行备份,手动压缩文件,然后手动复制到远程服务器。
我需要使用批处理文件自动执行此操作。将文件从服务器复制到服务器很容易,但如何首先自动压缩备份?
我需要的完整过程是:
- 每晚运行备份
- 压缩备份以减小大小(使用唯一的 zip 文件名)
- 将 zip 文件移动到远程服务器,该服务器设置为数据库服务器上的网络驱动器
我承认压缩部分已抛出我走开。任何建议都将非常受欢迎。
提前致谢。
I have the non-enterprise edition of SQL Server 2008. I do nightly backups, manually zip the files and then manually copy to a remote server.
I need to automate this using batch files. Copying files from server to server is easy but how do I automate the zipping of the backup first?
The full process I need is:
- Run the backup nightly
- Zip the backup to reduce size (with a unique zip filename)
- Move the zip file to a remote server which is setup as a network drive on the database server
I confess the compression part has thrown me off. Any advice would be very much welcomed.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
您可以使用SQLBackupAndFTP软件备份数据库。它是一个简单的 UI 工具,能够执行和安排备份作业(完整备份、差异备份和日志传输备份)。它只是使用嵌入式存档器或 7-zip 压缩备份,然后发送到本地文件夹、NAS 驱动器、FTP 或云(Dropbox、Google Drive、Amazon S3)。还有支持论坛。
You can backup databases with SQLBackupAndFTP software. It's a simple UI tool with ability to execute and schedule backup jobs (full, diff and log tran backups). It just compresses backups with embedded archiver or 7-zip and send to a local folder or to a NAS drive or FTP or a to a cloud (Dropbox, Google Drive, Amazon S3). Also there is support forum.
您绝对可以(而且应该!)调查 SQL Server 维护计划。
这些允许您自动执行一些操作,例如
我不确定它们是否内置支持压缩和复制到远程服务器,但您绝对可以通过维护计划来自动化备份部分,并通过某种命令文件来自动化其余部分。
You could (and should!) most definitely investigate the SQL Server maintenance plans.
These allow you to automate things like
I'm not sure if they have built-in support for zipping and copying to a remote server, but you could definitely automate the backup part with a maintenance plan, and the rest with a command file of some sort.
您没有指定您正在使用的 zip 实用程序。有很多,但我倾向于使用 Winzip,因为这是工作中使用的主要 zip 工具。 Winzip 有一个命令行界面 ( http://www.winzip.com/prodpagecl.htm )这是一个免费的 winzip 插件,可以从命令行调用。
另一种选择是通过命令行使用 cygwin 和 tar.gz。
you do not specify the zip utility that you are using. There are many, but I tend to use Winzip as that is the main zip tool used at work. Winzip has a command line interface ( http://www.winzip.com/prodpagecl.htm ) that is a free addin to winzip that can be called from a command line.
Another alternative would be to use cygwin and tar.gz via the command line.
如果您只是不知道如何从批处理脚本进行压缩:
"C:\Program Files\7-Zip\7z.exe" a -t7z MyBackups.7z [要压缩的文件]
为了获得唯一的文件名,我通常嵌入日期/时间:yyyymmddhhMMss-backup.7z
If you are just stuck on how to compress from a batch script:
"C:\Program Files\7-Zip\7z.exe" a -t7z MyBackups.7z [Files To Zip]
To get a unique filename, I usually embed the date/time: yyyymmddhhMMss-backup.7z
您可以从命令行压缩内容,例如使用 RAR。只需将 ZIP 命令添加到进行复制的位置即可。如果是在 T-SQL 中,您可以使用 xp_cmdshell。
对于豪华选项,请查看 Red Gate Backup,它使过程相当无痛。
You can ZIP stuff from the command line, for example with RAR. Just add the ZIP commands to wherever you do the copying. If that's in T-SQL, you can execute a ZIP command using xp_cmdshell.
For a luxury option, check out Red Gate Backup, it makes this process fairly painless.
从 2008 开始,您就已经安装了 Powershell。我建议查看成功备份后执行的 psh 脚本,以通过网络进行压缩和复制。这很可能是备份后的第二个工作步骤。
您也可以采用老式方法编写批处理文件来进行压缩和复制。然后在备份作业/步骤之后再次将其作为 cmdshell 作业步骤调用。
Since you've got 2008, you've got Powershell installed. I would suggest looking at a psh script executed after a successful backup to compress and copy over the wire. This would most likely be a second job step after your backup.
You can also go old-school and write a batch file to do the compress and copy. Then invoke that as a cmdshell job step, again after your backup job/step.
如果您是程序员,您可以创建一个应用程序,通过 SMO 获取数据库备份,并通过可用库将此文件压缩为 .gz 文件。
if you are a programmer you can make an application that get your db backup by SMO and zip this file to .gz file by available libraries.
试试这个链接:
[http://www.sqlhub.com/2009/05/copy-files-with-sql-server-from-one.html][1]
简而言之:
1 - 您必须启用“Ole Automation procedures”
2 - 修改&运行此脚本进行测试:
3 - 创建维护计划:
3.1 - 添加“备份数据库任务”并确保选择“设置备份压缩”= 压缩备份。 (这将以压缩格式创建备份)
3.2 - 使用上述脚本添加“执行 T-SQL 语句任务”,该脚本将移动将在 3.1 任务之后执行的文件:)。
try this link:
[http://www.sqlhub.com/2009/05/copy-files-with-sql-server-from-one.html][1]
in short:
1 - you must enable "Ole Automation Procedures"
2 - modify & run this script to test:
3 - create a maintenance plan:
3.1 - add a "Back Up Database Task" and make sure to choose "Set backup compression" = Compress backup. (this will create your backups in a compressed format)
3.2 - add an "Execute T-SQL Statement Task" with the above script that'll move your files that'll execute after the 3.1 task :).
尝试 SQL Backup Master,它可以压缩备份并将其移动到网络(或本地)文件夹。还可以将压缩的备份文件移动到 FTP、Dropbox、Amazon S3 或 Google Drive。基本版是免费的。
Try SQL Backup Master, which can zip backups and move them to a network (or local) folder. Can also move zipped backup files to FTP, Dropbox, Amazon S3, or Google Drive. Basic edition is free.
备份后压缩文件需要花费大量时间。使用 SQL Server 虚拟设备接口的备份程序可以解决您的任务并减少总体处理时间。尝试EMS SQL Backup,它还允许将压缩备份发送到网络位置、FTP 或云。
Zipping the file after backup takes significant time. Backup programs which use Virtual Device Interface of SQL Server solve your task and decrease overall process time. Try EMS SQL Backup which also allows sending compressed backups to network locations, FTP or clouds.
您可以使用备份助手。这将是一个解决方案。
您需要为此计划制定时间表。 (比如每小时)。
然后您需要在 Appsettings.json 中配置备份文件路径和 ftp 凭据
You can use Backup Assistant. It is going to be a solution.
You need to set a schedule for this program. (like every hour).
And then you need to configure your backup file paths and your ftp credentials in Appsettings.json