diff --git a/build_debian.sh b/build_debian.sh index 11c3e85adb88..3c8519b6288c 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -729,6 +729,22 @@ SONIC_VERSION_CACHE=${SONIC_VERSION_CACHE} \ DBGOPT="${DBGOPT}" \ scripts/collect_host_image_version_files.sh $CONFIGURED_ARCH $IMAGE_DISTRO $TARGET_PATH $FILESYSTEM_ROOT +# Install libc6-dev and python3-dev for compiling python-lzf +sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install libc6-dev python3-dev + +# Install python-lzf +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'python-lzf==0.2.4' + +# Install rdbtools +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install 'rdbtools==0.1.15' + +# Uninstall libc6-dev and python3-dev for compiling python-lzf +sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove libc6-dev +sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove python3-dev + +## Copy saidump.sh +sudo cp ./files/scripts/saidump.sh $FILESYSTEM_ROOT/usr/local/bin/saidump.sh +sudo chmod +x $FILESYSTEM_ROOT/usr/local/bin/saidump.sh # Remove GCC sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y remove gcc diff --git a/files/scripts/saidump.sh b/files/scripts/saidump.sh new file mode 100755 index 000000000000..76e2dab9dd51 --- /dev/null +++ b/files/scripts/saidump.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +save_saidump_by_rdb() { + #1. Save the Redis data. + sudo sonic-db-cli -n asic$1 SAVE > /dev/null + #2. Move dump files to /var/run/redisX/ + docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" + #3. Run rdb command to convert the dump files into JSON files + sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null + #4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. + docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" + #5. clear + sudo rm -f /var/run/redis$1/dump.rdb + sudo rm -f /var/run/redis$1/dump.json +} + +NUM_ASICS=`python -c 'from sonic_py_common.multi_asic import get_num_asics; print(get_num_asics())'` + + +if (( $# == 0 && $NUM_ASICS == 1 )); then + save_saidump_by_rdb +#validate if the argument is an integer +elif [[ "$1" =~ [0-9]+ ]] && (( $# == 1 && $1 >= 0 && $1 < $NUM_ASICS )) ; then + save_saidump_by_rdb $1 +else + echo "The number of ASICS is $NUM_ASICS." + echo "Usage:" + echo "saidump.sh or NULL" + echo " should be 0 ~ NUM_ASICS." + echo " E.g. \"saidump.sh 1\" is OK when NUMASICS is 2." + echo " NULL" + echo " E.g. \"saidump.sh\" is OK when NUMASICS is 1." +fi \ No newline at end of file