McdeSys gets the backup (lib/McdeSys/backup.c): a partition becomes the backup disk with an encrypted repository (borg init -e repokey-blake2); every hour root's crontab runs dtbackup run: borg create of / (and /home) on its own file systems, lz4, then prune -- 24 hourly, 30 daily, 52 weekly, every monthly unless set otherwise (keep_* in /etc/mcde-backup.conf, -1 keeps every one) -- and compact. The watcher: before and after each run, while the backup disk has less than min_free percent free (10 unless set), the oldest backup is deleted and the space given back; the newest is never deleted. Listing (borg list --json) and restoring a path into a folder (borg extract). The passphrase lives in /etc/mcde-backup.pass, root's alone, handed over by BORG_PASSCOMMAND. docs/reference/borg.txt from borg 1.4.5's own documentation. dtbackup run | status | list: the same from a shell and for cron, no X. Measured: builds on the Linux host and compiles in the build VM; as a user dtbackup status says no disk is set up and dtbackup run refuses. Not measured: a real backup -- borg is not on the host and goes into the set with the next userland. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
/*
|
|
* dtbackup.c -- MCDE: the backup from the command line, and for cron
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* dtbackup run one backup now (root's crontab runs this every hour,
|
|
* System Settings, Backup)
|
|
* dtbackup status the backup disk, whether it runs, the last backup
|
|
* dtbackup list the backups there are
|
|
*
|
|
* The work is McdeSys's (lib/McdeSys/backup.c, BorgBackup). No X: cron
|
|
* has no display.
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
|
|
static int
|
|
Usage(void)
|
|
{
|
|
fprintf(stderr, "usage: dtbackup run | status | list\n");
|
|
return 2;
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
static char log[65536];
|
|
static McdeSysBackupArchive a[2048];
|
|
McdeSysBackup b;
|
|
int n, i;
|
|
|
|
if (argc != 2)
|
|
return Usage();
|
|
if (strcmp(argv[1], "run") == 0) {
|
|
if (mcde_sys_backup_run(log, sizeof log) != MCDE_SYS_OK) {
|
|
fprintf(stderr, "dtbackup: %s\n", mcde_sys_error());
|
|
fputs(log, stderr);
|
|
return 1;
|
|
}
|
|
fputs(log, stdout);
|
|
return 0;
|
|
}
|
|
if (strcmp(argv[1], "status") == 0) {
|
|
char when[64] = "never";
|
|
|
|
(void) mcde_sys_backup_get(&b);
|
|
if (b.last > 0) {
|
|
time_t t = (time_t) b.last;
|
|
|
|
strftime(when, sizeof when, "%Y-%m-%d %H:%M",
|
|
localtime(&t));
|
|
}
|
|
printf("disk: %s\nbackups: %s\nhourly: %s\nlast: %s "
|
|
"(%s)\n", b.configured ? b.disk : "none",
|
|
b.configured ? b.repo : "-", b.enabled ? "on" : "off", when,
|
|
b.result[0] != '\0' ? b.result : "-");
|
|
return 0;
|
|
}
|
|
if (strcmp(argv[1], "list") == 0) {
|
|
n = mcde_sys_backup_archives(a, sizeof a / sizeof a[0]);
|
|
if (n < 0) {
|
|
fprintf(stderr, "dtbackup: %s\n", mcde_sys_error());
|
|
return 1;
|
|
}
|
|
for (i = 0; i < n; i++)
|
|
printf("%s %s\n", a[i].time, a[i].name);
|
|
return 0;
|
|
}
|
|
return Usage();
|
|
}
|