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:
parent
f23e28a157
commit
db946bc26e
4 changed files with 9 additions and 13 deletions
|
@ -19,7 +19,6 @@ services:
|
||||||
- BT_CRON="0 0 * * *" # Backup every day at midnight
|
- BT_CRON="0 0 * * *" # Backup every day at midnight
|
||||||
- "BT_DOCKER_URL=unix:///var/run/docker.sock"
|
- "BT_DOCKER_URL=unix:///var/run/docker.sock"
|
||||||
- BT_THREADS=4
|
- BT_THREADS=4
|
||||||
- BT_BACKUP_DIR=/backups
|
|
||||||
- BT_LOG_LEVEL=info
|
- BT_LOG_LEVEL=info
|
||||||
# Enable if using SSL over tcp
|
# Enable if using SSL over tcp
|
||||||
#- BT_SSL = true
|
#- BT_SSL = true
|
||||||
|
@ -33,7 +32,6 @@ services:
|
||||||
| -------- | ----------- | ------- |
|
| -------- | ----------- | ------- |
|
||||||
| BT_CRON | Cron expression for scheduling backups | 0 0 * * * |
|
| BT_CRON | Cron expression for scheduling backups | 0 0 * * * |
|
||||||
| BT_THREADS | Number of threads to use for backups | 4 |
|
| 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_LOG_LEVEL | Log level (debug, info, warn, error) | info |
|
||||||
| BT_SSL | Enable SSL for docker connection | false |
|
| BT_SSL | Enable SSL for docker connection | false |
|
||||||
| BT_CA | Path to CA certificate | none |
|
| BT_CA | Path to CA certificate | none |
|
||||||
|
@ -77,9 +75,9 @@ services:
|
||||||
## Backup Files
|
## 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:
|
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
|
## Roadmap
|
||||||
- [x] Add support for SQLite backups
|
- [x] Add support for SQLite backups
|
||||||
|
|
|
@ -42,7 +42,6 @@ STDOUT.sync = true
|
||||||
|
|
||||||
|
|
||||||
class Baktainer::Runner
|
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)
|
def initialize(url: 'unix:///var/run/docker.sock', ssl: false, ssl_options: {}, threads: 5)
|
||||||
@pool = Concurrent::FixedThreadPool.new(threads)
|
@pool = Concurrent::FixedThreadPool.new(threads)
|
||||||
@url = url
|
@url = url
|
||||||
|
@ -50,14 +49,14 @@ class Baktainer::Runner
|
||||||
@ssl_options = ssl_options
|
@ssl_options = ssl_options
|
||||||
Docker.url = @url
|
Docker.url = @url
|
||||||
setup_ssl
|
setup_ssl
|
||||||
LOGGER.level = ENV['LOG_LEVEL'].to_sym|| :info
|
LOGGER.level = ENV['LOG_LEVEL']&.to_sym || :info
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_backup
|
def perform_backup
|
||||||
LOGGER.info('Starting backup process.')
|
LOGGER.info('Starting backup process.')
|
||||||
LOGGER.debug('Docker Searching for containers.')
|
LOGGER.debug('Docker Searching for containers.')
|
||||||
Containers.find_all.each do |container|
|
Baktainer::Containers.find_all.each do |container|
|
||||||
# @pool.post do
|
@pool.post do
|
||||||
begin
|
begin
|
||||||
LOGGER.info("Backing up container #{container.name} with engine #{container.engine}.")
|
LOGGER.info("Backing up container #{container.name} with engine #{container.engine}.")
|
||||||
container.backup
|
container.backup
|
||||||
|
@ -66,7 +65,7 @@ class Baktainer::Runner
|
||||||
LOGGER.error("Error backing up container #{container.name}: #{e.message}")
|
LOGGER.error("Error backing up container #{container.name}: #{e.message}")
|
||||||
LOGGER.debug(e.backtrace.join("\n"))
|
LOGGER.debug(e.backtrace.join("\n"))
|
||||||
end
|
end
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Baktainer::Container
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
labels["baktainer.name"] || @container.info['Names'].first
|
labels["baktainer.name"] || database
|
||||||
end
|
end
|
||||||
|
|
||||||
def state
|
def state
|
||||||
|
@ -50,6 +50,7 @@ class Baktainer::Container
|
||||||
labels['baktainer.db.name'] || nil
|
labels['baktainer.db.name'] || nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def validdate
|
def validdate
|
||||||
return raise 'Unable to parse container' if @container.nil?
|
return raise 'Unable to parse container' if @container.nil?
|
||||||
return raise 'Container not running' if state.nil? || state != 'running'
|
return raise 'Container not running' if state.nil? || state != 'running'
|
||||||
|
@ -96,7 +97,7 @@ class Baktainer::Container
|
||||||
end
|
end
|
||||||
|
|
||||||
# :NODOC:
|
# :NODOC:
|
||||||
class Containers
|
class Baktainer::Containers
|
||||||
def self.find_all
|
def self.find_all
|
||||||
LOGGER.debug('Searching for containers with backup labels.')
|
LOGGER.debug('Searching for containers with backup labels.')
|
||||||
containers = Docker::Container.all.select do |container|
|
containers = Docker::Container.all.select do |container|
|
||||||
|
|
|
@ -4,8 +4,6 @@ services:
|
||||||
image: jamez01/baktainer:latest
|
image: jamez01/baktainer:latest
|
||||||
container_name: baktainer
|
container_name: baktainer
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
|
||||||
- "8080:8080"
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./backups:/backups
|
- ./backups:/backups
|
||||||
- ./config:/config
|
- ./config:/config
|
||||||
|
|
Loading…
Add table
Reference in a new issue