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 921B

123456789101112131415161718192021222324252627282930313233343536
  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. mysqldump --single-transaction --password="${mysqlpw}" gazelle | gzip -c > $backup/$date/gazelle.sql.gz
  8. rm $backup/current
  9. ln -s $backup/$date $backup/current
  10. # One backup per day for backups older than 12 hours
  11. hourlies=$(find $backup -maxdepth 1 -type d -mmin +720 | sort)
  12. day=0
  13. for i in $hourlies; do
  14. rday=$(echo $i | awk -F '-' '{print $3}')
  15. if [[ $rday = $day ]]; then
  16. rm -r $i
  17. else
  18. day=$rday
  19. fi
  20. done
  21. # One backup per month for backups older than two weeks
  22. monthlies=$(find $backup -maxdepth 1 -type d -mtime +14 | sort)
  23. month=0
  24. for i in $monthlies; do
  25. rmonth=$(echo $i | awk -F '-' '{print $2}')
  26. if [[ $rmonth = $month ]]; then
  27. rm -r $i
  28. else
  29. month=$rmonth
  30. fi
  31. done