Created
July 7, 2020 11:11
-
-
Save mwicat/133795ce8f87265245e8c1f380189d6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| innobackupx () | |
| { | |
| hostname="$1" | |
| echo "xbstream $hostname" | |
| xbstream_path="/database/xtrabackup/${hostname}-xtrabackup.xbstream-$(date -I)" | |
| log_path="/database/log/${hostname}-$(date -I).log" | |
| ssh "${hostname}" /usr/bin/innobackupex \ | |
| --defaults-file="/etc/mysql/my.cnf" \ | |
| --slave-info \ | |
| --socket /var/run/mysqld/mysqld.sock \ | |
| --throttle=100 \ | |
| --stream=xbstream \ | |
| /var/tmp/ > "${xbstream_path}" | |
| if [ -s "${xbstream_path}" ]; then | |
| # remove backups older than 2 days | |
| find /database/xtrabackup -name "${hostname}-xtrabackup.xbstream-*" -mtime +2 -exec rm {} \; | |
| # remove logs older than 30 days | |
| find /database/log -name "${hostname}-*.log" -mtime +30 -exec rm {} \; | |
| fi | |
| } | |
| innobackupx myhost1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment