Find yourself with a corrupt postfix virtual file? Have a working, good virtual.db? Follow these instructions to save the day…
Start by dumping the current known good virtual.db file:
[/path/to/postfix] % db_dump -p virtual.db > outfile
edit the resultant outfile
, deleting this part (top of the file):
VERSION=3<br />
format=print<br />
type=hash<br />
h_nelem=1015<br />
db_pagesize=16384<br />
HEADER=END
and this part (bottom of the file):
DATA=END
Then massage your data. I did it in Microsoft Word (I know, I know, but it’s really easy in Word…) by doing the following:
- open outfile in Word.
- find and replace all ‘space’ characters with nothing(delete the spaces in the text)
- find and replace all occurences of ‘0’ with nothing (delete the 0 from each line end)
- select all, Table–>Convert–>Convert Text to Table…
- change to 2 columns
- Table–>Convert–>Convert Table to Text…, separate text with tabs
- save file
move outfile back to your server, rename it, and hash the new file.
[/path/to/postfix] % mv outfile virtual<br />
[/path/to/postfix] % postmap hash:virtual
If you want to double-check yourself before doing the postmap
that actually re-writes your known good virtual.db, do this:
[/path/to/postfix] % db_dump -p virtual.db > knowngood
(same as we did in the beginning, dump the known good db file)[/path/to/postfix] % cp virtual newvirtual
(copy the virtual you just recreated, so you can hash it and not overwrite your original)[/path/to/postfix] % postmap hash:newvirtual
(create the new berkeley db hash file)[/path/to/postfix] % db_dump -p newvirtual.db > newoutfile
(dump the new db file)[/path/to/postfix] % diff knowngood newoutfile
(run diff against the old db_dump output vs. the new db_dump output)
If everything is copasetic, diff won’t return anything, as the newvirtual.db should match the known good virtual.db!
Wow, that was pretty easy. Of course, you can use whatever text editing program you’d like…
Hope this helps someone out…