Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backup_parent_dir="/Applications/MAMP/htdocs/test"
- mysql_user="root"
- mysql_password="root"
- db_name="cms"
- db_port="8889"
- days=3
- excluded_tables=(
- log
- )
- mysql_executable_folder="/Applications/MAMP/Library/bin"
- echo exit | ${mysql_executable_folder}/mysql -P $db_port --user=$mysql_user --password=$mysql_password -B 2>/dev/null
- if [ "$?" -gt 0 ]; then
- exit 1
- fi
- ignored_tables_as_string=''
- for table in "${excluded_tables[@]}"
- do :
- ignored_tables_as_string+=" --ignore-table=${db_name}.${table}"
- done
- backup_date=`date +%Y_%m_%d_%H_%M`
- backup_dir="${backup_parent_dir}/${backup_date}"
- mkdir -p "${backup_dir}"
- chmod 700 "${backup_dir}"
- ${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"
- chmod 600 "${backup_dir}/$db_name.sql.gz"
- find $backup_parent_dir/* -type d -mtime +$days -exec rm -rf {} \;
Add Comment
Please, Sign In to add comment