Fir3net.com is pleased to release dbdel ver3.1. This is basically a wrapper for Check Points existing dbver tool, but allows you to remove 100`s of Database Revisions with one simple command string. Unlike dbver where you have to add each database revision id. This allows you to add the amount your want to remove and then does the rest for you.
Script
#!/bin/bash # # DB Revision Deletion Tool v3.1 # Author : Fir3net.com # Date : 13/5/10 # . /opt/CPshrd-R??/tmp/.CPprofile.sh ### CHECK OS IS LINUX ### OS=`uname` if [ "${OS}" != "Linux" ] ; then echo "${OS}" is not currently supported by dbdel\. exit 1 fi ### VARIABLES ### VERDB=$FWDIR/conf/db_versions/database/versioning_db.fws TOTALDBLIST=`grep _id $VERDB | sed 's/.*(\|)//g'` TOTALDB=`grep _id $VERDB | sed 's/.*(\|)//g' | wc -l | sed 's/^ *//g'` TOTALSIZE=`du -sh /opt/CPsuite-R65/fw1/conf/db_versions/repository/ | awk ' { print $1 } '` ### FUNCTIONS ### list() { awk ' BEGIN { print " ----------------------------------\n | ID Date |\n ----------------------------------" } /ver_id|date/{arr[i++]=gensub(/^[^(]*\(|\)|"/,"","g")} arr[1]{print " | " arr[1]" | " arr[0]" | " ;i=0;delete arr} END { print " ----------------------------------"} ' "${VERDB}" } delete() { if [ "${DELNUM}" -gt "${TOTALDB}" ] ; then echo Error : Unable to remove "${DELNUM}" DB Revision\(s\) as there are only "${TOTALDB}" DB Revision\(s\) remaining. exit 1 fi TOTALDBARRAY=$((${TOTALDB} - ${DELNUM})) VersionArray=($TOTALDBLIST) echo -n Are you sure you want to remove "${DELNUM}" from the current "${TOTALDB}" DB Revision\(s\) ? \[Y\/N\] ; read input case $input in y ) ;; Y ) ;; n ) exit 0 ;; N ) exit 0 ;; * ) exit 0 esac dbver -m delete `for ((j=0; j < ${#VersionArray[@]} - ${TOTALDBARRAY} ; j++)) ; do echo -n ${VersionArray[j]}, ; done` > /dev/null if [ $? == 0 ] ; then echo Successfully removed "${DELNUM}" DB Revision\(s\). else echo Error : Return Code $?. fi echo } delete_before() { TOTALBEFORE=`list | awk ' NR>3 { print $2 } ' | grep -B10000 ${DELBEFORE} | wc -l | sed 's/^ *//g'` if [ "${TOTALBEFORE}" -eq "0" ] ; then echo Error : Incorrect Database Revision ID supplied. exit 1 fi TOTALDBARRAY=$((${TOTALDB} - ${TOTALBEFORE})) VersionArray=($TOTALDBLIST) echo -n Are you sure you want to remove the Database Revision "${DELBEFORE}" and all Revisions before? \[Y\/N\] ; read input case $input in y ) ;; Y ) ;; n ) exit 0 ;; N ) exit 0 ;; * ) exit 0 esac dbver -m delete `for ((j=0; j < ${#VersionArray[@]} - ${TOTALDBARRAY} ; j++)) ; do echo -n ${VersionArray[j]}, ; done` > /dev/null if [ $? == 0 ] ; then echo Successfully removed "${TOTALBEFORE}" DB Revision\(s\). else echo Error : Return Code $? fi echo } usage() { cat << EOF usage: dbdel [-d number | -b id_number | -s | -c | -l ] List, count and remove multiple database revisions -d number of db revisions to remove -b remove this db revision id and all before -s size of all DB Revisions -c count DB Revisions -l list DB Revisions -? usage EOF } ### MAIN ### while getopts "d:b:slc?" OPTION do case $OPTION in d) DELNUM=$OPTARG delete exit ;; b) DELBEFORE=$OPTARG delete_before exit ;; s) echo Total size of all DB Revisions = "${TOTALSIZE}" echo exit ;; l) list exit ;; c) echo Total number of Database Revisions = "${TOTALDB}" echo exit ;; ?) usage exit ;; esac done usage exit 0
You can copy and paste the script into your manager.
Adding the script to your manager
Below shows you the steps required to add the tool to your Check Point manager.
[[email protected]]#cat > dbdel <-- paste script --> [[email protected]]#chmod +x dbdel [[email protected]]#mv dbdel $FWDIR/bin
Options
Below shows you the switches the tool allows you to use.
[[email protected]]# dbdel ? usage: dbdel [-d number | -b id_number | -s | -c | -l ] List, count and remove multiple database revisions
-d number of db revisions to remove
-b remove this db revision id and all before
-s size of all DB Revisions
-c count DB Revisions
-l list DB Revisions
-? usage
Count
[[email protected]]# dbdel -c Total number of Database Revisions = 13
Remove DB Revisions
[[email protected]]# dbdel -d 632 Are you sure you want to remove 632 from the current 732 DB Revision(s) ? [Y/N]y Successfully removed 632 DB Revision(s)
Remove DB Revisions before
[[email protected]]# dbdel -b 122 Are you sure you want to remove the Database Revision 122 and all Revisions before? [Y/N] Successfully removed 122 DB Revision(s)
Show the Size
[[email protected]]# dbdel -s Total size of all DB Revisions = 4.2M
List Revisions
[[email protected]]# dbdel -l ---------------------------------- | ID Date | ---------------------------------- | 61 | Fri Oct 2 11:05:21 2009 | | 62 | Tue Nov 17 11:04:23 2009 | ----------------------------------
- How to Configure a BIND Server on Ubuntu - March 15, 2018
- What is a BGP Confederation? - March 6, 2018
- Cisco – What is BGP ORF (Outbound Route Filtering)? - March 5, 2018
Want to become an IT Security expert?
Here is our hand-picked selection of the best courses you can find online:
Internet Security Deep Dive course
Complete Cyber Security Course – Hackers Exposed
CompTIA Security+ (SY0-601) Certification Complete course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial