Fix OS upgrade script: date format and backup dir permission

- date -u +%H:%M:%S UTC → ts() helper with date -u +"%H:%M:%S UTC"
  (UTC as a separate word was being treated as an extra date argument)
- Backup dir changed from /var/novacpx/backups/ (root-owned, doesn't exist)
  to /tmp/novacpx-backup-TIMESTAMP/ (always writable by www-data)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 22:24:49 +00:00
parent 2f141973c1
commit f9d423b15a
+11 -10
View File
@@ -144,32 +144,33 @@ match ($action) {
$script = "/tmp/ncpx-os-update-{$jobId}.sh";
$webSvc = defined('WEB_SERVER') && WEB_SERVER === 'nginx' ? 'nginx' : 'apache2';
$webRoot = defined('WEB_ROOT') ? WEB_ROOT : '/srv/novacpx/public';
$backupDir = '/var/novacpx/backups/pre-os-update-' . date('YmdHis');
$backupDir = '/tmp/novacpx-backup-' . date('YmdHis');
$sh = <<<BASH
#!/bin/bash
exec > {$logFile} 2>&1
echo "[$(date -u +%H:%M:%S UTC)] Preparing backup..."
ts() { date -u +"%H:%M:%S UTC"; }
echo "[\$(ts)] Preparing backup..."
mkdir -p {$backupDir}
cp -a {$webRoot} {$backupDir}/public 2>/dev/null
echo "[$(date -u +%H:%M:%S UTC)] Updating package lists..."
echo "[\$(ts)] Updating package lists..."
sudo apt-get update -q
echo "[$(date -u +%H:%M:%S UTC)] Running upgrade (non-interactive)..."
DEBIAN_FRONTEND=noninteractive sudo apt-get upgrade -y \\
-o Dpkg::Options::="--force-confdef" \\
echo "[\$(ts)] Running upgrade (non-interactive)..."
DEBIAN_FRONTEND=noninteractive sudo apt-get upgrade -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold"
UPGRADE_EXIT=\$?
echo "[$(date -u +%H:%M:%S UTC)] Checking services..."
echo "[\$(ts)] Checking services..."
for SVC in {$webSvc} mysql postfix dovecot; do
if systemctl is-active --quiet \$SVC 2>/dev/null; then :; else
echo "[$(date -u +%H:%M:%S UTC)] Restarting \$SVC..."
echo "[\$(ts)] Restarting \$SVC..."
sudo systemctl restart \$SVC 2>/dev/null && echo " \$SVC restarted OK" || echo " \$SVC restart FAILED"
fi
done
if [ \$UPGRADE_EXIT -eq 0 ]; then
echo "[$(date -u +%H:%M:%S UTC)] Upgrade complete."
echo "[\$(ts)] Upgrade complete."
else
echo "[$(date -u +%H:%M:%S UTC)] Upgrade finished with errors (exit code \$UPGRADE_EXIT)."
echo "[\$(ts)] Upgrade finished with errors (exit code \$UPGRADE_EXIT)."
fi
echo \$UPGRADE_EXIT > {$doneFile}
BASH;