From c2bc150a6a05c97362d540c874deff81fad6f870 Mon Sep 17 00:00:00 2001 From: Vaibhav Hemant Dixit Date: Mon, 6 Mar 2023 10:56:51 -0800 Subject: [PATCH] [warm/fast-reboot] Backup logs from tmpfs to disk during fast/warm shutdown (#2714) Goal: Preserve logs during TOR upgrades and shutdown Need: Below PRs moved logs from disk to tmpfs for specific hwskus. Due to these changes, shutdown path logs are now lost. The logs in shutdown path are crucial for debug purposes. sonic-net/sonic-buildimage#13805 sonic-net/sonic-buildimage#13587 sonic-net/sonic-buildimage#13587 How I did it Check if logs are on tmpfs. If yes, backup logs from /var/log How to verify it Verified on a physical device - logs on tmfs are backed up for past 30 minutes. --- scripts/fast-reboot | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 5e7cc34bc9..2fb744f404 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -806,6 +806,17 @@ fi # Reboot: explicitly call Linux native reboot under sbin debug "Rebooting with ${REBOOT_METHOD} to ${NEXT_SONIC_IMAGE} ..." + +LOGS_ON_TMPFS=0 +df --output=fstype /var/log* | grep -c 'tmpfs' || LOGS_ON_TMPFS=$? +if [[ LOGS_ON_TMPFS -eq 0 ]]; then + debug "Backup shutdown logs to /host/logs_before_reboot" + mkdir -p /host/logs_before_reboot || /bin/true + # maxdepth 2: find files within 2 nested directories (eg. /var/log/ and /var/log/swss/) + # mmin 30: find files written in past 30 minutes + find /var/log -maxdepth 2 -mmin -30 -type f | xargs -I {} cp {} /host/logs_before_reboot/ || /bin/true +fi + exec ${REBOOT_METHOD} # Should never reach here