Project now functions.

TODO:
  - Add individual hook for completed backups
  - Add hook for fullly completed backups
  - Optionally limit time for each backup
This commit is contained in:
James Paterni 2025-05-08 22:41:50 -04:00
parent f23e28a157
commit db946bc26e
4 changed files with 9 additions and 13 deletions

View file

@ -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/<date>/<db_name>_<timestamp>.sql
/backups/<date>/<db_name>-<timestamp>.sql
```
Where `<date>` is the date of the backup ('YY-MM-DD' format) `<db_name>` is the name of the database, `<timestamp>` is the unix timestamp of the backup.
Where `<date>` is the date of the backup ('YY-MM-DD' format) `<db_name>` is the name provided by baktainer.name, or the name of the database, `<timestamp>` is the unix timestamp of the backup.
## Roadmap
- [x] Add support for SQLite backups

View file

@ -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

View file

@ -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|

View file

@ -4,8 +4,6 @@ services:
image: jamez01/baktainer:latest
container_name: baktainer
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- ./backups:/backups
- ./config:/config