debian mysql 定時自動備份的指令碼

2021-06-23 03:12:45 字數 1020 閱讀 1363

#!/bin/sh

log=/var/log/mysql-backup.log

# mysql db info

user_root=******

user_pwd=******x

# mysql data stored dir

today=`date +%f`

storedir=/mnt/tf-card/mysql-back/$today

mkdir $storedir

echo "*** path:$storedir mysql-backup ***" >> $log

# delete overtime backup files

rm -rf /mnt/tf-card/mysql-back/$(date +%f --date='15 days ago')

# backup mysql data file

mysqldump -u$user_root --password=$user_pwd --databases my_yd_net --lock-all-tables --flush-logs |gzip>$storedir/my_yd_net.sql.gz

建立指令碼:nano /etc/cron.daily/mysql-backup

增加執行許可權:chmod +x /etc/cron.daily/mysql-backup

建立備份檔案根目錄:mkdir /mnt/tf-card/mysql-back/

解釋:此指令碼每天會生成乙個備份目錄,/mnt/tf-card/mysql-back/yyyy-mm-dd/***x.sql.gz,並持保留15天內的資料,並對匯出的sql檔案用gzip壓縮

目錄可自行修改,mysql的連線帳號user_root與user_pwd自行修改;

「# backup mysql data file」這個部分的語句下面可以新增多條 mysqldump 備份語句,一次備份多個庫。

對於超過15天的資料處理:每天會嘗試刪除一次第15天前的乙個檔案。

debian mysql 定時自己主動備份的指令碼

bin sh log var log mysql backup.log mysql db info user root user pwd x mysql data stored dir today date f storedir mnt tf card mysql back today mkdir ...

debian mysql 允許外部鏈結方法

1 modify the etc mysql my.cnf instead of skip networking the default is now to listen only on localhost which is more compatible and is not less secur...

mysql定時自動備份

假想環境 mysql 安裝位置 c mysql 論壇資料庫名稱為 bbs mysql root 密碼 123456 資料庫備份目的地 d db backup 程式 echo off c mysql bin mysqladmin u root password 123456 shutdown c my...