Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # How to use
- # my_script_name bd_user db_pass project_name(should be same name on database and project_directory)
- mysql_user=$1
- mysql_pass=$2
- project_name=$3
- suffix=$(date +%Y%m%d)
- last_day_on_month=$(cal `date '+%m'` `date '+%Y'` | grep . | fmt -1 | tail -1)
- today=$(date +%d)
- month_bkp=$(date +%Y-%B)
- cd /home/deployer/bkps/
- mkdir mysql
- mysqldump --opt -u$mysql_user -p$mysql_pass -h 127.0.0.1 $project_name > mysql/$project_name.$suffix.sql
- tar -cvzf $project_name-db-$suffix.tar.gz mysql
- if [ $today -eq 29 ]; then
- cp $project_name-db-$suffix.tar.gz month/$project_name-db-$month_bkp.tar.gz
- fi
- rm -rf mysql
- #remove files with more than 10 days
- find /home/deployer/bkps/ -ctime +10 -exec rm {} \;
Add Comment
Please, Sign In to add comment