start mysqlbackup installer
commit
76818f9c1e
|
@ -0,0 +1 @@
|
|||
.DS_Store
|
|
@ -0,0 +1,2 @@
|
|||
# backup mysql just before midnight snaps
|
||||
50 23 * * * root /usr/local/bin/mysqlbackup
|
|
@ -0,0 +1,7 @@
|
|||
[client]
|
||||
user=root
|
||||
password=
|
||||
|
||||
[mysqldump]
|
||||
user=root
|
||||
password=
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh
|
||||
|
||||
cp mysqlbackup /usr/local/bin/
|
||||
chmod 755 /usr/local/bin/mysqlbackup
|
||||
|
||||
if [ ! -f /root/.my.cnf ]; then
|
||||
read -s -p "Enter the root MySQL Password: " MYSQL_PASS;
|
||||
cat <<EOF >> /tmp/.my.cfg
|
||||
[client]
|
||||
user=root
|
||||
password=${MYSQL_PASS}
|
||||
|
||||
[mysqldump]
|
||||
user=root
|
||||
password=${MYSQL_PASS}
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ ! -e /var/backup/mysql ]; then
|
||||
mkdir -p /var/backup/mysql
|
||||
fi
|
||||
|
||||
if ! grep mysqlbackup /etc/crontab > /dev/null; then
|
||||
cat crontab.in >> /etc/crontab
|
||||
fi
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script will backup all mysql databases into
|
||||
# compressed file named after date, ie: /var/backup/mysql/2016-07-13.tar.gz
|
||||
|
||||
# Setup variables used later
|
||||
|
||||
# Create date suffix with "F"ull date format
|
||||
suffix=$(date +%F)
|
||||
# Retrieve all database names except information schemas.
|
||||
dbs=$(/usr/local/bin/mysql --defaults-extra-file=/root/.my.cnf --batch --skip-column-names -e "SHOW DATABASES;" | grep -E -v "(information|performance)_schema")
|
||||
# Create temporary directory with "-d" option
|
||||
tmp=$(mktemp -d)
|
||||
# Set output dir here. /var/backups/ is used by system,
|
||||
# so intentionally used /var/backup/ for user backups.
|
||||
outDir="/var/backup/mysql"
|
||||
# Create output file name
|
||||
out="$outDir/$suffix.tar.gz"
|
||||
|
||||
# Actual script
|
||||
|
||||
# Check if output directory exists
|
||||
if [ ! -d "$outDir" ];then
|
||||
# Create directory with parent ("-p" option) directories
|
||||
mkdir -p "$outDir"
|
||||
fi
|
||||
|
||||
# Loop through all databases
|
||||
for db in $dbs; do
|
||||
# Dump database to temporary directory with file name same as database name + sql suffix
|
||||
/usr/local/bin/mysqldump --defaults-extra-file=/root/.my.cnf --events --triggers --routines --set-gtid-purged=OFF --databases "$db" > "$tmp/$db.sql"
|
||||
done
|
||||
|
||||
# Go to tmp dir
|
||||
cd $tmp
|
||||
|
||||
# Compress all dumps with gzip, discard any output to /dev/null
|
||||
tar -zcf "$out" * > "/dev/null"
|
||||
|
||||
# Cleanup
|
||||
cd "/tmp/"
|
||||
rm -rf "$tmp"
|
||||
|
Loading…
Reference in New Issue