# Snapshot & State sync

## Snapshot

```bash
sudo systemctl stop artelad

cp $HOME/.artelad/data/priv_validator_state.json $HOME/.artelad/priv_validator_state.json.backup
artelad tendermint unsafe-reset-all --home ~/.artelad/ --keep-addr-book

curl https://snapshot1.syanodes.my.id/artela/snapshot1-artela.tar.lz4 | lz4 -dc - | tar -xf - -C $HOME/.artelad

mv $HOME/.artelad/priv_validator_state.json.backup $HOME/.artelad/data/priv_validator_state.json

sudo systemctl restart artelad && sudo journalctl -fu artelad -o cat
```

## State Sync

```bash
sudo systemctl stop artelad

cp $HOME/.artelad/data/priv_validator_state.json $HOME/.artelad/priv_validator_state.json.backup
artelad tendermint unsafe-reset-all --home $HOME/.artelad

peers="a996136dcb9f63c7ddef626c70ef488cc9e263b8@144.217.68.182:22256,978dee673bd447147f61aa5a1bdaabdfb8f8b853@47.88.57.107:26656,aa416d3628dcce6e87d4b92d1867c8eca36a70a7@47.254.93.86:26656,30fb0055aced21472a01911353101bc4cd356bb3@47.89.230.117:26656,32d0e4aec8d8a8e33273337e1821f2fe2309539a@47.88.58.36:26656,9e2fbfc4b32a1b013e53f3fc9b45638f4cddee36@47.254.66.177:26656,a03ae11a093c67e2554b73d174c4168fe715af10@57.128.103.184:26656,b23bc610c374fd071c20ce4a2349bf91b8fbd7db@65.108.72.233:11656,04fe1c36f8481649101bff41485e66287e40b136@170.64.140.116:26656,0188a9bcff4f411b29dbddda527d77803396e1c6@185.245.182.180:26656,bec6934fcddbac139bdecce19f81510cb5e02949@47.254.24.106:26656,146d6011cce0423f564c9277c6a3390657c53730@157.90.226.23:26656,1b73ac616d74375932fb6847ec67eee4a98174e9@116.202.85.52:25556,35ce36af33e289a29787eedb3127d21bf10edcff@81.0.218.194:45656,de5612c035bd1875f0bd36d7cbf5d660b0d1e943@5.78.64.11:26656"
SNAP_RPC="https://artela-t-rpc.syanodes.my.id:443"

sed -i.bak -e "s/^persistent_peers *=.*/persistent_peers = \"$peers\"/" $HOME/.artelad/config/config.toml 

LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height);
BLOCK_HEIGHT=$((LATEST_HEIGHT - 1000));
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash) 

echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH && sleep 2

sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ;
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ;
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ;
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"| ;
s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"\"|" $HOME/.artelad/config/config.toml

mv $HOME/.artelad/priv_validator_state.json.backup $HOME/.artelad/data/priv_validator_state.json

sudo systemctl restart artelad && sudo journalctl -u artelad -f --no-hostname -o cat
```
