Advertisement
Guest User

VovaTiunov

a guest
Nov 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. mkdir JUSTFORBACKUP
  3. echo "Path to Directory, EXAMPLE:/home/admin00/Desktop"
  4. #read pathToDirectory
  5. echo "Rasshirenie, EXAMPLE:.txt"
  6. #read rasshirenie
  7. pathToDirectory="/home/admin00/Desktop/aaa/"
  8. rasshirenie=".txt"
  9. maxCopiesCount=5
  10. currentDate=$(date +%Y-%m-%d-%S)
  11. #firstsize=$(du -bS *.txt $pathToDirectory)
  12.  
  13.  
  14. #archivate
  15. tar -cf JUSTFORBACKUP/ArchiveForBackup$currentDate.tar $pathToDirectory*$rasshirenie
  16.  
  17.  
  18. #check if archive is bad
  19. tar -xf JUSTFORBACKUP/ArchiveForBackup$currentDate.tar >> /dev/null; echo $?
  20.  
  21.  
  22.  
  23. #delete old copies
  24. allCount=$((ls -f JUSTFORBACKUP)|(wc -l))
  25. copiesCount=$(($allCount-2)) #get Copies count
  26. for i in $(find -type f -name "*.tar" | sort)
  27. do
  28. if [[ $copiesCount < $(($maxCopiesCount+1)) ]]
  29. then
  30. echo $copiesCount
  31. break
  32. else
  33. rm $i
  34. copiesCount=$(($copiesCount-1))
  35. echo $copiesCount
  36. fi
  37. done
  38.  
  39.  
  40. #time when you do this
  41. #$(crontab -l; echo "0 0 * * 5/home/admin00/Desktop/backup.sh") | crontab -
  42. #cat <(crontab -l) <(echo "0 0 * * 5/home/admin00/Desktop/backup.sh") | crontab -
  43. #$(crontab -l 2>&/dev/null; echo "0 0 * * 5/home/admin00/Desktop/backup.sh")|crontab -
  44. #crontab -l|{cat; echo "0 0 * * 5/home/admin00/Desktop/backup.sh";}|crontab -
  45. #does backup every friday
  46. # in terminal: crontab -e, then 0 0 * * 5/home/admin00/Desktop/backup.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement