diff --git a/README.md b/README.md index 8fc5644..6259237 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ services: - BT_CRON="0 0 * * *" # Backup every day at midnight - "BT_DOCKER_URL=unix:///var/run/docker.sock" - BT_THREADS=4 - - BT_BACKUP_DIR=/backups - BT_LOG_LEVEL=info # Enable if using SSL over tcp #- BT_SSL = true @@ -33,7 +32,6 @@ services: | -------- | ----------- | ------- | | BT_CRON | Cron expression for scheduling backups | 0 0 * * * | | BT_THREADS | Number of threads to use for backups | 4 | -| BT_BACKUP_DIR | Directory to store backups | /backups | | BT_LOG_LEVEL | Log level (debug, info, warn, error) | info | | BT_SSL | Enable SSL for docker connection | false | | BT_CA | Path to CA certificate | none | @@ -77,9 +75,9 @@ services: ## Backup Files The backup files will be stored in the directory specified by the `BT_BACKUP_DIR` environment variable. The files will be named according to the following format: ``` -/backups//_.sql +/backups//-.sql ``` -Where `` is the date of the backup ('YY-MM-DD' format) `` is the name of the database, `` is the unix timestamp of the backup. +Where `` is the date of the backup ('YY-MM-DD' format) `` is the name provided by baktainer.name, or the name of the database, `` is the unix timestamp of the backup. ## Roadmap - [x] Add support for SQLite backups diff --git a/app/lib/baktainer.rb b/app/lib/baktainer.rb index 65d7e98..fde151c 100644 --- a/app/lib/baktainer.rb +++ b/app/lib/baktainer.rb @@ -42,7 +42,6 @@ STDOUT.sync = true class Baktainer::Runner - SUPPORTED_ENGINES = %w[postgres postgres-all sqlite mongodb mysql mariadb].freeze def initialize(url: 'unix:///var/run/docker.sock', ssl: false, ssl_options: {}, threads: 5) @pool = Concurrent::FixedThreadPool.new(threads) @url = url @@ -50,14 +49,14 @@ class Baktainer::Runner @ssl_options = ssl_options Docker.url = @url setup_ssl - LOGGER.level = ENV['LOG_LEVEL'].to_sym|| :info + LOGGER.level = ENV['LOG_LEVEL']&.to_sym || :info end def perform_backup LOGGER.info('Starting backup process.') LOGGER.debug('Docker Searching for containers.') - Containers.find_all.each do |container| - # @pool.post do + Baktainer::Containers.find_all.each do |container| + @pool.post do begin LOGGER.info("Backing up container #{container.name} with engine #{container.engine}.") container.backup @@ -66,7 +65,7 @@ class Baktainer::Runner LOGGER.error("Error backing up container #{container.name}: #{e.message}") LOGGER.debug(e.backtrace.join("\n")) end - # end + end end end diff --git a/app/lib/baktainer/container.rb b/app/lib/baktainer/container.rb index 23843ad..eb55d84 100644 --- a/app/lib/baktainer/container.rb +++ b/app/lib/baktainer/container.rb @@ -23,7 +23,7 @@ class Baktainer::Container end def name - labels["baktainer.name"] || @container.info['Names'].first + labels["baktainer.name"] || database end def state @@ -50,6 +50,7 @@ class Baktainer::Container labels['baktainer.db.name'] || nil end + def validdate return raise 'Unable to parse container' if @container.nil? return raise 'Container not running' if state.nil? || state != 'running' @@ -96,7 +97,7 @@ class Baktainer::Container end # :NODOC: -class Containers +class Baktainer::Containers def self.find_all LOGGER.debug('Searching for containers with backup labels.') containers = Docker::Container.all.select do |container| diff --git a/docker-compose.yml b/docker-compose.yml index 4b773a7..6638ea1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,6 @@ services: image: jamez01/baktainer:latest container_name: baktainer restart: unless-stopped - ports: - - "8080:8080" volumes: - ./backups:/backups - ./config:/config