Guest User

Untitled

a guest
Aug 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # How to use
  4. # my_script_name bd_user db_pass project_name(should be same name on database and project_directory)
  5. # by Alfredo Ribeiro: alfredo@aatecnologia.com.br
  6. # Create the daily backup, delete old backups, and each month, make a copy last backup on a separated directory
  7. # Is need create a directory month inside your backup directory
  8.  
  9. mysql_user=$1
  10. mysql_pass=$2
  11. project_name=$3
  12.  
  13. suffix=$(date +%Y%m%d)
  14. last_day_on_month=$(cal `date '+%m'` `date '+%Y'` | grep . | fmt -1 | tail -1)
  15. today=$(date +%d)
  16. month_bkp=$(date +%Y-%B)
  17. host=127.0.0.1
  18.  
  19. if [ ! -d /tmp/mysql ]; then
  20. mkdir /tmp/mysql
  21. fi
  22.  
  23. if [ -d /home/user/bkps/month ]; then
  24. mkdir -p /home/user/bkps/month
  25. fi
  26.  
  27. mysqldump --opt -u$mysql_user -p$mysql_pass -h $host $project_name > /tmp/mysql/$project_name.$suffix.sql
  28. tar -cvzf /tmp/$project_name-db-$suffix.tar.gz /tmp/mysql
  29. if [ $today -eq $last_day_on_month ]; then
  30. mv /tmp/$project_name-db-$suffix.tar.gz month/$project_name-db-$month_bkp.tar.gz
  31. fi
  32.  
  33. rm -rf /tmp/mysql
  34.  
  35. #remove files with more than 10 days
  36. find /home/user/bkps/ -ctime +10 -exec rm -rf {} \;
Add Comment
Please, Sign In to add comment