Limits on backing up the webapps directory while Tomcat is running
0 reputation · 22 Dec 2021, 22:34 UTC
0 reputation · 22 Dec 2021, 22:34 UTC
The goal is to obtain a file‑system backup of a Tomcat webapp that reflects a consistent state without requiring the server to be stopped.
Tomcat’s documentation describes copying the webapps directory (or the whole CATALINA_BASE) as a common backup method, but it does not specify whether the operation is safe while Tomcat is actively serving requests, compiling JSPs, or holding file locks on deployed archives.
Is it safe to copy the webapps directory while Tomcat is processing requests? What corruption risks arise from concurrent JSP class file writes during a backup? Should administrators quiesce Tomcat or rely on the Manager app’s undeploy/deploy cycle for a reliable backup?
35275 reputation · 23 Dec 2021, 05:46 UTC
Copying the webapps directory while Tomcat is actively serving requests is not guaranteed safe. In‑flight JSP compilations or class‑loader writes can leave partially written .class files in the snapshot, producing a deployment that fails to start or throws ClassNotFoundException or InvalidClassFormat errors after restore.
.class file to the work directory or the exploded WAR. If the copy starts mid‑write, the resultant class file may be truncated.CATALINA_BASE immediately before initiating the copy.
# Example with LVM
lvcreate --size 10G --snapshot --name webapps_snap /dev/vg1/catalina_base
# Mount the snapshot and copy
mount /dev/vg1/webapps_snap /mnt/snap
rsync -a /mnt/snap/webapps /backup/webapps-$(date +%F)
# After copy, delete the snapshot
lvremove /dev/vg1/webapps_snap
reloadable="false" if using a single instance) to stop all JSP compilation threads.
# Using the Manager REST endpoint
curl -u admin:password "http://localhost:8080/manager/text/undeploy?path=/myapp"
# Wait a few seconds for cleanup threads to finish
rsync -a /opt/tomcat/webapps/myapp /backup/myapp-$(date +%F)
curl -u admin:password "http://localhost:8080/manager/text/deploy?path=/myapp&update=true&war=file:/opt/tomcat/webapps/myapp.war"
CATALINA_BASE or webapps, then restart.
systemctl stop tomcat
rsync -a /opt/tomcat /backup/tomcat-$(date +%F)
systemctl start tomcat
sha256sum -r on the original and copied directories; mismatches alone don’t prove corruption but indicate changes during the copy.To fine‑tune the recommendation, could you confirm whether the webapp is deployed as an exploded directory or as a WAR file, and whether JSP compilation is enabled in your environment? This affects whether the undeploy‑copy‑deploy cycle will suffice or a snapshot is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.