banovski

Backup

Jun 14th, 2022 (edited)
1,266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function exiting()
  4. {
  5.     espeak -v english "$1"
  6.     exit "$2"
  7. }
  8.  
  9. if test -f "$1"; then
  10.     file="$1"
  11. else
  12.     exiting "Invalid path or the file is missing" 1
  13. fi
  14.  
  15. path_to_parent_directory=$(dirname "$file")
  16. cd "$path_to_parent_directory" || exiting "Couldn't access the directory!"
  17.  
  18. mkdir backup
  19.  
  20. file_extension=".${file##*.}"
  21. current_copy="./backup/current_copy${file_extension}"
  22. cp "$file" "$current_copy"
  23.  
  24. yad --notification --image=archive &
  25. panel_control_pid=$!
  26.  
  27. while ps -p "$panel_control_pid"; do
  28.     if [ "$file" -nt "$current_copy" ]; then
  29.         cp "$current_copy" "./backup/$(date +%y-%m-%d_%H-%M-%S)${file_extension}"
  30.         cp "$file" "$current_copy"
  31.         play -n synth 0.1 sine 220 vol -24dB
  32.     fi
  33.     sleep 3
  34. done
  35.  
  36. exiting "Quitting" 0
  37.  
  38.  
Add Comment
Please, Sign In to add comment