批处理脚本安装过程
我正在计划一个程序,使用使用 Windows 批处理脚本的现有程序的高级版本向客户发布我们的软件。 我希望改进这个过程并自动安装以下项目:
- 文件。 文件只需复制到目的地即可。
- MSSQL 数据库。 我想我将使用 OSQL 命令针对数据库运行这些命令。
- IIS 虚拟目录。 Windows 的服务器版本通常安装了 IIS 工具包,其中包含一些用于从命令行创建虚拟目录等的工具,因此我将使用它。 我认为“iiscnfg”是我的用于将以前保存的配置文件插入 IIS。
- Windows 服务。 我们的服务能够从命令行自行安装。
因此,对于每个应用程序部署,我都有这样的结构:
Releases\
| get-release.bat
| Release1\
| Release2\
| Release3\
| | Content\
| | | Application1\
| | | | bin\
| | | | | Application1.exe
| | | | etc\
| | | | | Application1.config
| | | | db\
| | | | | CreateDatabase.sql
| | | | | CreateTable1.sql
| | | | | CreateTable2.sql
| | | | iis\
| | | | | Application1Web.xml
| | | | pre.bat
| | | | post.bat
| | | | environment.bat
| | | Application2\
| | | Application3\
| | | Application4\
| | Release1.doc
因此,基本上,您打开终端和 CD 到 Releases 目录,运行类似以下的命令:
get-release "Release3"
这将对 Release3 目录中的所有应用程序运行一系列命令,并复制所有文件、配置、安装所有数据库和 iis 虚拟目录。
它还有一些功能,例如备份文件的目标目录等,但目前与此无关。
我的问题是是否有人有进行此类部署的经验,如果有任何错误我可以从其他人的经验中学习。
不幸的是,我们不能使用 MSI 软件包或 NullSoft 软件包(我暂时忘记了他的名字)。 如果不是这样完成的,那么它是手动完成的,所以我真的很想在这里帮助自己。
I am planning a procedue to release our software to our customers using an advanced version of an existing procedure which uses windows batch scripts. I am hoping to improve this process and automate the installation of the following items:
- Files. Files are simply copied to a destination.
- MSSQL Databases. I guess I'll use the OSQL command to run these against a database.
- IIS Virtual Directories. Server versions of windows generally have the IIS toolkit installed which has some tools for creating virtual directories and whatnot from the commandline so I will use that. I think the "iiscnfg" is the one I use to insert previously saved config files into IIS.
- Windows Services. Our services have the ability to install themself from the commandline.
So for each application deployment I have a structure like this:
Releases\
| get-release.bat
| Release1\
| Release2\
| Release3\
| | Content\
| | | Application1\
| | | | bin\
| | | | | Application1.exe
| | | | etc\
| | | | | Application1.config
| | | | db\
| | | | | CreateDatabase.sql
| | | | | CreateTable1.sql
| | | | | CreateTable2.sql
| | | | iis\
| | | | | Application1Web.xml
| | | | pre.bat
| | | | post.bat
| | | | environment.bat
| | | Application2\
| | | Application3\
| | | Application4\
| | Release1.doc
So basically you open a terminal and CD to the Releases directory, run a command something like:
get-release "Release3"
which will run a series of commands on all the applications in the Release3 directory and copy all the files, configs, install all the databases and iis virtual directories.
There is a little bit more which it does like backup the destination directory for files, etc. but its irrelevant for the moment.
My question is whether anyone has any experience doing a deployment like this and if there is any mistakes I can learn from other peoples experience.
Unfortunately we cannot go with MSI packages or that NullSoft one (who's name escapes me for the moment). If its not done like this it is done manually so I'm really trying to help myself here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经滚动了几个这样的脚本,要处理的最丑陋的部分是错误处理——如何检测错误,发生错误时做什么,是否可以回滚迄今为止所做的所有更改,等等。 如果您正在进行全新安装,则相对简单,但如果您正在更新现有系统,则几乎没有那么简单。 (您永远不应该假设它每次都会完美地工作 - 毕竟,明天的 MS 更新可能会破坏今天的脚本。)
只有几件事;)您无法在批处理文件中合理地完成这些操作。 您可以插入 VB 脚本、java 脚本、一些 Powershell 调用或其他任何东西来处理困难的事情吗?
I've rolled several scripts like this, and the ugliest parts to deal with are error handling -- how do you detect errors, what do you do when they occur, can you roll back all changes made to date, and so on. Relatively simple if you're doing a fresh install, not nearly so simple if you're updating an existing system. (You should never assume it will work perfectly every time--tomorrow's MS update might break today's script, after all.)
There are just a few things ;) you can't reasonably do from within a batch file. Can you slip in VB scripts, java scripts, some Powershell calls, or anything else to handle the difficult stuff?
我认为使用批处理文件执行此类操作没有任何问题。 但是,您必须考虑一下机器之间的一些差异(缺少目录、已经存在的目录、已经存在的文件、文件版本等)可能是什么,解决它们,并在各种机器。
遗憾的是您无法使用安装程序,因为安装程序已经为您解决了大部分问题。 本质上,您将滚动自己的安装程序,并且您不会从安装程序为您提供的经验教训、最佳实践等中受益。
如果没有安装程序,您可能无法做的另一件事是安装被操作系统锁定的文件。 安装程序通过将文件复制到临时位置,将“重新启动时加载”条目放入注册表,然后要求用户重新启动计算机来处理此问题。
I don't see any problem with doing things like this with a batch file. However, you're going to have to give some thought to what some of the differences between machines (missing directories, already existing directories, already existing files, file versions, etc.) might be, address them, and test really well on a variety of machines.
It's too bad you can't use an installer, because installers already mitigate most of these issues for you. In essence, you will be rolling your own installer, and you will not benefit from lessons learned, best practices, etc., that an installer will give you.
Another thing you might not be able to do without an installer is install a file that is being locked by the operating system. Installers deal with this by copying the file to a temporary location, putting a "load on restart" entry into the registry, and then asking the user to restart the computer.