Guest User

Untitled

a guest
Sep 2nd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. backup_parent_dir="/Applications/MAMP/htdocs/test"
  2. mysql_user="root"
  3. mysql_password="root"
  4. db_name="cms"
  5. db_port="8889"
  6. days=3
  7. excluded_tables=(
  8. log
  9. )
  10. mysql_executable_folder="/Applications/MAMP/Library/bin"
  11.  
  12. echo exit | ${mysql_executable_folder}/mysql -P $db_port --user=$mysql_user --password=$mysql_password -B 2>/dev/null
  13. if [ "$?" -gt 0 ]; then
  14. exit 1
  15. fi
  16.  
  17. ignored_tables_as_string=''
  18. for table in "${excluded_tables[@]}"
  19. do :
  20. ignored_tables_as_string+=" --ignore-table=${db_name}.${table}"
  21. done
  22.  
  23. backup_date=`date +%Y_%m_%d_%H_%M`
  24. backup_dir="${backup_parent_dir}/${backup_date}"
  25. mkdir -p "${backup_dir}"
  26. chmod 700 "${backup_dir}"
  27.  
  28. ${mysql_executable_folder}/mysqldump -P $db_port --user=$mysql_user --password=$mysql_password ${ignored_tables_as_string} $db_name | gzip -9 > "${backup_dir}/$db_name.sql.gz"
  29. chmod 600 "${backup_dir}/$db_name.sql.gz"
  30.  
  31. find $backup_parent_dir/* -type d -mtime +$days -exec rm -rf {} \;
Add Comment
Please, Sign In to add comment