Scripts that Oppaiti.me uses to run
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backup.sh 1017B

12345678910111213141516171819202122232425262728293031323334353637
  1. #! /bin/bash
  2. backup=/var/backup
  3. date=$(date "+%Y-%m-%d-%H%M%S")
  4. mysqlpw="AAAAAAAAAA"
  5. mkdir -p $backup/$date/www
  6. rsync -ax --delete --exclude='.git*' --exclude='misc/*' --link-dest=$backup/current/www/ /var/www/ $backup/$date/www/
  7. rsync -ax --delete --link-dest=$backup/current/torrents/ /var/torrents/ $backup/$date/torrents/
  8. mysqldump --single-transaction --password="${mysqlpw}" gazelle | gzip -c > $backup/$date/gazelle.sql.gz
  9. rm $backup/current
  10. ln -s $backup/$date $backup/current
  11. # One backup per day for backups older than 12 hours
  12. hourlies=$(find $backup -maxdepth 1 -type d -mmin +720 | sort)
  13. day=0
  14. for i in $hourlies; do
  15. rday=$(echo $i | awk -F '-' '{print $3}')
  16. if [[ $rday = $day ]]; then
  17. rm -r $i
  18. else
  19. day=$rday
  20. fi
  21. done
  22. # One backup per month for backups older than two weeks
  23. monthlies=$(find $backup -maxdepth 1 -type d -mtime +14 | sort)
  24. month=0
  25. for i in $monthlies; do
  26. rmonth=$(echo $i | awk -F '-' '{print $2}')
  27. if [[ $rmonth = $month ]]; then
  28. rm -r $i
  29. else
  30. month=$rmonth
  31. fi
  32. done