From cc78747409aad52b5b2e60169691f7e6db3ca9ee 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 dbd13aa9f2..16ba9e4f23 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -752,6 +752,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