Clear old Snapshots

  • To check oldest snapshot:

nodetool listsnapshots | grep opscenter | head -3 | tail -1 | awk '{print $1}'
  • To clear oldest snapshot:

nodetool clearsnapshot -t $(nodetool listsnapshots | grep opscenter | head -3 | tail -1 | awk '{print $1}')
  • Bash script:

!/bin/bash

get_latest_snapshot=$(nodetool listsnapshots | awk '{print $1}' | grep opscenter | sort | tail -1)

get_older_snapshot=$(nodetool listsnapshots | awk '{print $1}' | grep opscenter | sort | head -1)


if [ "${get_latest_snapshot}" != "${get_older_snapshot}" ]; then

    echo "Strings are not equal. Clearing old snapshot"
    # nodetool clearsnapshot -t ${get_older_snapshot}
    echo "Done"

else

    echo "Strings are equal. There is only the latest snapshot left"

fi

Last updated