Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker optional backup and restore with documentation #1692

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/docker/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,26 @@ cardanocommunity/cardano-node:latest # Mandatory: image to run

#### Un-Official Docker managment cli tool
- [Lazydocker](https://github.com/jesseduffield/lazydocker)

### Docker backups and restores

The docker container has an optional backup and restore functionality that can be used to backup the `/opt/cardano/cnode/db` directory. To have the
backup persist longer than the countainer, the backup directory should be mounted as a volume.

[!NOTE]
The backup and restore functionality is disabled by default.

[!WARNING]
Make sure adequate space exists on the host as the backup will double the space consumed by the database.

#### Creating a Backup

When the container is started with the **ENABLE_BACKUP** environment variable set to **Y** the container will automatically create a
backup in the `/opt/cardano/cnode/backup/$NETWORK-db` directory. The backup will be created when the container is started and if the
backup directory is smaller than the db directory.

#### Restoring from a Backup

When the container is started with the **ENABLE_RESTORE** environment variable set to **Y** the container will automatically restore
the latest backup from the `/opt/cardano/cnode/backup/$NETWORK-db` directory. The database will be restored when the container is started
and if the backup directory is larger than the db directory.
22 changes: 14 additions & 8 deletions files/docker/node/addons/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ echo "NETWORK: $NETWORK $POOL_NAME $TOPOLOGY";
echo "NODE: $HOSTNAME - Port:$CNODE_PORT - $POOL_NAME";
cardano-node --version;

dbsize=$(du -s ${CNODE_HOME}/db | awk '{print $1}')
bksizedb=$(du -s $CNODE_HOME/priv/$NETWORK-db 2>/dev/null | awk '{print $1}')
if [[ "${ENABLE_BACKUP}" == "Y" ]] || [[ "${ENABLE_RESTORE}" == "Y" ]]; then
[[ ! -d "${CNODE_HOME}"/backup/$NETWORK-db ]] && mkdir -p $CNODE_HOME/backup/$NETWORK-db
dbsize=$(du -s $CNODE_HOME/db | awk '{print $1}')
bksizedb=$(du -s $CNODE_HOME/backup/$NETWORK-db 2>/dev/null | awk '{print $1}')
if [[ "${ENABLE_RESTORE}" == "Y" ]] && [[ "$dbsize" -lt "$bksizedb" ]]; then
echo "Backup Started"
cp -rf "${CNODE_HOME}"/backup/"${NETWORK}"-db/* "${CNODE_HOME}"/db 2>/dev/null
echo "Backup Finished"
fi

if [[ "$dbsize" -lt "$bksizedb" ]]; then
cp -rf $CNODE_HOME/priv/$NETWORK-db/* ${CNODE_HOME}/db 2>/dev/null
fi

if [[ "$dbsize" -gt "$bksizedb" ]]; then
cp -rf $CNODE_HOME/db/* $CNODE_HOME/priv/$NETWORK-db/ 2>/dev/null
if [[ "${ENABLE_BACKUP}" == "Y" ]] && [[ "$dbsize" -gt "$bksizedb" ]]; then
echo "Restore Started"
cp -rf "${CNODE_HOME}"/db/* "${CNODE_HOME}"/backup/"${NETWORK}"-db/ 2>/dev/null
echo "Restore Finished"
fi
fi

# Customisation
Expand Down