Skip to content

Commit 36e98b3

Browse files
vaibhavhdisabelmsft
authored andcommitted
[warm/fast-reboot] Backup logs from tmpfs to disk during fast/warm shutdown (sonic-net#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.
1 parent a1c3bd5 commit 36e98b3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

scripts/fast-reboot

+11
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,17 @@ fi
806806
807807
# Reboot: explicitly call Linux native reboot under sbin
808808
debug "Rebooting with ${REBOOT_METHOD} to ${NEXT_SONIC_IMAGE} ..."
809+
810+
LOGS_ON_TMPFS=0
811+
df --output=fstype /var/log* | grep -c 'tmpfs' || LOGS_ON_TMPFS=$?
812+
if [[ LOGS_ON_TMPFS -eq 0 ]]; then
813+
debug "Backup shutdown logs to /host/logs_before_reboot"
814+
mkdir -p /host/logs_before_reboot || /bin/true
815+
# maxdepth 2: find files within 2 nested directories (eg. /var/log/ and /var/log/swss/)
816+
# mmin 30: find files written in past 30 minutes
817+
find /var/log -maxdepth 2 -mmin -30 -type f | xargs -I {} cp {} /host/logs_before_reboot/ || /bin/true
818+
fi
819+
809820
exec ${REBOOT_METHOD}
810821
811822
# Should never reach here

0 commit comments

Comments
 (0)