feature: the router makes scheduled backups to a local folder, copied to the cloud with rclone, or to a Proxmox Backup Server, and vpn-router-backup restores them.
Release / release (push) Successful in 13s
Release / release (push) Successful in 13s
This commit is contained in:
1 parent
7d1f639508
commit
fe45272f7c
16 files changed
+986
-19
No files matched your search
@@ -63,6 +63,9 @@ MANAGER_PORT = 7080
|
||||
#: The password of the metrics service account, which setup makes and keeps (root only).
|
||||
METRICS_SECRET = pathlib.Path('/etc/vpn-router/metrics.secret')
|
||||
|
||||
#: The schedule of the backup timer, written from backup.schedule.
|
||||
BACKUP_SCHEDULE = pathlib.Path('/etc/systemd/system/vpn-router-backup.timer.d/schedule.conf')
|
||||
|
||||
#: The configuration of Caddy, the HTTPS proxy, which the package's drop-in for caddy.service names;
|
||||
#: Caddy runs as the user and group CADDY_GROUP, which the caddy package creates.
|
||||
CADDYFILE = pathlib.Path('/etc/caddy/vpn-router.Caddyfile')
|
||||
@@ -566,6 +569,27 @@ def manage_metrics(ctx):
|
||||
run(['systemctl', 'restart', unit], check=False)
|
||||
|
||||
|
||||
def manage_backup(cfg):
|
||||
"""Run the backup timer on backup.schedule while backups are enabled, and stop it when not.
|
||||
|
||||
The schedule is a drop-in of the timer, BACKUP_SCHEDULE, which replaces the OnCalendar of the shipped unit.
|
||||
"""
|
||||
unit = 'vpn-router-backup.timer'
|
||||
if not cfg['backup']['enabled']:
|
||||
run(['systemctl', 'disable', '--now', unit], check=False)
|
||||
if BACKUP_SCHEDULE.exists():
|
||||
BACKUP_SCHEDULE.unlink()
|
||||
run(['systemctl', 'daemon-reload'], check=False)
|
||||
return
|
||||
text = f'[Timer]\nOnCalendar=\nOnCalendar={cfg["backup"]["schedule"]}\n'
|
||||
if not BACKUP_SCHEDULE.exists() or BACKUP_SCHEDULE.read_text(encoding='utf-8') != text:
|
||||
BACKUP_SCHEDULE.parent.mkdir(parents=True, exist_ok=True)
|
||||
BACKUP_SCHEDULE.write_text(text, encoding='utf-8')
|
||||
run(['systemctl', 'daemon-reload'], check=False)
|
||||
run(['systemctl', 'restart', unit], check=False)
|
||||
run(['systemctl', 'enable', '--now', unit], check=False)
|
||||
|
||||
|
||||
def run_platform_setup(cfg, ctx):
|
||||
"""Let the platform module apply its own state, if it defines any."""
|
||||
module = vpnrouter.platform_module(cfg)
|
||||
@@ -734,6 +758,8 @@ def main():
|
||||
refresh_web(cfg, ctx)
|
||||
progress('running', 'metrics service')
|
||||
manage_metrics(ctx)
|
||||
progress('running', 'backup timer')
|
||||
manage_backup(cfg)
|
||||
if problem:
|
||||
progress('failed', failed_step, problem)
|
||||
print(f'vpn-router: error: {problem}', file=sys.stderr)
|
||||
|
||||
Reference in new issue
Block a user