Categorygithub.com/bata94/DockerRight
module
0.0.0-20240611145844-0d88966f730a
Repository: https://github.com/bata94/dockerright.git
Documentation: pkg.go.dev

# README

DockerRight

Go Report Card

Description

A simple Docker Container that allows you to monitor your other Docker Containers and backup your Docker Volumes, with notifictaions.

It creates a tarball (.tar) per configured volume, at the configured time, and stores it in the configured location :) In the best case the Output directory is mapped to a Network Drive or another Host.

To see whats working now and whats planned in the near future see TODOs.

Tested and developed for Linux. Windows, WSL, MacOS might be working, but not tested/designed for!

Limitations/Warnings

Not recommended to use DockerRight as a solo backup solution for DBs or complex applications! But it's still better than no backup at all :D

It is a very young and developing Project, so use at your own risk!

How to use

Minimal Docker run CMD:

docker run -d 
    -v /var/run/docker.sock:/var/run/docker.sock
    -v /path/to/config:/opt/DockerRight/config
    -v /path/to/backupDir:/opt/DockerRight/backup
    # Optional: -v /path/to/logsDir:/opt/DockerRight/logs
    -e TZ=Europe/Berlin
    --name dockerright 
    ghcr.io/bata94/dockerright:latest

Minimal Docker-Compose File:

services:
  dockerright:
    container_name: dockerright
    image: ghcr.io/bata94/dockerright:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /path/to/config:/opt/DockerRight/config
      - /path/to/backupDir:/opt/DockerRight/backup
      # Optional: - /path/to/logsDir:/opt/DockerRight/logs
    environment:
      TZ: Europe/Berlin

To run the service successfully the containername needs to be "dockerright"! Start the Container, it will stop after a few seconds on it's own.

Now you edit the created config.json.

A restart option might be a good idea, for such a service, but it's easier to set it after the first run, to only generate the config.json.

If you don't set Before- or AfterBackupCMDs that would need network access, you should set the Docker Network to "none".

If you don't want to use the ContainerRegistry, just git clone this repository and build your image. The Dockerfile and an example Composefile are already there.

Available VersionTags

TagDescription
latestThe latest version
XThe latest Major version
0.XThe latest Minor version
0.0.XSpecific patch (see releases for versions)

DockerRight uses Semantic Versioning, so you can lock the Image Version to a specific tag, as shown above.

When all ToDos are completed I will move to Major 1 :)
Most ToDos should increase the Minor by 1.

The Patchnotes can be found here

Configuration

Parameters that can be set in the config.json. To reset them, delete the config.json and restart the container.

The Parameters in the config.json are typed in UpperCamelCase. To use those Parameters in environment variables, the must be typed as UPPER_SNAKE_CASE.

Parameters are evaluated as follows:

1. EnvironmentVariables
2. config.json
3. default values

If you change a Parameter you will need to restart the DockerRightContainer to apply the change.

Parameter (config.json)Parameter (EnvVar)DefaultTypeDescription
EnableBackupENABLE_BACKUPfalseBoolEnable backup service
EnableMonitorENABLE_MONITORfalseBoolEnable monitor service
MonitorIntervalSecondsMONITOR_INTERVAL_SECONDS60IntInterval in seconds
MonitorRetiesMONITOR_RETIES5IntRetries before sending notification
BackupHoursBACKUP_HOURS[][]IntBackup at these hours
RetentionHoursRETENTION_HOURS120IntBackup Retention in hours (24h * 5d)
LogRetentionDaysLOG_RETENTION_DAYS7IntLog Retention in days
ConcurrentBackupContainerCONCURRENT_BACKUP_CONTAINERnumCPUs/2IntHow many mounts should be backed up at once
BackupPathBACKUP_PATH"/opt/DockerRight/backup"StringBackup Path inside container (shouldn't be changed)
LogsPathLOGS_PATH"/opt/DockerRight/logs"StringLogs Path inside container (shouldn't be changed)
BeforeBackupCMDBEFORE_BACKUP_CMD""StringCMD to execute before backup
AfterBackupCMDAFTER_BACKUP_CMD""StringCMD to execute after backup
Log2FileLOG2FILEfalseBoolToggle Log to File
LogLevelLOG_LEVEL"info"StringSet LogLevel (debug, info, warn, error, fatal, panic)
NotifyLevelNOTIFY_LEVEL"error"StringSet NotificationLevel (debug, info, warn, error, fatal, panic)
BackupOnStartupBACKUP_ON_STARTUPfalseBoolStart a Backup on startup, won't run again if started in a BackupHour
CreateTestContainerOnStartupCREATE_TEST_CONTAINER_ON_STARTUPtrueBoolCreate a TestContainer on startup, to check docker.sock
NotifyLevelNOTIFY_LEVEL"warn"StringSet NotificationLevel (debug, info, warn, error, fatal, panic, none)
TelegramBotTokenTELEGRAM_BOT_TOKEN""StringTelegram Bot Token TelegramConf
TelegramChatIDsTELEGRAM_CHAT_IDS[][]IntTelegram Chat IDs TelegramConf

Notifications

If you want to get Notifications you will need to set the desired NotifyLevel, so all Logs in that Level (and above) will be send to the configured NotifyClients (i.e Telegram).

Container Monitoring will always be sent to all available clients.

NotifyTelegram

To enable Telegram notifications you will need to setup a BotToken and at least one ChatID.

To get a BotToken got to BotFather, create a new Bot and start it. It is necessary to create a new Bot for every DockerRightInstance!

The ChatID is more or less your ID, to get it you have two options:

1. DockerRight is not running -> send a message to your created Bot and than visit >>https://api.telegram.org/bot<HIER_DEIN_BOT_TOKEN>/getUpdates<<
2. DockerRight is running -> send a message to your created Bot and than watch the DockerRight logs. Under the WARN Flag there should pop up a LogMessage with your ID

TODOs

What's planned in the near future? If you have any ideas, feature requests, suggestions or bug reports, please open an issue or create a PR :)

Those points are roughly in order of importance (for me):

  • Create Backups per mount
  • Delete old Backups
  • Make config parameters settable by environment variables
  • Add VersionTag to startup console output
  • Better DockerBackupHelperNames, that reflect ContainerName and Mount
  • Enable concurrent backups
  • BackupContainer Output to File
  • Backup Docker Compose Files/Run Parameters
  • Logs to File
  • Monitor Docker Containers
  • Telegram Notifications
  • Fix Monitor only Loop
  • Mount Container Volumes/Binds as read only, for safety
  • Change from time.sleep() to time.Ticker() or Crons
  • Find reason for high CPU usage on low end CPUs (Zimaboard 40% in "idle"...) might be time.sleep
  • Add Parameter to enable/disable log to File
  • Deleting EnvVars do not overwrite config.json... (not sure how to fix/handle it right now...)
  • config.json FilePermissions
  • Add FormatWrapper for Notify Package (add LogLevel to Msg as well)
  • Refactor!!!
  • Mail Notifications
  • Discord Notifications
  • Fine grain settings via Container Labels (like traefik for example)
  • Restore Backups
  • Image specific backup CMDs (i.e. for DBs, Nextcloud, Zammad, Mailcow etc.)
  • SSH, SFTP, S3, NFS, SMB Backup location options
  • Either configure Watchtower Container from DockerRight or program Watchtower functionality into DockerRight
  • Refactor!!!
  • WebUI for Configuration, Monitoring and Dashboard
  • Add tests :D

Patchnotes

If a specific Version is not listed here, eventhough it was released, it might only be a refactor or super minor change, without changes for the user. As the development is rapid I might skip the patchnotes for a version!

0.2.1

  • Telegram Notifications implemented
  • DockerContainer Monitor implemented
  • Added Parameter to toggle File logging
  • Moved away from time.Sleep() -> performance
  • Refactored BackupLoop -> performance

0.1.1

  • Parameter now settable via Environment Variables
  • Improved Struct logging (if "\n" are display instead of linebreaks, pls check your Docker LogDriver!)
  • Disabled BackupRunner to run twice in one hour, if DockerRight is started in a defined BackupHour
  • Changed BackupRunner ContainerNaming to better show what is running
  • DockerRight will now print the current VersionTag to the startup console
  • Added cuncurrent running of BackupRunners
  • ContainerInfo is now in a file, inside the backup directory
  • After-/BeforeBackupCMD Output as well as regular Logs are now written to /opt/DockerRight/logs/ (default value) directory
  • BackupErrors will be found in the BackupDir as well

0.0.11

  • Better logging
  • Fixed a bug where the backup is blocked if only one backup time is defined

0.0.6

  • Some refactoring and optimization
  • Bugfixes, specially with finding the BackupPath of the DockerRightContainer on Host
  • Build pipeline changes and CD testing

0.0.4

  • Deletes old backups now

0.0.1

  • Initial Release

License

This project is licensed under the Unlicense, so do what you want, but don't blame me :D

# Packages

No description provided by the author