Back up to /volumes and /databases
This commit is contained in:
parent
7f6b140a00
commit
d3933f8913
|
@ -16,8 +16,8 @@ This includes both host mapped volumes and actual docker volumes.
|
|||
* When backup starts a new instance of the container is created
|
||||
mapping in all the needed volumes. It will copy networks etc
|
||||
to ensure databases can be reached
|
||||
* Volumes are mounted to `/backup/<service_name>/<path>`
|
||||
in the backup process container. `/backup` is pushed into restic
|
||||
* Volumes are mounted to `/volumes/<service_name>/<path>`
|
||||
in the backup process container. `/volumes` is pushed into restic
|
||||
* Databases are backed up from stdin / dumps
|
||||
* Cron triggers backup
|
||||
|
||||
|
@ -117,7 +117,7 @@ volumes:
|
|||
|
||||
Will dump databases directly into restic through stdin.
|
||||
They will appear in restic as a separate snapshot with
|
||||
path `/backup/<service_name>/dump.sql` or similar.
|
||||
path `/databases/<service_name>/dump.sql` or similar.
|
||||
|
||||
```yaml
|
||||
mariadb:
|
||||
|
|
|
@ -82,7 +82,7 @@ def backup(config, containers):
|
|||
volumes = containers.this_container.volumes
|
||||
|
||||
# Map volumes from other containers we are backing up
|
||||
mounts = containers.generate_backup_mounts('/backup')
|
||||
mounts = containers.generate_backup_mounts('/volumes')
|
||||
volumes.update(mounts)
|
||||
|
||||
result = backup_runner.run(
|
||||
|
@ -123,7 +123,7 @@ def start_backup_process(config, containers):
|
|||
# Back up volumes
|
||||
try:
|
||||
logger.info('Backing up volumes')
|
||||
vol_result = restic.backup_files(config.repository, source='/backup')
|
||||
vol_result = restic.backup_files(config.repository, source='/volumes')
|
||||
logger.debug('Volume backup exit code: %s', vol_result)
|
||||
if vol_result != 0:
|
||||
logger.error('Backup command exited with non-zero code: %s', vol_result)
|
||||
|
|
|
@ -6,7 +6,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def test():
|
||||
return run_command(['ls', '/backup'])
|
||||
return run_command(['ls', '/volumes'])
|
||||
|
||||
|
||||
def ping_mysql(host, port, username, password) -> int:
|
||||
|
|
|
@ -163,6 +163,7 @@ class Container:
|
|||
if self._include:
|
||||
for mount in self._mounts:
|
||||
for pattern in self._include:
|
||||
print(pattern, self._include)
|
||||
if pattern in mount.source:
|
||||
break
|
||||
else:
|
||||
|
@ -182,7 +183,7 @@ class Container:
|
|||
|
||||
return filtered
|
||||
|
||||
def volumes_for_backup(self, source_prefix='/backup', mode='ro'):
|
||||
def volumes_for_backup(self, source_prefix='/volumes', mode='ro'):
|
||||
"""Get volumes configured for backup"""
|
||||
mounts = self.filter_mounts()
|
||||
volumes = {}
|
||||
|
@ -333,7 +334,7 @@ class RunningContainers:
|
|||
"""Obtain all containers with backup enabled"""
|
||||
return [container for container in self.containers if container.backup_enabled]
|
||||
|
||||
def generate_backup_mounts(self, dest_prefix='/backup') -> dict:
|
||||
def generate_backup_mounts(self, dest_prefix='/volumes') -> dict:
|
||||
"""Generate mounts for backup for the entire compose setup"""
|
||||
mounts = {}
|
||||
for container in self.containers_for_backup():
|
||||
|
|
|
@ -45,7 +45,7 @@ class MariadbContainer(Container):
|
|||
config = Config()
|
||||
return restic.backup_from_stdin(
|
||||
config.repository,
|
||||
f'/backup/{self.service_name}/all_databases.sql',
|
||||
f'/databases/{self.service_name}/all_databases.sql',
|
||||
self.dump_command(),
|
||||
)
|
||||
|
||||
|
@ -88,7 +88,7 @@ class MysqlContainer(Container):
|
|||
config = Config()
|
||||
return restic.backup_from_stdin(
|
||||
config.repository,
|
||||
f'/backup/{self.service_name}/all_databases.sql',
|
||||
f'/databases/{self.service_name}/all_databases.sql',
|
||||
self.dump_command(),
|
||||
)
|
||||
|
||||
|
@ -135,6 +135,6 @@ class PostgresContainer(Container):
|
|||
with utils.environment('PGPASSWORD', creds['password']):
|
||||
return restic.backup_from_stdin(
|
||||
config.repository,
|
||||
f"/backup/{self.service_name}/{creds['database']}.sql",
|
||||
f"/databases/{self.service_name}/{creds['database']}.sql",
|
||||
self.dump_command(),
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@ def init_repo(repository: str):
|
|||
]))
|
||||
|
||||
|
||||
def backup_files(repository: str, source='/backup'):
|
||||
def backup_files(repository: str, source='/volumes'):
|
||||
return commands.run(restic(repository, [
|
||||
"--verbose",
|
||||
"backup",
|
||||
|
|
Loading…
Reference in New Issue