mysqldump 全表备份 sql

时间:2023-02-04 12:56:45


#!/bin/bash

time=`date +"%Y-%m-%d"`
bak_dir="/var/lib/mysql/bak"
ip="127.0.0.1"
port="3306"
user="root"
pwd="123456"

mkdir -p $bak_dir


echo "备份工作目录 ${bak_dir}"
echo "查看备份状态 cat ${bak_dir}/hint.txt"
echo "正在备份 $time-all.sql.gz" > ${bak_dir}/hint.txt
mysqldump -u $user -h $ip -p$pwd --all-databases | gzip > ${bak_dir}/$time-all.sql.gz

find ${bak_dir}/ -name "*.gz" -type f -mtime +15 | xargs rm -rf

echo "备份完成 $time-all.sql " > ${bak_dir}/hint.txt
echo "恢复命令 gunzip < ${bak_dir}/$time-all.sql.gz | mysql -u $user -h $ip -p$pwd" >> ${bak_dir}/hint.txt