eerevert.in 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. . <(ffoom init)
  3. FFOO_INI_PATH="__FFOO_INI_PATH__"
  4. ffoo import core
  5. ffoo import ini
  6. ffoo import recon
  7. usage() {
  8. usage_is "[-d|--debug] [-v|--verbose] [--dry-run] [-c|--connection] domain [snapshot]"
  9. }
  10. FFOO_DRY_RUN=false
  11. connection="qemu:///system"
  12. while true; do
  13. case $1 in
  14. -c|--connection)
  15. connection=$2
  16. shift 2
  17. ;;
  18. -d|--debug)
  19. FFOO_DEBUG=true
  20. shift 1
  21. ;;
  22. -q|--quiet)
  23. FFOO_VERBOSE=false
  24. shift 1
  25. ;;
  26. -v|--verbose)
  27. FFOO_VERBOSE=true
  28. shift 1
  29. ;;
  30. --dry-run)
  31. FFOO_DRY_RUN=true
  32. shift 1
  33. ;;
  34. "")
  35. usage
  36. ;;
  37. --)
  38. shift 1
  39. break
  40. ;;
  41. *)
  42. break
  43. ;;
  44. esac
  45. done
  46. domain="$1"
  47. snapshot="$2"
  48. test -z "$snapshot" && {
  49. think "looking for $domain in revert.ini"
  50. snapshot=$(iniread -1 -p revert.to.snapshot.$domain)
  51. }
  52. test -z "$snapshot" && {
  53. think "looking for default snapshot name in revert.ini"
  54. snapshot=$(iniread -1 -p revert.to.snapshot._default_)
  55. }
  56. test -z "$snapshot" && {
  57. die "could not determine snapshot for $domain"
  58. }
  59. think "reverting $domain to $snapshot"
  60. debug "virsh -c "$connection" snapshot-revert $domain $snapshot"
  61. $FFOO_DRY_RUN || virsh -c "$connection" snapshot-revert $domain $snapshot
  62. think "starting $domain"
  63. debug "virsh -c "$connection" start $domain"
  64. $FFOO_DRY_RUN || virsh -c "$connection" start $domain