Skip to content

Instantly share code, notes, and snippets.

@mwicat
Created July 7, 2020 11:11
Show Gist options
  • Select an option

  • Save mwicat/133795ce8f87265245e8c1f380189d6d to your computer and use it in GitHub Desktop.

Select an option

Save mwicat/133795ce8f87265245e8c1f380189d6d to your computer and use it in GitHub Desktop.
#!/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