从 shell 脚本增量部署

发布于 2024-09-06 08:22:04 字数 612 浏览 2 评论 0原文

我有一个项目,我被迫使用 ftp 作为将文件部署到实时服务器的方法。 我正在 Linux 上进行开发,所以我编写了一个 bash 脚本来备份 ftp 服务器的内容, 删除 ftp 上的所有文件,并从 Mercurial 存储库上传所有新文件。 (并处理用户上传的文件和文件夹,并进行部署后更改等)

它运行良好,但项目开始变得足够大,导致部署过程太长。

我想修改脚本来查找哪些文件已更改,并仅部署修改后的文件。 (备份很好,因为它是atm)

我使用mercurial作为VCS,所以我的想法是以某种方式请求两个版本之间更改的文件,迭代更改的文件, 并上传每个修改的文件,并删除每个删除的文件。

我可以使用 hg log -vr rev1:rev2 ,从输出中,我可以使用 grep/sed/etc 切出更改的文件。

两个问题:

我听说过解析 ls 的输出会导致疯狂的恐怖故事,所以我的猜测是这同样适用于这里, 如果我尝试解析 hg log 的输出,变量将经历分词和各种转换。

hg log 没有告诉我文件被修改/添加/删除。修改和删除的文件之间的区别是最少的。

那么,这样做的正确方法是什么?我使用 yafc 作为 ftp 客户端,以防需要,但愿意切换。

I have a project, where I'm forced to use ftp as a means of deploying the files to the live server.
I'm developing on linux, so I hacked together a bash script that makes a backup of the ftp server's contents,
deletes all the files on the ftp, and uploads all the fresh files from the mercurial repository.
(and taking care of user uploaded files and folders, and making post-deploy changes, etc)

It's working well, but the project is starting to get big enough to make the deployment process too long.

I'd like to modify the script to look up which files have changed, and only deploy the modified files. (the backup is fine atm as it is)

I'm using mercurial as a VCS, so my idea is to somehow request the changed files between two revisions from it, iterate over the changed files,
and upload each modified file, and delete each removed file.

I can use hg log -vr rev1:rev2, and from the output, I can carve out the changed files with grep/sed/etc.

Two problems:

I have heard the horror stories that parsing the output of ls leads to insanity, so my guess is that the same applies to here,
if I try to parse the output of hg log, the variables will undergo word-splitting, and all kinds of transformations.

hg log doesn't tell me a file is modified/added/deleted. Differentiating between modified and deleted files would be the least.

So, what would be the correct way to do this? I'm using yafc as an ftp client, in case it's needed, but willing to switch.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花辞树 2024-09-13 08:22:04

您可以使用自定义样式来为您进行解析。

hg log --rev rev1:rev2 --style mystyle

然后将其通过管道传递给 sort -u 以获取唯一的文件列表。文件“mystyle”将如下所示:

changeset = '{file_mods}{file_adds}\n'
file_mod = '{file_mod}\n'
file_add = '{file_add}\n'

mods 和添加模板是修改或添加的文件。对于已删除的文件,有类似的 file_delsfile_del 模板。

或者,您可以使用 hg status -ma --rev rev1-1:rev2 在修改/添加文件之前添加 MA 。您需要传递一个不同的修订范围,比 rev1 小一个,因为它是自该“基线”以来的状态。删除的文件类似 - 您需要 -d 标志,并在每个删除的文件之前添加 D

You could use a custom style that does the parsing for you.

hg log --rev rev1:rev2 --style mystyle

Then pipe it to sort -u to get a unique list of files. The file "mystyle" would look like this:

changeset = '{file_mods}{file_adds}\n'
file_mod = '{file_mod}\n'
file_add = '{file_add}\n'

The mods and adds templates are files modified or added. There is a similar file_dels and file_del template for deleted files.

Alternatively, you could use hg status -ma --rev rev1-1:rev2 which adds an M or an A before modified/added files. You need to pass a different revision range, one less than rev1, as it is the status since that "baseline". Deleted files are similar - you need the -d flag and a D is added before each deleted file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文