Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/rdk/backup_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ if [ -f /etc/env_setup.sh ]; then
. /etc/env_setup.sh
fi

APP_LOG="apps"
PREV_LOG_PATH="$LOG_PATH/PreviousLogs"
PREV_LOG_BACKUP_PATH="$LOG_PATH/PreviousLogs_backup"
APP_LOG_PATH="$LOG_PATH/apps"
APP_PREV_LOG_PATH="$PREV_LOG_PATH/apps"

backupLog() {
timestamp=$(/bin/timestamp)
Expand All @@ -42,11 +45,21 @@ if [ ! -d "$LOG_PATH" ];then
mkdir -p "$LOG_PATH"
fi

# create app log workspace if not there
if [ ! -d "$APP_LOG_PATH" ];then
mkdir -p "$APP_LOG_PATH"
fi

# create intermediate log workspace if not there
if [ ! -d $PREV_LOG_PATH ];then
mkdir -p $PREV_LOG_PATH
fi

# create intermediate app log workspace if not there
if [ ! -d $APP_PREV_LOG_PATH ];then
mkdir -p $APP_PREV_LOG_PATH
fi

# create log backup workspace if not there
if [ ! -d $PREV_LOG_BACKUP_PATH ];then
mkdir -p $PREV_LOG_BACKUP_PATH
Expand Down Expand Up @@ -104,21 +117,36 @@ if [ "$HDD_ENABLED" = "false" ]; then
if [ $? -ne 0 ]; then
backupLog "Error:Failed to Move the logs from $LOG_PATH to $PREV_LOG_PATH"
fi

find $APP_LOG_PATH -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" \) -exec mv '{}' $APP_PREV_LOG_PATH \;
if [ $? -ne 0 ]; then
backupLog "Error:Failed to Move the app logs from $APP_LOG_PATH to $APP_PREV_LOG_PATH"
fi

elif [ ! -f "$PREV_LOG_PATH/$sysLogBAK1" ]; then
# box reboot within 8 minutes after reboot
backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" $BAK1
backupAndRecoverLogs "$APP_LOG_PATH/" "$APP_PREV_LOG_PATH/" mv "" $BAK1
elif [ ! -f "$PREV_LOG_PATH/$sysLogBAK2" ]; then
# box reboot within 8 minutes after reboot
backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" $BAK2
backupAndRecoverLogs "$APP_LOG_PATH/" "$APP_PREV_LOG_PATH/" mv "" $BAK2
elif [ ! -f "$PREV_LOG_PATH/$sysLogBAK3" ]; then
# box reboot within 8 minutes after reboot
backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" $BAK3
backupAndRecoverLogs "$APP_LOG_PATH/" "$APP_PREV_LOG_PATH/" mv "" $BAK3
else
# box reboot within 8 minutes after reboot
backupAndRecoverLogs "$PREV_LOG_PATH/" "$PREV_LOG_PATH/" mv "$BAK1" ""
backupAndRecoverLogs "$PREV_LOG_PATH/" "$PREV_LOG_PATH/" mv "$BAK2" "$BAK1"
backupAndRecoverLogs "$PREV_LOG_PATH/" "$PREV_LOG_PATH/" mv "$BAK3" "$BAK2"
backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" "$BAK3"

#backup for apps log
backupAndRecoverLogs "$APP_PREV_LOG_PATH/" "$APP_PREV_LOG_PATH/" mv "$BAK1" ""
backupAndRecoverLogs "$APP_PREV_LOG_PATH/" "$APP_PREV_LOG_PATH/" mv "$BAK2" "$BAK1"
backupAndRecoverLogs "$APP_PREV_LOG_PATH/" "$APP_PREV_LOG_PATH/" mv "$BAK3" "$BAK2"
backupAndRecoverLogs "$APP_LOG_PATH/" "$APP_PREV_LOG_PATH/" mv "" "$BAK3"
fi

/bin/touch "$PREV_LOG_PATH/last_reboot"
Expand All @@ -132,14 +160,17 @@ else
if [ ! -f "$PREV_LOG_PATH/$sysLog" ]; then
backupLog "Move logs from $LOG_PATH to $PREV_LOG_PATH"
find $LOG_PATH -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" -o -name "bootlog" \) -exec mv '{}' $PREV_LOG_PATH \;
find $APP_LOG_PATH -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" \) -exec mv '{}' $APP_PREV_LOG_PATH \;
/bin/touch $PREV_LOG_PATH/last_reboot
else
find "$PREV_LOG_PATH" -name last_reboot | xargs rm >/dev/null
timestamp=$(date "+%m-%d-%y-%I-%M-%S%p")
LogFilePathPerm="$PREV_LOG_PATH/logbackup-$timestamp"
mkdir -p "$LogFilePathPerm"
mkdir -p "$LogFilePathPerm/$APP_LOG"
backupLog "Move logs from $LOG_PATH to $LogFilePathPerm"
find "$LOG_PATH" -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" -o -name "bootlog" \) -exec mv '{}' "$LogFilePathPerm" \;
find "$APP_LOG_PATH" -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" \) -exec mv '{}' "$LogFilePathPerm/$APP_LOG" \;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not just about backup. A new sub directory in logs is not in alignment with the systems architecture. This also means that we will also loose capabilities to get telemetry insights.
Log monitoring, upload and other systems dealing with logging also might need to be thoughtfully revisisted.
This change cannot be taken in without involving system architects.

/bin/touch "$LogFilePathPerm/last_reboot"
fi
fi
Expand Down