3 # --------------------------------------------------------------
4 # -- DNS cache save/load script
7 # -- By Yuri Voinov (c) 2006, 2014
8 # --------------------------------------------------------------
10 # ident "@(#)unbound_cache.sh 1.2 14/10/30 YV"
17 # Installation base dir
18 CONF="/etc/opt/csw/unbound"
22 UC="$BASE/sbin/unbound-control"
23 FNAME="unbound_cache.dmp"
26 BASENAME=`which basename`
42 $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h] [filename]"
44 $ECHO "l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value."
45 $ECHO "s - Save - save Unbound DNS cache contents to plain file with domain names."
46 $ECHO "r - Reload - reloadind new cache entries and refresh existing cache"
47 $ECHO "h - this screen."
48 $ECHO "filename - file to save/load dumped cache. If not specified, $CONF/$FNAME will be used instead."
49 $ECHO "Note: Run without any arguments will be in default mode."
50 $ECHO " Also, unbound-control must be configured."
56 if [ ! `$ID | $CUT -f1 -d" "` = "uid=0(root)" ]; then
57 $ECHO "ERROR: You must be super-user to run this script."
64 if [ ! -f "$UC" ]; then
66 $ECHO "ERROR: $UC not found. Exiting..."
74 if [ ! -z "$filename" -a ! -f "$filename" ]; then
76 $ECHO "ERROR: File $filename does not exists. Save it first."
78 elif [ ! -f "$CONF/$FNAME" ]; then
80 $ECHO "ERROR: File $CONF/$FNAME does not exists. Save it first."
89 if [ -z "$filename" ]; then
90 $ECHO "Saving cache in $CONF/$FNAME..."
91 $UC dump_cache>$CONF/$FNAME
94 $ECHO "Saving cache in $filename..."
95 $UC dump_cache>$filename
103 # Load saved cache contents and warmup cache
105 if [ -z "$filename" ]; then
106 $ECHO "Loading cache from saved $CONF/$FNAME..."
108 check_saved_file $filename
109 $CAT $CONF/$FNAME|$UC load_cache
111 $ECHO "Loading cache from saved $filename..."
113 check_saved_file $filename
114 $CAT $filename|$UC load_cache
120 # Reloading and refresh existing cache and saved dump
133 # Check unbound-control
136 # Check command-line arguments
137 if [ "x$*" = "x" ]; then
138 # If arguments list empty,load cache by default
143 set -- `$GETOPT sSlLrRhH: $arg_list` || {
154 -h | -H | \?) usage_note;;
163 shift `$EXPR $OPTIND - 1`
166 if [ "$save" = "1" ]; then
168 elif [ "$save" = "0" ]; then
170 elif [ "$save" = "2" ]; then