Advertisement
justin_hanekom

Bash script to tar home/justin to current directory

Aug 22nd, 2020
2,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.11 KB | None | 0 0
  1. # File: tar-home.sh
  2. # Copyright (c) 2018-2020 Justin Hanekom <justinhanekom@rogers.com>
  3. # Licensed under the MIT License
  4.  
  5. # Permission is hereby granted, free of charge, to any person obtaining
  6. # a copy of this software and associated documentation files
  7. # (the "Software"), to deal in the Software without restriction,
  8. # including without limitation the rights to use, copy, modify, merge,
  9. # publish, distribute, sublicense, and/or sell copies of the Software,
  10. # and to permit persons to whom the Software is furnished to do so,
  11. # subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be
  14. # included in all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20. # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  
  24. # Setup a safe Bash scripting environment
  25.  
  26. set -o errexit      # Exit immediately if an error occurs
  27. set -o noclobber    # Do not allow files to be overwritten via redirect
  28. set -o nounset      # Do not allow unset variables
  29.  
  30. # Set the exit code of a pipeline to the rightmost non-zero on error
  31.  
  32. set -o pipefail
  33.  
  34. # Set the internal field separator to newline or tab, but not space
  35.  
  36. IFS=$'\n\t'
  37.  
  38. # Setup a secure Bash scripting environment by: setting a secure path;
  39. # clearing all aliases; clearing the command path hash; setting the hard limit
  40. # to 0 to turn off core dumps; and setting a secure umask
  41.  
  42. PATH=$(PATH='/bin:/usr/bin' getconf PATH); export PATH
  43. builtin unalias -a
  44. hash -r
  45. ulimit -H -c 0 --
  46.  
  47. UMASK=002
  48. umask ${UMASK}
  49.  
  50. # Global constant definitions
  51.  
  52. TS=$(date '+%Y%m%d%H%M%S')
  53. FILE="home-justin_${TS}.tar.gz"
  54. DEST_DIR=$(pwd)
  55.  
  56. (
  57.     cd /home
  58.     tar --create --atime-preserve --gzip --preserve-permissions --seek \
  59.     --verbose --file="${DEST_DIR}/${FILE}" justin || true
  60. )
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement