写一个备份mysql数据库的shell脚本
时间: 2023-03-07 20:26:47 浏览: 127
基于xtrabackup的MySQL数据库备份及还原Shell脚本.zip
我可以给你一个写一个备份mysql数据库的shell脚本的示例:#!/bin/bash
# This script will backup all databases# Set the backup folder
BACKUP_DIR="/var/backups/mysql"# Set the date
NOW="$(date +'%Y-%m-%d-%H-%M-%S')"# Create the backup directory
mkdir -p $BACKUP_DIR/$NOW# Get the databases name
databases=`mysql -u <username> -p<password> -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`# Backup each database
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"
mysqldump -u <username> -p<password> --databases $db > $BACKUP_DIR/$NOW/$db.sql
fi
done
阅读全文