executable_backup 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. case "$1" in
  5. clean)
  6. cat <<'EOF'
  7. Backups for guix.wugi.info:
  8. EOF
  9. sudo --login \
  10. RESTIC_PASSWORD="$(pass show wugi.info/restic/all)" \
  11. RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/guixsd}" \
  12. "$HOME/.guix-profile/bin/restic" --json snapshots \
  13. | jq -c --raw-output '. | reverse.[] | [.time, .tags]' \
  14. | cat -n \
  15. | tac
  16. echo sudo --login \
  17. 'RESTIC_PASSWORD="$(pass show wugi.info/restic/all)"' \
  18. 'RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/guixsd}"' \
  19. "$HOME/.guix-profile/bin/restic" \
  20. forget --prune --keep-last N
  21. cat <<'EOF'
  22. Backups for windows.local:
  23. EOF
  24. sudo --login \
  25. RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)" \
  26. RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/win10}" \
  27. "${HOME}/.guix-profile/bin/restic" --json snapshots \
  28. | jq -c --raw-output '. | reverse.[] | [.time, .tags]' \
  29. | cat -n \
  30. | tac \
  31. | grep null \
  32. | tail -5
  33. echo sudo --login \
  34. 'RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)"' \
  35. 'RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/win10}"' \
  36. "$HOME/.guix-profile/bin/restic" \
  37. forget --prune --keep-last N
  38. cat <<'EOF'
  39. Backups for ntfsgames:
  40. EOF
  41. sudo --login \
  42. RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)" \
  43. RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/ntfsgames}" \
  44. "${HOME}/.guix-profile/bin/restic" --json snapshots \
  45. | jq -c --raw-output '. | reverse.[] | [.time, .tags]' \
  46. | cat -n \
  47. | tac \
  48. | grep null \
  49. | tail -5
  50. echo sudo --login \
  51. 'RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)"' \
  52. 'RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/ntfsgames}"' \
  53. "$HOME/.guix-profile/bin/restic" \
  54. forget --prune --keep-last N
  55. ;;
  56. *)
  57. sudo --login \
  58. RESTIC_PASSWORD="$(pass show wugi.info/restic/all)" \
  59. RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/guixsd}" \
  60. "$HOME/.guix-profile/bin/restic" "$@"
  61. # shellcheck disable=SC2016
  62. cat <<'EOF'
  63. Restore "${HOME}/.mozilla" backup example:
  64. sudo --login RESTIC_PASSWORD="$(pass show wugi.info/restic/all)" RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/guixsd}" "${HOME}/.guix-profile/bin/restic" restore latest --include "${HOME}/.mozilla" --target /
  65. List Windows snapshots:
  66. sudo --login RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)" RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/win10}" "${HOME}/.guix-profile/bin/restic" snapshots
  67. Restore Windows snapshot:
  68. RESTIC_PASSWORD="$(sudo cat /etc/guix/secrets/windows)" RESTIC_REPOSITORY="${RESTIC_REPOSITORY:-/srv/backup/win10}" "${HOME}/.guix-profile/bin/restic" dump latest win10.img | dd of=/dev/lvm1/win10 bs=4M
  69. EOF
  70. ;;
  71. esac