core-agent-linux/qubes-rpc/qubes.RegisterBackupLocation
Marek Marczykowski-Górecki 8066129445
Add services for paranoid backup restore mode
Add a pair of services:
1. qubes.RegisterBackupLocation - called by dom0, registers what backup
location (including both file and command options) can be accessed.
Registered location gets an ID returned to the caller. The location (and
its ID) is valid as long as the service call remains open.

2. qubes.RestoreById - called by restoring DispVM to retrieve the backup
content. The service expects location ID as an argument, and then list
of files/directories (separated with spaces) on the first line of stdin.
This is very similar to qubes.Restore service, with exception for the
archive location control.

QubesOS/qubes-issues#5310
2020-08-03 03:43:09 +02:00

33 lines
918 B
Bash

#!/bin/sh
# Register backup location (path or a command) to be retrieved with qubes
# .RestoreById service.
# Registered location is only valid as long as this service call stays open
set -e
REGISTRY_DIR="$XDG_RUNTIME_DIR/qubes-backup-location"
if ! [ -d "$REGISTRY_DIR" ]; then
mkdir -p "$REGISTRY_DIR"
fi
read -r backup_location
REGISTRY_FILE=$(mktemp "$REGISTRY_DIR/XXXXXXXX")
PID=$$
# this isn't perfetct, as comm field could contain spaces, but we do control
# this value and we know it doesn't
START_TIME=$(cut -f 22 -d ' ' /proc/$PID/stat)
# add process id at the beginning to help verifying if it's still running;
# record starttime too, to detect PID reuse
printf "%d %d\n%s\n" "$PID" "$START_TIME" "$backup_location" >"$REGISTRY_FILE"
# output registered ID to the user
basename "$REGISTRY_FILE"
# close stdout
exec >&-
# wait for stdin to close
cat >/dev/null
# and cleanup
rm -f "$REGISTRY_FILE"