Advertisement
v1ral_ITS

EASY Compressed Backup Script [ ANY FILES/DIRECTORIES ]

Jun 23rd, 2020
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #/#/ Define any tools needed here seperated only by a "\:space:"\
  4. needed_tool=' yad rsync tar '
  5.  
  6. #//* Begin System Tool Search
  7. require_tools ()
  8. {
  9.     local NOT_AVAIL=""
  10.     for TOOL in $needed_tool; do
  11.         if [ "`which $TOOL`" 2> /dev/null == "" ]; then
  12.     NOT_AVAIL="$NOT_AVAIL $TOOL";
  13.     fi
  14.     done
  15.     if [[ "$NOT_AVAIL" != "" ]]; then
  16.     echo "ERROR: The following required tool(s) cannot be found: $NOT_AVAIL"
  17.         exit 3
  18.     fi
  19. }
  20.  
  21. # Check file system tools before we start
  22. require_tools || exit 1
  23.  
  24. # VARIABLES
  25. THIS_DIR=$PWD/TMP_BKUP
  26. MK_DIR=$(mkdir $THIS_DIR)
  27. FILE=./backup.$(echo $RANDOM).tar
  28. DESTIN="$(yad --title "Choose Direcotory To Backup" --file-selection --directory)"
  29.  
  30. # PREPERATION
  31. $MK_DIR
  32.  
  33. # ADDING FILE TO ARCHIVE
  34. rsync -vrhu --append-verify --progress "$DESTIN" "$THIS_DIR"
  35. echo -e "Files copied to temporary directory; press [E]nter to create compressed archive and remove the temporary directory: "
  36. read NULL
  37.  
  38. # COMPRESS BACKUP AND REMOVE FILES
  39. tar -vcf $FILE --remove-files "$THIS_DIR"
  40. echo -e "\nCompressed archive backup file has been created.\nPress [E]nter to cleanup and finish: "
  41. read NULL1
  42.  
  43. # FINISH
  44. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement