Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- mkdir JUSTFORBACKUP
- echo "Path to Directory, EXAMPLE:/home/admin00/Desktop"
- #read pathToDirectory
- echo "Rasshirenie, EXAMPLE:.txt"
- #read rasshirenie
- pathToDirectory="/home/admin00/Desktop/aaa/"
- rasshirenie=".txt"
- maxCopiesCount=5
- currentDate=$(date +%Y-%m-%d-%S)
- #firstsize=$(du -bS *.txt $pathToDirectory)
- #archivate
- tar -cf JUSTFORBACKUP/ArchiveForBackup$currentDate.tar $pathToDirectory*$rasshirenie
- #check if archive is bad
- tar -xf JUSTFORBACKUP/ArchiveForBackup$currentDate.tar >> /dev/null; echo $?
- #delete old copies
- allCount=$((ls -f JUSTFORBACKUP)|(wc -l))
- copiesCount=$(($allCount-2)) #get Copies count
- for i in $(find -type f -name "*.tar" | sort)
- do
- if [[ $copiesCount < $(($maxCopiesCount+1)) ]]
- then
- echo $copiesCount
- break
- else
- rm $i
- copiesCount=$(($copiesCount-1))
- echo $copiesCount
- fi
- done
- #time when you do this
- #$(crontab -l; echo "0 0 * * 5/home/admin00/Desktop/backup.sh") | crontab -
- #cat <(crontab -l) <(echo "0 0 * * 5/home/admin00/Desktop/backup.sh") | crontab -
- #$(crontab -l 2>&/dev/null; echo "0 0 * * 5/home/admin00/Desktop/backup.sh")|crontab -
- #crontab -l|{cat; echo "0 0 * * 5/home/admin00/Desktop/backup.sh";}|crontab -
- #does backup every friday
- # in terminal: crontab -e, then 0 0 * * 5/home/admin00/Desktop/backup.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement