說明:以下是資料庫自動備份指令碼,可以儲存成.bat的方式,然後用計畫任務去定時執行。
::echo 資料庫開始備份!
@echo off
::定義磁碟
set disk=d
::定義單位名稱
set unit=jd_scjdj
::定義壓縮檔案路徑
set rar=c:\program files\winrar
::定義存放路徑
set filepath_ntdat=%disk%:\webserver\data_bak\ntdat
set filepath_ntcms=%disk%:\webserver\data_bak\ntcms_jd_scjdj
set filepath_ntlas=%disk%:\webserver\data_bak\ntlas_jd_sc
set filepath_ntlfs=%disk%:\webserver\data_bak\ntlfs_jd_sc
set filepath_ntpms=%disk%:\webserver\data_bak\ntpms_jd_sc
set filepath_ntrem=%disk%:\webserver\data_bak\ntrem_jd_sc
set filepath_pras=%disk%:\webserver\data_bak\pras
::定義檔案型別
set filetype=mysql
::定義時間格式
set datetime="%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%"
::定義檔名
set filename_ntdat=ntdat_%unit%-%filetype%-%datetime%
set filename_ntcms_jd_scjdj=ntcms_jd_scjdj_%unit%-%filetype%-%datetime%
set filename_ntlas_jd_sc=ntlas_jd_sc_%unit%-%filetype%-%datetime%
set filename_ntlfs_jd_sc=ntlfs_jd_sc_%unit%-%filetype%-%datetime%
set filename_ntpms_jd_sc=ntpms_jd_sc_%unit%-%filetype%-%datetime%
set filename_ntrem_jd_sc=ntrem_jd_sc_%unit%-%filetype%-%datetime%
set filename_pras=pras_%unit%-%filetype%-%datetime%
::判斷資料夾是否存在
if not exist %filepath_ntdat% md %filepath_ntdat%
if not exist %filepath_ntcms% md %filepath_ntcms%
if not exist %filepath_ntlas% md %filepath_ntlas%
if not exist %filepath_ntlfs% md %filepath_ntlfs%
if not exist %filepath_ntpms% md %filepath_ntpms%
if not exist %filepath_ntrem% md %filepath_ntrem%
if not exist %filepath_pras% md %filepath_pras%
::備份資料庫
cd /d "%disk%:\webserver\tools\mysql_5.6.26\bin"
mysqldump.exe --opt -u "root" --password="root" "ntdat" > "%filepath_ntdat%\ntdat.sql"
mysqldump.exe --opt -u "root" --password="root" "ntcms" > "%filepath_ntcms%\ntcms_jd_scjdj.sql"
mysqldump.exe --opt -u "root" --password="root" "ntlas" > "%filepath_ntlas%\ntlas_jd_sc.sql"
mysqldump.exe --opt -u "root" --password="root" "ntlfs" > "%filepath_ntlfs%\ntlfs_jd_sc.sql"
mysqldump.exe --opt -u "root" --password="root" "ntpms" > "%filepath_ntpms%\ntpms_jd_sc.sql"
mysqldump.exe --opt -u "root" --password="root" "ntrem" > "%filepath_ntrem%\ntrem_jd_sc.sql"
mysqldump.exe --opt -u "root" --password="root" "pras" > "%filepath_pras%\pras.sql"
::壓縮備份檔案
cd /d "%filepath_ntdat%"
"%rar%\winrar.exe" a "%filename_ntdat%.rar" "ntdat.sql"
del /q "ntdat.sql"
cd /d "%filepath_ntcms%"
"%rar%\winrar.exe" a "%filename_ntcms_jd_scjdj%.rar" "ntcms_jd_scjdj.sql"
del /q "ntcms_jd_scjdj.sql"
cd /d "%filepath_ntlas%"
"%rar%\winrar.exe" a "%filename_ntlas_jd_sc%.rar" "ntlas_jd_sc.sql"
del /q "ntlas_jd_sc.sql"
cd /d "%filepath_ntlfs%"
"%rar%\winrar.exe" a "%filename_ntlfs_jd_sc%.rar" "ntlfs_jd_sc.sql"
del /q "ntlfs_jd_sc.sql"
cd /d "%filepath_ntpms%"
"%rar%\winrar.exe" a "%filename_ntpms_jd_sc%.rar" "ntpms_jd_sc.sql"
del /q "ntpms_jd_sc.sql"
cd /d "%filepath_ntrem%"
"%rar%\winrar.exe" a "%filename_ntrem_jd_sc%.rar" "ntrem_jd_sc.sql"
del /q "ntrem_jd_sc.sql"
cd /d "%filepath_pras%"
"%rar%\winrar.exe" a "%filename_pras%.rar" "pras.sql"
del /q "pras.sql"
::echo 資料庫結束備份!
it達仁
mysql定時自動備份
假想環境 mysql 安裝位置 c mysql 論壇資料庫名稱為 bbs mysql root 密碼 123456 資料庫備份目的地 d db backup 程式 echo off c mysql bin mysqladmin u root password 123456 shutdown c my...
mysql定時備份指令碼 Mysql自動備份指令碼
我這裡要把mysql資料庫存放目錄 var lib mysql下面的pw85資料庫備份到 home mysql data裡面,並且儲存為mysqldata bak 2012 04 11.tar.gz的壓縮檔案格式 2012 04 11是指備份執行時當天的日期 最後只保留最近7天的備份。實現步驟 1 ...
定時備份mysql指令碼 每天自動備份mysql指令碼
下面是程式設計之家 jb51.cc 通過網路收集整理的 片段。1 執行 crontab e 00 00 bin bash yourpath mysqlbak.sh 2 開啟自動執行檔案 vi etc crontab 在etc中加入如下內容,讓其自動執行任務。00 00 root mysqlbak.s...