From b5e191bc077e04a8126274b82d14885c0e974134 Mon Sep 17 00:00:00 2001 From: Vaibhav Hemant Dixit Date: Fri, 3 Mar 2023 20:55:57 +0000 Subject: [PATCH 1/2] [warm/fast-reboot] Backup logs from tmpfs to disk during fast/warm shutdown --- scripts/fast-reboot | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 5e7cc34bc9..cbc0875d8a 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 '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 From e1b449bc04eb8c3e3246e71d34fa248067bbc9e9 Mon Sep 17 00:00:00 2001 From: Vaibhav Hemant Dixit Date: Fri, 3 Mar 2023 21:16:34 +0000 Subject: [PATCH 2/2] Use grep -c to suppress the output to a single count --- scripts/fast-reboot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index cbc0875d8a..2fb744f404 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -808,7 +808,7 @@ fi debug "Rebooting with ${REBOOT_METHOD} to ${NEXT_SONIC_IMAGE} ..." LOGS_ON_TMPFS=0 -df --output=fstype /var/log* | grep 'tmpfs' || LOGS_ON_TMPFS=$? +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