qubes.Restore 1.3 KB

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