> For the complete documentation index, see [llms.txt](https://docs.harmony.one/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.harmony.one/home/network/validators/node-setup/5.-advanced-how-to-create-snapdb-on-your-server.md).

# 5. \[Advanced] - how to create snapDB on your server

## SnapDB snapshots be the core team

Please note, you can still find the snapDB from the core team by the [link](https://docs.harmony.one/home/network/validators/node-setup/syncing-db#id-3.-shard-0-validator-snap-db-sync), but if your own you are welcome to proceed.

## Requirements&#x20;

* an **extra** Harmony node
* time -> snapDB creation is taking around 2 days
* extra space:
  * current DB around 200->500 GB
  * snapDB will be around 120+ GB

## Creating a snapDB snapshot

You need to do the following to get the fresh snapDB:

1. Stop currently running harmony service/container/any other way how you run Harmony node, e.g. systemd service:

```bash
sudo systemctl stop harmony.service
# we don't want some server reboot to start normal harmony service
sudo systemctl disable harmony.service
```

2. Place the following bash script \`check-and-run-snapdb.sh\` nearby the binary.

{% hint style="info" %}
Reason : the dumpdb feature may crash, fortunately, at restart of the process the dump **will** **start** **where it left off**
{% endhint %}

{% hint style="warning" %}
Note: `KakashiDB batch writhing` and `account` lines will produce you 90GB of logs without providing you any extra information => so let's just ignore these lines.
{% endhint %}

```bash
#!/bin/bash
​
# make sure the folder where the new snapDB is is created
mkdir -p /data/snapdb/new_snapdb_creation
​
# Specify the name of the program you want to monitor
program_name="harmony"
​binary_path="/put_yours_here"
db_path="/put_yours_here" # by default it is the same folder as for binary
snapdb_path="/put_yours_here"

# Use pgrep to get the number of PIDs for the specified program
pid_count=$(pgrep -cx "$program_name")
​
if [ "$pid_count" -eq 1 ]; then
    echo "$program_name is running all good"
else
    "$binary_path"/harmony dumpdb \
    "$db_path" "$snapdb_path" | \
     grep -v "KakashiDB batch writhing\|account" >> "$binary_path"/newsnapdb.log &
fi
```

3. Put the check-and-run-snapdb.sh in the cron to rerun every 5 minutes via `crontab -e`

{% hint style="danger" %}
Note: by default SHELL in crontab is set to /bin/sh and all relative path like `~/` wouldn't work here, **use full path**
{% endhint %}

```bash
*/5 * * * * bash /data/snapdb/check-and-run-snapdb.sh
```

4. Time to time check the logs:

```bash
less +F +G /your_path_for_logs/newsnapdb.log
```

5. What will you see in the logs when snapdb creation have been finished:

{% hint style="info" %}
Note, this process will take around 2 days
{% endhint %}

```
===dumpMain===
head-block: 48393536 0x03cd3c3093f4299a4d70721c2d70192080e82a42401b72a1cdc425751ce8ac12
start copying...
Dump completed!
KakashiDB Close
```

6. Comment the crontab entry from the 3rd step via `crontab -e`

```bash
#*/5 * * * * bash /data/snapdb/check-and-run-snapdb.sh
```

7. Move your old DB and name it like backup, and make a :

<pre class="language-bash"><code class="lang-bash">db_path="/put_yours_here"
snapdb_path="/put_yours_here/"
<strong>mv "$db_path" "$db_path"_backup
</strong><strong>mv "$snapdb_path" "$db_path"
</strong></code></pre>

8. Start your harmony process again:

```bash
sudo systemctl start harmony.service
sudo systemctl enable harmony.service
```

9. Wait till the node is synced with the latest HEAD block, it will take some small amount of time around 5-15 minutes - node needs to fetch 2+ day blocks.
10. If everything good - remove old DB from the server, check the step 7:

{% hint style="danger" %}
Note: running `rm -rf` is dangerous, please double check what are you about to delete!&#x20;
{% endhint %}

```bash
rm -rf /your_path_to_DB_backup/
```
