rsync-external-backup 838 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bash
  2. # TODO LEGACY: USE BTRBK
  3. ask_ok() {
  4. read -r -p "$* [y/N]: " response
  5. response=${response,,}
  6. [[ ! "$response" =~ ^(yes|y)$ ]] && return 1
  7. return 0
  8. }
  9. declare -a include_dirs=(
  10. "$HOME/music"
  11. "$HOME/documents"
  12. "$HOME/downloads"
  13. "$HOME/pictures"
  14. "$HOME/ebooks"
  15. "$HOME/devices"
  16. "$HOME"/.*
  17. )
  18. declare -a exclude_dirs=(
  19. "$HOME/.**"
  20. "$HOME/..**"
  21. )
  22. declare destination="/run/media/bryan/4tb-external/$HOSTNAME"
  23. declare rsync_cmd="rsync -aAXL --info=progress2 --delete"
  24. for i in "${include_dirs[@]}"; do
  25. rsync_cmd+=" --include $i**"
  26. done
  27. for i in "${exclude_dirs[@]}"; do
  28. rsync_cmd+=" --exclude $i"
  29. done
  30. echo "Command to run: $rsync_cmd $destination"
  31. ask_ok "Continue?" || exit 1
  32. [[ ! -d "$destination" ]] && mkdir -p "$destination"
  33. eval "$rsync_cmd $destination"