Guest User

Untitled

a guest
Oct 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #!/usr/bin/zsh
  2. # zsh-sysbackup.zsh
  3. # Ashton Hellwig @ashellwig
  4. # Purpose: Performs a full system backup using Rsync
  5.  
  6. # --- Pre-Backup ---
  7. function pre_run_func() {
  8. local build_dir="~/tmp/BUILDS"
  9. mkdir -p "${build_dir}"
  10. cat << END > "${build_dir}/rsync-exclude.txt"
  11. /home/ahellwig/tmp/***
  12. /home/ahellwig/.cache/***
  13. /home/ahellwig/.vscode/***
  14. /home/ahellwig/.cargo/***
  15. /home/ahellwig/.rustup/***
  16. /home/ahellwig/.cargo/***
  17. /home/ahellwig/.g*/***
  18. /dev/*
  19. /proc/*
  20. /sys/*
  21. /tmp/*
  22. /run/*
  23. /mnt/*
  24. /media/*
  25. /lost+found
  26. /swapfile
  27. /srv/*
  28. /var/log/*
  29. END
  30. cd "${build_dir}"
  31. return
  32. }
  33.  
  34. # --- Backup Function ---
  35. function run_func() {
  36. # For production, replace '--dry-run' with '--info=flist2,name,progress'
  37. local build_dir="~/tmp/BUILDS"
  38. sudo rsync '-aAxXhHv' '--partial' '--delete' '--dry-run' '--exclude-from="${build_dir}/rsync-exclude.txt"' '/' '/mnt/backup'
  39. return
  40. }
  41.  
  42. # --- Clean Function ---
  43. function clean_func() {
  44. local build_dir="~/tmp/BUILDS"
  45. if [[ "$(pwd)" = "${build_dir}"]]; then
  46. cd ~
  47. fi
  48. rm '-rf' "${build_dir}"
  49. return
  50. }
  51.  
  52. # --- Call to Functions ---
  53. function main_func() {
  54. print -f "\033[3;33m\nCreating Necessary Directories...\033[0m\n"
  55. pre_run_func
  56.  
  57. print -f "\n\033[3;4;32mBeginning Backup\033[0m\n"
  58. run_func
  59.  
  60. print -f "\n\033[3;33m \033[0m\n"
  61. clean_func
  62.  
  63. print -f "\n\033[3;33mUnsetting functions and variables...\033[0m\n"
  64. if [[ -v build_dir ]]; then
  65. unset build_dir
  66. fi
  67. unfunction pre_run_func &
  68. unfunction run_func &
  69. unfunction clean_func
  70.  
  71. print -f "\n\033[1;32mDone!\033[0m\n"
  72. return 0
  73. }
  74.  
  75. # --- Script ---
  76. main_func
  77.  
  78. # Final Cleanup
  79. unfunction main_func
  80. return 0
  81.  
  82. # vim: set et ts=2 sw=2 ft=zsh:
Add Comment
Please, Sign In to add comment