#!/bin/bash # 备份目录和文件名 backup_dir=/var/backups/mysql backup_name=mysql_backup_$(date +%Y-%m-%d_%H-%M-%S) # MySQL 连接信息 mysql_user=root mysql_password=your_password # 备份命令 xtrabackup --backup --user=$mysql_user --password=$mysql_password --target-dir=$backup_dir/$backup_name # 压缩备份文件 tar -czvf $backup_dir/$backup_name.tar.gz $backup_dir/$backup_name # 传输备份文件到远程位置 rsync -avz $backup_dir/$backup_name.tar.gz user@remote_server:/remote_backup_dir #!/bin/bash # 备份文件名和目录 backup_name=mysql_backup_2023-04-13_10-30-00.tar.gz backup_dir=/var/backups/mysql # MySQL 数据目录 mysql_data_dir=/var/lib/mysql # 解压备份文件 tar -xzvf $backup_dir/$backup_name -C $backup_dir # 关闭 MySQL 服务 systemctl stop mysql # 恢复备份 xtrabackup --prepare --target-dir=$backup_dir/mysql_backup_2023-04-13_10-30-00 # 恢复完成后将备份数据拷贝到 MySQL 数据目录 rsync -av $backup_dir/mysql_backup_2023-04-13_10-30-00/* $mysql_data_dir/ # 修改备份数据目录的所有权和权限 chown -R mysql:mysql $mysql_data_dir chmod -R 700 $mysql_data_dir # 启动 MySQL 服务 systemctl start mysql
标签:name,--,恢复,备份,xtrabackup,mysql,backup,dir From: https://www.cnblogs.com/xietaiyang/p/17352653.html