The method to extract the code eth.getcode takes an optional block height parameter as documented here. The function signature is:
web3.eth.getCode(addressHexString [, defaultBlock] [, callback]),
defaultBlock (Maybe "block" would have been a better name?) can be any block number or some special valued strings such as
"pending". You can see the documentation here.
This means that you will be able to extract the code of the contract N blocks back. But you should note that you need to run a blockchain node which stores and indexes all historic information in order for you to be allowed to make the call at an arbitrary block height. In Parity wallet, this setting is referred to as
--pruning archive, cf. https://wiki.parity.io/Getting-Synced#database-pruning.
You should also note that this function call will return the binary code of the contract, not the source code. If you receive the source code through some other souce, you can however, verify that the binary code returned by
getcode matches the source code by compiling the source code with the option
--bin-runtime as described in this answer:
Nothing that takes place on the blockchain is ever deleted :)