top of page

Backing up the Chia Blockchain: A Step-by-Step Guide

Updated: Sep 6, 2023

If you're involved in cryptocurrency mining, chances are you're familiar with Chia (XCH). Chia operates on a proof-of-space blockchain, relying on hard drives for its functionality. However, the process of synchronizing the Chia blockchain can be quite time-consuming. I recall that when I initially installed the Chia blockchain, it took a little over a week to sync the 3.5 million transactions, and this number continues to grow daily. Presently, the Chia blockchain has expanded to accommodate 4,184,792 transactions, implying that synchronization would require even more time. To preemptively address this issue, I had two options: I could either resort to downloading the synced blockchain from a dubious mega link hosted by an anonymous internet user or opt for the safer route of backing up the Chia database. Today seemed like an opportune moment to create an additional backup, just in case my primary C drive encounters any unforeseen issues. In this article, we will explore a straightforward method for backing up the Chia database.


Backing up the DB Folder:

  • Close out of the Chia Application (This is needed because the app runs SQL. SQL will more than likely corrupt if copied while its still writing/syncing transactions)

  • Navigate to: C:\Users\"Your Username"

  • Here you will see a .chia folder

  • This folder will contain all data from the mainnet, including plotters, your wallet, the database, your config and cache.

  • Click on this folder and select Copy

  • Paste it onto the drive you want to use as a backup

  • After the folder is copied, you can open the Chia app and continue farming!

Backing Up using SQL Lite:

In a post on Reddit, user DrakeFS enlightened me about the possibility of performing a database backup using SQL Lite. This approach offers several benefits, such as reducing the occurrence of data corruption during backup processes and allowing backups to be executed even while the Chia client continues to run.


Download SQLite tools

To download SQLite, you open the download page of the SQlite official website.


Open the download page https://www.sqlite.org/download.html


SQLite offers a range of cross-platform tools compatible with Windows, Linux, and Mac. To get started, simply choose the appropriate version for your operating system. For instance, if you're using Windows, you can obtain the command-line shell program, as depicted in the screenshot below, to begin working with SQLite. For this tutorial we will be downloading the sqlite-tools-win32.


  1. Extract the folder, you should see sqldiff, sqlite3 and sqlite_analyzer in the folder.

  2. Create a folder on the root C drive called sqlite

  3. Copy the extracted files here


Creating a backup bat script:

Now that the shell version of sqlite is on your computer, we can create a bat script to use this tool for backing up the Chia database. Create a new text document on your desktop and copy the following text:


@echo off


SET SQLITE_EXE=C:\sqlite\sqlite3.exe

SET MAIN_DB=C:\Users\%Username%\.chia\mainnet\wallet\db\blockchain_wallet_v2_r1_mainnet_1036222499.sqlite

SET MAIN_BAK=E:\Backups\blockchain_v1_mainnet.sqlite.bak


SET WALLET_DB=C:\Users\%Username%\.chia\mainnet\wallet\db\blockchain_wallet_v2_r1_mainnet_1036222499.sqlite-wal

SET WALLET_BAK=E:\Backups\blockchain_wallet_v2_r1_mainnet_1036222499.sqlite.bak


echo ========================================

echo Start Chia main database backup

echo %TIME%


if exist %MAIN_BAK% del %MAIN_BAK%

%SQLITE_EXE% %MAIN_DB% "vacuum into '%MAIN_BAK%'"


echo End Chia main database backup

echo %TIME%

echo ========================================


echo Start Chia wallet database backup

echo %TIME%


if exist %WALLET_BAK% del %WALLET_BAK%

%SQLITE_EXE% %WALLET_DB% "vacuum into '%WALLET_BAK%'"


echo End Chia wallet database backup

echo %TIME%

echo ========================================


pause


Locate your Files:

Replace %username% with your user account name that is logged in and running Chia. Alternatively you can navigate to the .Chia folder and copy the file location from here. You will want to copy the file location for the main DB file (over 100GB) and the wallet file which will end with "-wal". Also don't forget to create a folder on your backup drive called "Backup" and set the correct drive letter in the script.








My Backup Script Example:

@echo off


SET SQLITE_EXE=C:\sqlite\sqlite3.exe

SET MAIN_DB=C:\Users\ChaChaChia\.chia\mainnet\db\blockchain_v2_mainnet.sqlite

SET MAIN_BAK=E:\Backups\blockchain_v2_mainnet.sqlite.bak


SET WALLET_DB=C:\Users\ChaChaChia\.chia\mainnet\db\blockchain_v2_mainnet.sqlite-wal

SET WALLET_BAK=E:\Backups\blockchain_v2_mainnet.sqlite.bak


echo ========================================

echo Start Chia main database backup

echo %TIME%


if exist %MAIN_BAK% del %MAIN_BAK%

%SQLITE_EXE% %MAIN_DB% "vacuum into '%MAIN_BAK%'"


echo End Chia main database backup

echo %TIME%

echo ========================================


echo Start Chia wallet database backup

echo %TIME%


if exist %WALLET_BAK% del %WALLET_BAK%

%SQLITE_EXE% %WALLET_DB% "vacuum into '%WALLET_BAK%'"


echo End Chia wallet database backup

echo %TIME%

echo ========================================


pause

Comments


bottom of page