linux下備份MYSQL數據庫的辦法。本站提示廣大學習愛好者:(linux下備份MYSQL數據庫的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是linux下備份MYSQL數據庫的辦法正文
只需依照上面3步做,一切都在你的掌控之下:
第一步:在辦事器上設置裝備擺設備份目次代碼:
--------------------------------------------------------------------------------
mkdir /var/lib/mysqlbackup
cd /var/lib/mysqlbackup
--------------------------------------------------------------------------------
第二步:編寫備份劇本代碼:
--------------------------------------------------------------------------------
vi dbbackup.sh
--------------------------------------------------------------------------------
粘帖以下代碼,務必更改個中的username,password和dbname。
代碼:
--------------------------------------------------------------------------------
#!/bin/sh #Username to access the MySQL server USERNAME="username" # Username to access the MySQL server PASSWORD="password" # List of DBNAMES for Backup DBNAME="dbname" #date timestamp for log message DATE=`/bin/date +%Y-%m-%d_%Hh%Mm` #output file OUTDIR="/var/lib/mysqlbackup/" OUTFILE="ip_bindass".$DATE."sql.gz" #working directory DIR="/var/lib/mysqlbackup/"#cd $DIR # MySQL Backup /usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u$USERNAME -p$PASSWORD | /usr/bin/gzip -9 > $OUTDIR$OUTFILE
--------------------------------------------------------------------------------
更改備份劇本權限
代碼:
--------------------------------------------------------------------------------
chmod +x dbbackup.sh
--------------------------------------------------------------------------------
第三步:用crontab准時履行備份劇本代碼:
--------------------------------------------------------------------------------
crontab -e
--------------------------------------------------------------------------------
若天天下晝3點20備份,添加以下代碼,
代碼:
--------------------------------------------------------------------------------
20 15 * * * /var/lib/mysqlbackup/dbbackup.sh
--------------------------------------------------------------------------------
弄定!