2019-03-28-脚本

#!/bin/bash
BACKUP_HOST="localhost"
BACKUP_USER="root"
BACKUP_PASS="123456"
BACKUP_DIR="/backup/mysql"
BACKUP_DBNAME="one two three"
COPIES=10
MYSQLDUMP="mysqldump"
TIMEPOINT=$(date +%Y-%m-%d)
MYSQLDUMP_OPTS="-h $BACKUP_HOST -u$BACKUP_USER -p$BACKUP_PASS"
umask 0077
test ! -d "$BACKUP_DIR" && mkdir -p "$BACKUP_DIR"
test ! -w $BACKUP_DIR && echo "Error: $BACKUP_DIR is un-writeable." && exit 0
for dbname in $BACKUP_DBNAME
do
   test ! -d "$BACKUP_DIR/$dbname" && mkdir -p "$BACKUP_DIR/$dbname"
   $MYSQLDUMP $MYSQLDUMP_OPTS $dbname | gzip > $BACKUP_DIR/$dbname/$dbname.$TIMEPOINT.sql.gz
done
find $BACKUP_DIR -type f -mtime +$COPIES -delete

你可能感兴趣的:(2019-03-28-脚本)