(Tomcat) Backup WAR on Deploy

2020-07-18 03:18发布

Are there any built in mechanisms to backup a war file on deploy in Tomcat?

For example, I deploy whosit.war. I want the current whosit.war that's deployed to backup to whosit-backup.war. Or if each deploy kept an extra copy of the deploy at whosit-deploy-20110317-211037.war. etc etc.

Obviously I could add this to my deploy script but it would make my life so nice if Tomcat did anything like the above.

标签: tomcat
2条回答
虎瘦雄心在
2楼-- · 2020-07-18 04:03

You can tag a deploy when deploying a webapp remotely by specifying the tag attribute. If you're using Maven you can specify the tag with the tomcat-plugin. Assuming you already have the plugin setup you need only to specify the property. Example:

<properties>
    <maven.tomcat.url>http://example.com:8080/manager</maven.tomcat.url>
    <tomcat.username>tomcat</tomcat.username>
    <tomcat.password>tomcat</tomcat.password>
    <maven.tomcat.tag>mytag</maven.tomcat.tag>
    <maven.tomcat.path>/myapp</maven.tomcat.path>
</properties>

This will create a copy of the war in the work directory of your manager in a directory named after your tag (e.g. $CATALINA_HOME/work/Catalina/localhost/manager/mytag). You can retrieve and redeploy this war through the manager by specifying the path and tag:

http://example.com:8080/manager/deploy?path=/myapp&tag=mytag

Note: if the manager work directory ever gets deleted then your tagged deploys will be gone.

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-07-18 04:05

I think you'll have to script this up yourself.

查看更多
登录 后发表回答