core-agent-linux/qubes-rpc/qubes.Restore
Marek Marczykowski-Górecki b38ea60f00
backup: improve exit code reporting
Return some meaningful error code. Unfortunately the more meaningful
option (retrieving process exit code) can lead to false errors
(described in comment), but at least report exit code of tar2qfile.
2015-11-02 03:10:22 +01:00

39 lines
1.3 KiB
Plaintext

echo Starting Restorecopy >&2
read args
read paths
echo Arguments: $args >&2
echo Paths: $paths >&2
if [ -f "$args" ] ; then
echo "Performing restore from backup file $args" >&2
TARGET="$args"
echo "Copying $TARGET to STDOUT" >&2
/usr/lib/qubes/tar2qfile "$TARGET" $paths
else
echo "Checking if arguments is matching a command" >&2
COMMAND=`echo $args | cut -d ' ' -f 1`
if which "$COMMAND" >/dev/null; then
tmpdir=`mktemp -d`
mkfifo $tmpdir/backup-data
echo "Redirecting $args to STDOUT" >&2
# Parsing args to handle quotes correctly
# Dangerous method if args are uncontrolled
eval "set -- $args"
# Use named pipe to pass original stdin to tar2file
$@ > $tmpdir/backup-data < /dev/null &
/usr/lib/qubes/tar2qfile $tmpdir/backup-data $paths
# Restoration may be terminated earlier because of selected files. This
# will be seen as EPIPE to the retrieving process, which may cause retcode
# other than 0 in some cases - which would be incorrectly treated as backup
# restore error. So instead of that, use tar2qfile exit code (and have dom0
# detect if anything wrong with actual data)
retcode=$?
wait -n
rm $tmpdir/backup-data
rmdir $tmpdir
exit $retcode
else
echo "Invalid command $COMMAND" >&2
exit 2
fi
fi