archive.sh 484 B

12345678910111213141516171819202122
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. display_help(){
  4. echo "Usage: ${0##*/} [ext] [file/s]"
  5. exit 2
  6. }
  7. [[ $# -lt 2 ]] && display_help
  8. ext="$1"
  9. case "$ext" in
  10. zip) cmd="zip -r9" ;;
  11. 7z) cmd="7z a -t7z -mx=9" ;;
  12. tar) cmd="tar -uvf" ;;
  13. tar.*) cmd="tar -cavf" ;;
  14. # tar.zst) cmd="tar -c -I'zstd --ultra -filefile -T0' -vf" ;;
  15. h|\?|:|*) display_help ;;
  16. esac
  17. shift 1
  18. date=$(date +'%F')
  19. $cmd "archive_${date}_${1}.${ext}" -- "$@"