Skip to content

Commit

Permalink
Docker optional backup and restore with documentation (#1692)
Browse files Browse the repository at this point in the history
* Make backups optional with env ENABLE vars.
Use a dedicated backup directory instead of priv.

* Docker optional backup and restore documentation
  • Loading branch information
TrevorBenson authored Oct 22, 2023
1 parent 8402049 commit 7a11683
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
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

0 comments on commit 7a11683

Please sign in to comment.