TLDR; Produce a pruned block directory from a full block directory without copying any extra block data
I have a full node, but at times I want to run in a VM or on a RPi or something. Normally I have to clone my whole 300 GB block directory, enable pruning, then point
bitcoin-qt.exe to the clone to finally arrive at a small 4 GB
datadir. I found it frustrating that I was doing this 295 GB of pointless copy operations since once I enable pruning, the old blocks are discarded. I was also discouraged at the fact that
.\Bitcoin\testnet3\blocks\blk00186.dat is different (by checksum) in a pruned and non-pruned directory.
So I finally came up with an answer. Basically, I copy over the latest few
rev*.dat files, then just make empty copies of the other
rev*.dat files. Then once
bitcoin-qt.exe launches, it discards the empty files and rewrites the few files it needs. For Windows, it looks something like this:
set /a "sum=0" for /f %%I in ('dir /s /b /o:-n %full_blk%\blk*.dat') do ( set size=%%~zI set blkdat=%%~nxI set revdat=!blkdat:blk=rev! if !sum! GTR !pruned_mb! ( echo.> %pruned_blk%\!blkdat! echo.> %pruned_blk%\!revdat! ) else ( copy %full_blk%\!blkdat! %pruned_blk%\!blkdat! copy %full_blk%\!revdat! %pruned_blk%\!revdat! ) set /a "sum=!sum! -1 + !size!/(1024*1024)" )
I can stamp out a pruned blocks directory from my full blocks directory in seconds. Much easier... well for me.
Here's the source, but no guarantees. Just food for thought.
Update: I had originally thought to
symlink the unused files, but turns out they are never read at all, so I can just dummy them out.