Avijit
Avijit

Reputation: 1800

Delete Snapshots of 30 days older from HBASE Using Unix Shell Script

I want to delete 30 days older snapshots from HBASE using shell script. I have written below function but the function will be deleting all snapshots. 30 days older logic also need to be implemented.

deleteSnapshot() {

  echo -e "list_snapshots '${NAMESPACE}_${TABLE}'" | hbase shell -n | grep ''${NAMESPACE}'_'${TABLE}'' 2>/dev/null

  local RET=$?

  if [ ${RET} -eq 0 ]; then
      echo "Deleting Snapshot ${NAMESPACE}_${TABLE}"
      echo -e "delete_snapshot '${NAMESPACE}_${TABLE}'" | hbase shell -n 2>/dev/null
      echo "Successfully deleted Snapshot ${NAMESPACE}_${TABLE}"
  fi
}

Help need on that.

Upvotes: 2

Views: 3033

Answers (2)

Petro
Petro

Reputation: 3652

The quick and dirty way to delete multiple snapshots at once:

If our snapshot name was: table_name_snapshot_20190701

delete_all_snapshot 'table_name_snapshot_201907.*'

This deletes anything from July. The . in the name is used as a cutoff for the rest of the snapshot name (which we've replaced with a wildcard *)

Upvotes: 2

Nicole
Nicole

Reputation: 889

You can append the time stamp to the the snapshot name and apply a regex to match only the snapshots that are older than 30 days.

You can refer the document:

https://www.cloudera.com/documentation/enterprise/5-2-x/topics/cm_bdr_managing_hbase_snapshots.html#concept_aqd_sry_bp

Upvotes: 2

Related Questions