daily pastebin goal
24%
SHARE
TWEET

shibiru

a guest Mar 24th, 2019 50 in 2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Bash
  2.  
  3. declare -a cf
  4. declare -a pf
  5. declare -a cfc
  6. declare -a pfc
  7. declare -a pfi
  8. declare i
  9. declare j
  10. declare k
  11. declare buwd
  12. declare datum
  13. declare archname
  14. declare currname
  15. declare bushdir
  16.  
  17. while IFS=" " read -r cfield pfield; do [[ $cfield = \#* ]] && continue
  18.                             cf[i]=$cfield
  19.                             pf[i]=$pfield
  20. #                           printf '%s\n' "${cf[i]} ${pf[i]}"
  21.                 let "i += 1"
  22.                         done < $1
  23.  
  24. #The code above reads the two coloumns of the given file into two arrays, cf[i] as command field, and pf[i] as path field, while increasing the variable i with each coloumn, ignoring comment signs.
  25.  
  26.  
  27.  
  28.  
  29. while [[ $i != 0 ]]; do
  30.  #  printf '%s\n' "${pf[i]}"
  31.     if [ ! -z ${cf[i]} ]
  32.     then
  33.         cfc[i]+=${cf[i]}
  34.     pfc[i]+=${pf[i]}
  35.         let "j += 1"
  36.     fi
  37.     let "i -= 1"
  38. done
  39.  
  40. #The code above cycles through the cf and pf arrays and gives their value to the cfc and pfc ("command field corrected" and "path field corrected") only if it isn't empty, while decreasing the variable i, to do as many iterations as there are variables in the arrays, while increasing the variable j.
  41.  
  42.  
  43. k=1
  44.  
  45. #printf '%s\n' "$k"
  46.  
  47. while [[ $j != 0 ]]; do
  48. #   printf '%s\n' "${cfc[j]}"
  49.     case ${cfc[j]} in
  50.         INCLUDE)
  51. #       pfi+=( "${pfc[j]}" )
  52.         pfi[k]=${pfc[j]}
  53. #       printf '%s\n' "${pfi[j]}"
  54.         let "k += 1"
  55.         ;;
  56.     BUWORKDIR)
  57.         buwd=${pfc[j]}
  58. #       printf '%s\n' "$buwd"
  59.         ;;
  60.     ARCHNAME)
  61.         archname=${pfc[j]}
  62. #       printf '%s\n' "$archname"
  63.         ;;
  64.     BUSHDIR)
  65.         bushdir=${pfc[j]}
  66. #       printf '%s\n' "$bushdir"
  67.         ;;
  68.  
  69.     *)
  70.         printf '%s\n' "Unknown command '${cfc[j]}'"
  71.         ;;
  72.     esac  
  73.     let "j -= 1"
  74. done
  75.  
  76. #The code above cycles through the array cfc and if it's = "INCLUDE" then it adds it's value to the array pfi.("path field include"), while increasing the variable k every step. If cfc=BUWORKDIR then it adds its value to the variable buwd. The cycle stops when the variable j reaches zero, which is the number of variables in the array pfc.
  77.  
  78. cd $bushdir
  79. mkdir $buwd
  80.  
  81. let "k -= 1"
  82.  
  83. #printf '%s\n' "$k"
  84.  
  85. #printf '%s\n' "${pfi[1]}"
  86.  
  87. while [[ $k != 0 ]]; do
  88. #    printf '%i\n' "$k"
  89. #    printf '%s\n' "${pfi[k]}"
  90.     cp -v --parents "${pfi[k]}" "$buwd"
  91.     let "k -= 1"
  92. done
  93.  
  94. #The code above cycles through the array pfi, and copies every file written in this array to the location written in the variable buwd, while decreasing the variable k in every step, which is the number of files included.
  95.  
  96.  
  97.  
  98.  
  99. datum=`date +"%Y-%m-%d-%H-%-M-%S"`
  100. #printf '%s\n' "$datum"
  101. currname=${archname}${datum}.tar.gz
  102. #printf '%s\n' "$currname"
  103. tar -czvf $currname -C $bushdir $buwd
  104. rm -rf $buwd
  105. cd ~
  106.  
  107. #The code above fills a variable with the current date and time, concatenate it with the filename given in config, and archives, then compresses the backupped files into a tar.gz archive. Then the code deletes the files.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top