mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-10-30 00:57:33 -04:00
fix(apache-tomcat): restore the update backup from its real store (#18145)
The A-B refactor (#15075) moved the backup to create_backup but kept the old hand-written restore, which reads $BACKUP_DIR. Nothing sets it any more, so the first restore cp failed after the install dir was wiped: the update aborted with Tomcat stopped and the config left in /opt/apache-tomcat.backup. Restore conf and webapps with restore_backup, which also removes the store. lib gets a store of its own so only the jars the new release lacks (JDBC drivers and the like) are copied back; restoring it whole would put the old Tomcat jars over the new ones. Co-authored-by: Matt Daleo <12395090+mazelado@users.noreply.github.com> Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,40 +51,37 @@ function update_script() {
|
||||
exit
|
||||
fi
|
||||
|
||||
msg_info "Stopping Tomcat service"
|
||||
systemctl stop tomcat
|
||||
msg_ok "Stopped Tomcat service"
|
||||
|
||||
create_backup $TOMCAT_DIR/conf
|
||||
[[ -d $TOMCAT_DIR/webapps ]] && create_backup $TOMCAT_DIR/webapps
|
||||
[[ -d $TOMCAT_DIR/lib ]] && create_backup $TOMCAT_DIR/lib
|
||||
|
||||
msg_info "Downloading Tomcat ${LATEST_VERSION}"
|
||||
TOMCAT_URL="https://dlcdn.apache.org/tomcat/tomcat-${TOMCAT_MAJOR}/v${LATEST_VERSION}/bin/apache-tomcat-${LATEST_VERSION}.tar.gz"
|
||||
curl -fsSL "$TOMCAT_URL" -o /tmp/tomcat-update.tar.gz
|
||||
msg_ok "Downloaded Tomcat ${LATEST_VERSION}"
|
||||
|
||||
# Keep only the jars in lib that the new release does not ship (JDBC drivers
|
||||
# and the like). ecj and jakartaee-migration are Tomcat's own and change name
|
||||
# with each version, so they are never carried over.
|
||||
TOMCAT_FILES=$(tar -tzf /tmp/tomcat-update.tar.gz)
|
||||
BACKUP_PATHS=("$TOMCAT_DIR/conf")
|
||||
[[ -d $TOMCAT_DIR/webapps ]] && BACKUP_PATHS+=("$TOMCAT_DIR/webapps")
|
||||
for jar in "$TOMCAT_DIR"/lib/*.jar; do
|
||||
[[ -f $jar ]] || continue
|
||||
case "${jar##*/}" in ecj-*.jar | jakartaee-migration-*.jar) continue ;; esac
|
||||
grep -qxF "apache-tomcat-${LATEST_VERSION}/lib/${jar##*/}" <<<"$TOMCAT_FILES" || BACKUP_PATHS+=("$jar")
|
||||
done
|
||||
|
||||
msg_info "Stopping Tomcat service"
|
||||
systemctl stop tomcat
|
||||
msg_ok "Stopped Tomcat service"
|
||||
|
||||
create_backup "${BACKUP_PATHS[@]}"
|
||||
|
||||
msg_info "Installing update"
|
||||
rm -rf "${TOMCAT_DIR:?}"/*
|
||||
tar --strip-components=1 -xzf /tmp/tomcat-update.tar.gz -C "$TOMCAT_DIR"
|
||||
rm -f /tmp/tomcat-update.tar.gz
|
||||
msg_ok "Installed update"
|
||||
|
||||
msg_info "Restoring configuration and applications"
|
||||
cp -a "$BACKUP_DIR/conf"/* "$TOMCAT_DIR/conf/"
|
||||
cp -a "$BACKUP_DIR/webapps"/* "$TOMCAT_DIR/webapps/" 2>/dev/null || true
|
||||
if [[ -d "$BACKUP_DIR/lib" ]]; then
|
||||
for jar in "$BACKUP_DIR/lib"/*.jar; do
|
||||
[[ -f $jar ]] || continue
|
||||
jar_name=$(basename "$jar")
|
||||
if [[ ! -f "$TOMCAT_DIR/lib/$jar_name" ]]; then
|
||||
cp "$jar" "$TOMCAT_DIR/lib/"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
rm -rf "$BACKUP_DIR"
|
||||
restore_backup
|
||||
chown -R root:root "$TOMCAT_DIR"
|
||||
msg_ok "Restored configuration and applications"
|
||||
|
||||
msg_info "Starting Tomcat service"
|
||||
systemctl start tomcat
|
||||
|
||||
Reference in New Issue
Block a user