Charm architecture: bacula-fd¶
The bacula-fd charm is a subordinate charm that installs and manages the Bacula file daemon on target machines. Bacula-fd (Bacula File Daemon) is the backup agent that needs to be installed on machines requiring backups. The bacula-fd handles many important duties, such as uploading backup files and downloading restored backup files.
High-level overview of backup charms deployment¶
Here’s a typical backup charm suite deployment in the machine charm environment. This deployment shows the bacula-server charm as the backup server, the bacula-fd charm as the backup agent, and the backup-integrator charm as the backup relation provider.
The backup-integrator charm requests backups from the bacula-fd charm on
behalf of the backup source charm source. The bacula-fd charm then
integrates with the bacula-server charm to submit the backup files. The
bacula-server charm is integrated with the PostgreSQL charm for storing
backup metadata and with the s3-integrator charm to use S3 storage as
the destination for backup files.
C4Context
title Container diagram for backup charms
System_Boundary(backup server, "Backup Server Model") {
Container(s3-integrator, "S3 Integrator", "", "Provide backup destination")
Container(bacula-server, "Bacula Server", "", "Backup server")
Container(postgresql, "PostgreSQL", "", "Store backup metadata")
Rel(s3-integrator, bacula-server, "")
Rel(postgresql, bacula-server, "")
}
System_Boundary(backup source, "Backup Source Model") {
Container_Boundary(backup-source, "Backup Source") {
Component(source, "", "Backup source principal charm")
Component(backup-integrator, "", "Backup relation integrator")
Component(bacula-fd, "", "Bacula file daemon")
}
Rel(source, backup-integrator, "")
Rel(backup-integrator, bacula-fd, "")
}
Rel(bacula-fd, bacula-server, "")
Juju events¶
config-changed: Monitors changes to the backup integrator configuration to update the relation data with the latest configuration values.
leader-elected,leader-settings-changed: Monitors changes in the charm’s leadership. Since only the leader unit can modify application relation data, triggering a relation data update when leadership changes ensures the relation is updated regardless of leader status during relation establishment.upgrade-charm: Triggered when the charm has been upgraded. This ensures that the new version of the backup integrator charm can update the relation data if needed.
bacula-dir-relation-changed,
bacula-dir-relation-broken: Monitors changes, creation, and removal of thebacula-dirrelation to update relation data when needed.backup-relation-changed, backup-relation-broken, backup-relation-departed: Monitors changes, creation, and removal of the
backuprelation to update relation data when needed.secret-changed: Monitors changes in secrets inside relations to update configuration when needed.
Note
See more in the Juju docs: Hook
Charm code overview¶
The src/__main__.py file is the default entry point for the backup
integrator charm; it creates an instance of the BaculaFdCharm
class (imported from the charm module), which inherits from
ops.CharmBase. ops.CharmBase is the base class from which all charms
are derived, provided
by Ops (the Python
framework for developing charms).
Note
See more in the Juju docs: Charm
The __init__ method of BaculaFdCharm ensures that the charm observes
and handles all events relevant to its operation.
For example, when a configuration is changed via the CLI:
The user runs the configuration command:
juju config bacula-fd port=8888
A
config-changedevent is emitted.In the
__init__method, the handler for this event is defined as follows:
self.framework.observe(self.on.config_changed, self._reconcile_event)
The
__reconcile_eventmethod, in turn, takes the necessary actions, such as waiting for the backup relation(s) and updating the backup relation data.