I would like to keep the latest 512 MB of blocks on my SSD (using pruning?) and the rest of the blockchain on an external non-SSD hard-drive. Is there a way to do this already, or do I need to write a script to accomplish this?
Blocks are not accessed under normal operation, except: When a peer fetches one (and the most recent block is usually served out of an in memory cache), when there is a reorginization that must undo the effect of a block (which is pretty rare), or when you use an RPC to look up a historic block.
With that in mind, perhaps you can just put your blocks directory on the other disk.
If you set your node to be pruned but set the pruned amount much larger than the amount of block data, you will avoid peers fetching large numbers of old blocks from you (but still keep the data around).
If you found high disk accesses while in this configuration, I think thats something that the project would like to fix.
You could have two datadirs, one locally and one on the external hard drive where, every so often, you connect the external hard drive and start Bitcoin Core to use that as a datadir and sync it up. The local one could be pruned.
However if you wanted to have most blocks stored on the external hard drive and have Bitcoin Core automatically move them there and then be able to handle when it can't find those blocks, then that is not possible.
If you are already synced, you could call a simple script using
blocknotify=script.sh in your
bitcoin.conf to check for a higher numbered block file, and if one is found, move the lowest one out and the newest one in.
But a better way would probably be doing this at the block level with some fs/raid abstraction, or an inotify watcher if you have to do it at the file level.