Guest User

Untitled

a guest
Aug 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #!/bin/bash
  2. # How to use
  3. # my_script_name bd_user db_pass project_name(should be same name on database and project_directory)
  4. mysql_user=$1
  5. mysql_pass=$2
  6. project_name=$3
  7. suffix=$(date +%Y%m%d)
  8. last_day_on_month=$(cal `date '+%m'` `date '+%Y'` | grep . | fmt -1 | tail -1)
  9. today=$(date +%d)
  10. month_bkp=$(date +%Y-%B)
  11.  
  12. cd /home/deployer/bkps/
  13. mkdir mysql
  14. mysqldump --opt -u$mysql_user -p$mysql_pass -h 127.0.0.1 $project_name > mysql/$project_name.$suffix.sql
  15. tar -cvzf $project_name-db-$suffix.tar.gz mysql
  16. if [ $today -eq 29 ]; then
  17. cp $project_name-db-$suffix.tar.gz month/$project_name-db-$month_bkp.tar.gz
  18. fi
  19. rm -rf mysql
  20.  
  21. #remove files with more than 10 days
  22. find /home/deployer/bkps/ -ctime +10 -exec rm {} \;
Add Comment
Please, Sign In to add comment