Skip to content
Snippets Groups Projects
Commit fd107ea9 authored by jurgenhaas's avatar jurgenhaas
Browse files

Merge branch 'develop' into 'main'

Merging develop into main

See merge request !33
parents 21f348ca c4150b73
No related branches found
No related tags found
1 merge request!33Merging develop into main
Pipeline #575721 failed
...@@ -167,7 +167,8 @@ class Handler extends BaseHandler { ...@@ -167,7 +167,8 @@ class Handler extends BaseHandler {
'backup' => [ 'backup' => [
'enable' => FALSE, 'enable' => FALSE,
'version' => 'base-1.2.0-1.6.0', 'version' => 'base-1.2.0-1.6.0',
'crontime' => '0 1 * * *', 'crontime' => '50 */6 * * *',
'crontimecheck' => '30 23 1 * *',
'remoterepo' => FALSE, 'remoterepo' => FALSE,
'retention' => [ 'retention' => [
'hourly' => 2, 'hourly' => 2,
...@@ -220,6 +221,19 @@ class Handler extends BaseHandler { ...@@ -220,6 +221,19 @@ class Handler extends BaseHandler {
$relatedprojectdomains[] = $related_subdomain . '.' . $traefik['domain']; $relatedprojectdomains[] = $related_subdomain . '.' . $traefik['domain'];
} }
$this->config->setValue('relatedprojectdomains', $relatedprojectdomains, FALSE); $this->config->setValue('relatedprojectdomains', $relatedprojectdomains, FALSE);
if ($alerta_api_key = getenv('ALERTA_APIKEY')) {
$alerta = [
'apikey' => $alerta_api_key,
];
if ($value = getenv('ALERTA_ENVIRONMENT')) {
$alerta['environment'] = $value;
}
if ($value = getenv('ALERTA_PROJECT_ID')) {
$alerta['project_id'] = $value;
}
$this->config->setValue('alerta', $alerta, FALSE);
}
} }
/** /**
...@@ -255,6 +269,14 @@ class Handler extends BaseHandler { ...@@ -255,6 +269,14 @@ class Handler extends BaseHandler {
$crontabs = $this->config->readValue('crontabs'); $crontabs = $this->config->readValue('crontabs');
$crontabs['enable'] = (array_sum(array_map('count', $crontabs)) > 0); $crontabs['enable'] = (array_sum(array_map('count', $crontabs)) > 0);
if (!$isStaging) { if (!$isStaging) {
$crontabs['borgmatic']['Backup'] = [
'schedule' => $this->config->readValue(['backup', 'crontime']),
'command' => 'backup',
];
$crontabs['borgmatic']['Check backup'] = [
'schedule' => $this->config->readValue(['backup', 'crontimecheck']),
'command' => 'check',
];
$crontabs['www-data']['MySQL backup'] = [ $crontabs['www-data']['MySQL backup'] = [
'schedule' => '5 0 * * *', 'schedule' => '5 0 * * *',
'command' => 'cd /var/www/html && /usr/local/bin/drush sql:dump --result-file=/var/backups/mysql/drupal.sql', 'command' => 'cd /var/www/html && /usr/local/bin/drush sql:dump --result-file=/var/backups/mysql/drupal.sql',
...@@ -622,13 +644,20 @@ class Handler extends BaseHandler { ...@@ -622,13 +644,20 @@ class Handler extends BaseHandler {
// Add leading "0" for seconds. // Add leading "0" for seconds.
$schedule = '0 ' . $schedule; $schedule = '0 ' . $schedule;
} }
$activeTasks[] = [ if ($user === 'borgmatic') {
'name' => $task['name'], $backup = $this->config->readValue('backup');
'schedule' => $schedule, $backup['healthckeck_url'][$command] = $ping_url;
'command' => $command, $this->config->setValue('backup', $backup, FALSE);
'ping_url' => $ping_url, }
'user' => $user, else {
]; $activeTasks[] = [
'name' => $task['name'],
'schedule' => $schedule,
'command' => $command,
'ping_url' => $ping_url,
'user' => $user,
];
}
} }
} }
if (!empty($activeTasks)) { if (!empty($activeTasks)) {
......
...@@ -41,9 +41,18 @@ consistency: ...@@ -41,9 +41,18 @@ consistency:
prefix: 'backup-' prefix: 'backup-'
hooks: hooks:
mysql_databases:
- name: drupal
hostname: mariadb
port: 3306
username: drupal
password: drupal
options: '--skip-comments --no-tablespaces'
before_backup: before_backup:
- echo "`date` - Starting backup" - echo "`date` - Starting backup"
after_backup: after_backup:
- echo "`date` - Finished backup" - echo "`date` - Finished backup"
{% if alerta is defined %}
on_error: on_error:
- /usr/local/bin/alertalerta.py --pid={{ CI_PROJECT_ID }} {{ HOST_NAME|default('unknown') }} {{ ALERTA_ENVIRONMENT|default("production") }} {{ ALERTA_WEBHOOK|default('https://alerta.lakedrops.com/api') }} {{ ALERTA_APIKEY }} '{"service":["https://www.borgbase.com"],"resource":"{{ HOST_NAME|default('unknown') }}","event":"Borg {configuration_filename}","value":"{repository}","text":"Borg {configuration_filename}","rawData":"{output}"}' - echo -n '{"service":["https://www.borgbase.com"],"resource":"{{ HOST_NAME|default('unknown') }}","event":"Borg {configuration_filename}","value":"{repository}","text":"Borg {configuration_filename}","rawData":"{output}"}' | nc -u -w1 alerta {{ alerta.proxy_port|default(20002) }}
{% endif %}
{{ backup.crontime }} PATH=$PATH:/usr/bin /usr/bin/borgmatic --stats -v 0 2>&1 {{ backup.crontime }} PATH=$PATH:/usr/bin /usr/bin/borgmatic --stats -v 0 2>&1 && curl -fsS --retry 5 --retry-delay 9 -o /dev/null {{ backup.healthckeck_url.backup }}
30 23 1 * * PATH=$PATH:/usr/bin /usr/local/bin/borgmatic --check -v 0 2>&1 {{ backup.crontimecheck }} PATH=$PATH:/usr/bin /usr/local/bin/borgmatic --check -v 0 2>&1 && curl -fsS --retry 5 --retry-delay 9 -o /dev/null {{ backup.healthckeck_url.check }}
...@@ -482,6 +482,24 @@ services: ...@@ -482,6 +482,24 @@ services:
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
{% endif %} {% endif %}
{% if drupal.live|default(0) %} {% if drupal.live|default(0) %}
{% if alerta is defined %}
alerta:
image: 'registry.lakedrops.com/docker/alerta-proxy:1.0.1'
restart: unless-stopped
tty: true
environment:
- ALERTA_API_KEY={{ alerta.apikey }}
{% if alerta.environment is defined %}
- ALERTA_ENVIRONMENT={{ alerta.environment }}
{% endif %}
{% if alerta.project_id is defined %}
- ALERTA_PROJECT_ID={{ alerta.project_id }}
{% endif %}
{% if alerta.proxy_port is defined %}
- PORT={{ alerta.proxy_port }}
{% endif %}
{% endif %}
{% if backup.enable|default(0) %} {% if backup.enable|default(0) %}
borgmatic: borgmatic:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment