写一个脚本
用于自动化备份MySQL数据库。
#!/bin/bash
#This script is used to backup the MySQL database automatically.
# Set MySQL user and password
MYSQL_USER="root"
MYSQL_PASSWORD="password"
# Set the backup directory path
BACKUP_DIR="/home/mysqlbackup" # Please create this directory manually before running this script.
DATE=`date +%Y-%m-%d` # Get the current date.
# Create a new directory using the current date in the backup directory for storing the current date backup.
mkdir -p $BACKUP_DIR/$DATE
# Backup all databases with mysqldump command.
mysqldump --user=$MYSQL_USER --password=$MYSQL_PASSWORD --all-databases > $BACKUP_DIR/$DATE/alldb-$DATE.sql
# Compress all databases backup file with gzip command.
gzip $BACKUP_DIR/$DATE/alldb-$DATE.sql
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!