1@echo off
2rem --------------------------------------------------------------
3rem -- DNS cache save/load script
4rem --
5rem -- Version 1.2
6rem -- By Yuri Voinov (c) 2014
7rem --------------------------------------------------------------
8
9rem Variables
10set prefix="C:\Program Files (x86)"
11set program_path=%prefix%\Unbound
12set uc=%program_path%\unbound-control.exe
13set fname="unbound_cache.dmp"
14
15rem Check Unbound installed
16if exist %uc% goto start
17echo Unbound control not found. Exiting...
18exit 1
19
20:start
21
22rem arg1 - command (optional)
23rem arg2 - file name (optional)
24set arg1=%1
25set arg2=%2
26
27if /I "%arg1%" == "-h" goto help
28
29if "%arg1%" == "" (
30echo Loading cache from %program_path%\%fname%
31dir /a %program_path%\%fname%
32type %program_path%\%fname%|%uc% load_cache
33goto end
34)
35
36if defined %arg2% (goto Not_Defined) else (goto Defined)
37
38rem If file not specified; use default dump file
39:Not_defined
40if /I "%arg1%" == "-s" (
41echo Saving cache to %program_path%\%fname%
42%uc% dump_cache>%program_path%\%fname%
43dir /a %program_path%\%fname%
44echo ok
45goto end
46)
47
48if /I "%arg1%" == "-l" (
49echo Loading cache from %program_path%\%fname%
50dir /a %program_path%\%fname%
51type %program_path%\%fname%|%uc% load_cache
52goto end
53)
54
55if /I "%arg1%" == "-r" (
56echo Saving cache to %program_path%\%fname%
57dir /a %program_path%\%fname%
58%uc% dump_cache>%program_path%\%fname%
59echo ok
60echo Loading cache from %program_path%\%fname%
61type %program_path%\%fname%|%uc% load_cache
62goto end
63)
64
65rem If file name specified; use this filename
66:Defined
67if /I "%arg1%" == "-s" (
68echo Saving cache to %arg2%
69%uc% dump_cache>%arg2%
70dir /a %arg2%
71echo ok
72goto end
73)
74
75if /I "%arg1%" == "-l" (
76echo Loading cache from %arg2%
77dir /a %arg2%
78type %arg2%|%uc% load_cache
79goto end
80)
81
82if /I "%arg1%" == "-r" (
83echo Saving cache to %arg2%
84dir /a %arg2%
85%uc% dump_cache>%arg2%
86echo ok
87echo Loading cache from %arg2%
88type %arg2%|%uc% load_cache
89goto end
90)
91
92:help
93echo Usage: unbound_cache.cmd [-s] or [-l] or [-r] or [-h] [filename]
94echo.
95echo l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value.
96echo s - Save - save Unbound DNS cache contents to plain file with domain names.
97echo r - Reload - reloadind new cache entries and refresh existing cache
98echo h - this screen.
99echo filename - file to save/load dumped cache. If not specified, %program_path%\%fname% will be used instead.
100echo Note: Run without any arguments will be in default mode.
101echo       Also, unbound-control must be configured.
102exit 1
103
104:end
105exit 0
106