Please describe the feature you’d like to see added.
It will be good to have a option included in bitcoind to backup and restore the current state of the datadir periodically.
Is your feature related to a problem, if so please describe it.
Not a software problem, but its the environment. Many events can corrupt data inside datadir, to name some: power outages, out of resources (RAM), network fail (in case of network storage). Once corrupted, it’s costly to re-sync it again from scratch. So instead of syncing, it can just restore the backed datadir to some point in time.
Describe the solution you’d like
Add a folder called backup to datadir, it can have 4 files: the last two backups named with timestamp and compressed as tar.gz (or other better format) and one text file for each backup with info to restore them.
Add options to bitcoind:
-restorebackup=<0|1>
-backup=<n>
where n can be
- 0, to disable
- 1 to backup only once after node are synced, and do not update this backup in case of it already present in backup folder
- greater than 1 indicating the period in days since last backup to do it again. It will keep always two backups to address the case in which a failure occurs during the backup process.
Describe any alternatives you’ve considered
The backed data to reconstruct any state in time are (i think):
- chainstate folder;
- Last blocks/*.blk and .rev files that are not completely full;
- blocks/index folder
- Any other file that are used with specific configuration, like bloom filters (or in the case of restoring the backup, just reconstruct them to avoid conflicts)
Actually i do it manually, i keep an HDD with datadir up to May/2024, and when restoring, just copy chainstate, last blk/rev files of backup, excluding the others not present in backup, blocks/index Since my node uses HDD and have 2GB RAM, it takes one month to sync from scratch. So i restored this backup sometimes and saved a lot of time.
The creation of this backup also can be automated using scripts in bash, python, etc. The script need to stop bitcoind, write chainstate, blocks/index and some last .blk and .rev files. The restoration can be done manually, jsut replace chainstate, blocks/index and exclude .blk/.rev files down to current in the backup.
Please leave any additional context
No response