有人可以向我解释这个备份脚本吗?

时间:2022-05-08 01:27:52

I have a batch file for making a backup of my mysqldump, this works. But I don't understand the code. can someone, explain this to me.

我有一个批处理文件用于备份我的mysqldump,这是有效的。但我不明白代码。谁可以给我解释一下这个。

for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i

for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i

for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i
for /f %%i in ('time /t') do set DATE_TIME=%%i
for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i

:: here i make my backup 
"C:\Program Files\xampp\mysql\bin\mysqldump" -u root mamzel > "C:\Program Files\xampp\mysql\bin\%DATE_DAY%_%DATE_TIME%_mamzel10.sql"
at /delete /yes

at 09:00 /every:maandag,woensdag,donderdag d:\mysqlBackup.bat

Thanks in advance!

提前致谢!

1 个解决方案

#1


3  

for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i
for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i

If in the U.S. time format, date /t outputs the date as Wed 02/01/2012 A token (without delims specified) will separate that output using spaces as the delimiting factor. So token 1=Wed and token 2=02/01/2012. So you are assigning DATE_DOW=Wed and DATE_DAY=02/01/2012. Seeing as the days aren't in English, it's probably formated as year/month/day.

如果采用美国时间格式,则日期/ t输出日期为Wed 02/01/2012。令牌(未指定delims)将使用空格作为分隔因子来分隔该输出。令牌1 =星期三,令牌2 = 02/01/2012。所以你指定的是DATE_DOW = Wed和DATE_DAY = 02/01/2012。看到日子不是英文,它可能形成为年/月/日。

for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i

This strips the / from the date and replacing it with -, so your output is 02-01-2012 as opposed to 02/01/2012

这样剥离日期并将其替换为 - ,因此您的输出是02-01-2012而不是02/01/2012

for /f %%i in ('time /t') do set DATE_TIME=%%i
for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i

This does the same thing as the first part, except its grabbing the time format. The second line replaces the colons : with dashes -.

除了抓住时间格式之外,这与第一部分完全相同。第二行替换冒号:用破折号 - 。

"C:\Program Files\xampp\mysql\bin\mysqldump" -u root mamzel > "C:\Program Files\xampp\mysql\bin\%DATE_DAY%_%DATE_TIME%_mamzel10.sql"

This then uses your new date and time formats to dump it to a timestamped dump file.

然后,它使用新的日期和时间格式将其转储到带时间戳的转储文件。

#1


3  

for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i
for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i

If in the U.S. time format, date /t outputs the date as Wed 02/01/2012 A token (without delims specified) will separate that output using spaces as the delimiting factor. So token 1=Wed and token 2=02/01/2012. So you are assigning DATE_DOW=Wed and DATE_DAY=02/01/2012. Seeing as the days aren't in English, it's probably formated as year/month/day.

如果采用美国时间格式,则日期/ t输出日期为Wed 02/01/2012。令牌(未指定delims)将使用空格作为分隔因子来分隔该输出。令牌1 =星期三,令牌2 = 02/01/2012。所以你指定的是DATE_DOW = Wed和DATE_DAY = 02/01/2012。看到日子不是英文,它可能形成为年/月/日。

for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i

This strips the / from the date and replacing it with -, so your output is 02-01-2012 as opposed to 02/01/2012

这样剥离日期并将其替换为 - ,因此您的输出是02-01-2012而不是02/01/2012

for /f %%i in ('time /t') do set DATE_TIME=%%i
for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i

This does the same thing as the first part, except its grabbing the time format. The second line replaces the colons : with dashes -.

除了抓住时间格式之外,这与第一部分完全相同。第二行替换冒号:用破折号 - 。

"C:\Program Files\xampp\mysql\bin\mysqldump" -u root mamzel > "C:\Program Files\xampp\mysql\bin\%DATE_DAY%_%DATE_TIME%_mamzel10.sql"

This then uses your new date and time formats to dump it to a timestamped dump file.

然后,它使用新的日期和时间格式将其转储到带时间戳的转储文件。