做個備忘錄
rem ******MySQL backup start******
@echo off
::設(shè)置時間變量
::set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%"
::set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%"
::set "Ymd=%date:~0,4%%date:~5,2%"
::set "today=%date:~0,4%/%date:~5,2%/%date:~8,2%"
::數(shù)據(jù)庫名
set "db=ht_go_v2_dev"
::保存的文件名,不含后綴
set "filename=ht_go_v2_dev"
::執(zhí)行備份操作
::D:\phpstudy_pro\Extensions\MySQL5.7.26\bin\mysqldump --user=dev --password=dev2021 --host=192.168.7.3 --protocol=tcp --port=3306 --default-character-set=utf8 --single-transaction=TRUE --routines --events "ht_go_v2_dev" > mysql_backup_%Ymd%.sql
D:\phpstudy_pro\Extensions\MySQL5.7.26\bin\mysqldump --user=dev --password=dev2021 --host=192.168.7.3 --protocol=tcp --port=3306 --default-character-set=utf8 --single-transaction=TRUE --routines --events %db% > %filename%.sql
::刪除一周前的備份數(shù)據(jù)
::forfiles /p "D:\WWW\mysql_backup" /s /m mysql_backup_*.sql /d -7 /c "cmd /c del @path"
::forfiles /s /m mysql_backup_*.sql /d -1 /c "cmd /c del @path"
:: pause
@echo on
rem ******MySQL backup end******