qubes.Restore 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. echo Starting Restorecopy >&2
  3. read args
  4. read paths
  5. echo Arguments: $args >&2
  6. echo Paths: $paths >&2
  7. if [ -f "$args" ] ; then
  8. echo "Performing restore from backup file $args" >&2
  9. TARGET="$args"
  10. echo "Copying $TARGET to STDOUT" >&2
  11. /usr/lib/qubes/tar2qfile "$TARGET" $paths
  12. else
  13. echo "Checking if arguments is matching a command" >&2
  14. COMMAND=`echo $args | cut -d ' ' -f 1`
  15. if type "$COMMAND" >/dev/null; then
  16. tmpdir=`mktemp -d`
  17. mkfifo $tmpdir/backup-data
  18. echo "Redirecting $args to STDOUT" >&2
  19. # Parsing args to handle quotes correctly
  20. # Dangerous method if args are uncontrolled
  21. eval "set -- $args"
  22. # Use named pipe to pass original stdin to tar2file
  23. $@ > $tmpdir/backup-data < /dev/null &
  24. /usr/lib/qubes/tar2qfile $tmpdir/backup-data $paths
  25. # Restoration may be terminated earlier because of selected files. This
  26. # will be seen as EPIPE to the retrieving process, which may cause retcode
  27. # other than 0 in some cases - which would be incorrectly treated as backup
  28. # restore error. So instead of that, use tar2qfile exit code (and have dom0
  29. # detect if anything wrong with actual data)
  30. retcode=$?
  31. wait -n
  32. rm $tmpdir/backup-data
  33. rmdir $tmpdir
  34. exit $retcode
  35. else
  36. echo "Invalid command $COMMAND" >&2
  37. exit 2
  38. fi
  39. fi