我有一个批处理文件,其中包含以下内容:
set m=%date:~-7,2%
set /A m -= 1
set DATE_DIR=%date:~-10,2%-%m%-%date:~-4,4%
echo 'DATE_DIR'
![enter image description here][1]
:: First delete all snapshots from this day last week
:: Create a file with all scheduled snapshots
ec2-describe-snapshots|find /i "%DATE_DIR%: Daily Backup for"
我已将DATE_DIR参数设置为昨天的日期,因此ec2-describe语句应该获取昨天创建的快照,但它正在获取当天的数据!!
任何领导都表示赞赏。
由于
答案 0 :(得分:2)
此批处理文件使用powershell来获取昨天的日期。
@echo Off
:: change -1 to 0 for todays date.
for /f "delims=" %%a in ('"powershell get-date((get-date).addDays(-1)) -uformat "%%Y%%m%%d" "') do set "d8=%%a"
echo yesterday was %d8%
pause
这是一个用于计算不同日期的VBS批处理脚本。您可以将今天的-1更改为0,或者100天前更改为-100,或者从现在开始将200更改为200,等等。
@echo off
call :routine today -1
set "date_dir=%yy%-%mm%-%dd%"
echo '%DATE_DIR%'
echo :: First delete all snapshots from this day last week
echo :: Create a file with all scheduled snapshots
pause
pause
call ec2-describe-snapshots|find /i "%DATE_DIR%">"%EC2_HOME%\Working\SnapshotsDOW.txt"
echo :: Delete snapshots for older backups
pause
pause
for /F "tokens=2" %%i in ('type "%EC2_HOME%\Working\SnapshotsDOW.txt" ') do call ec2-delete-snapshot "%%i"
:: Now create a snapshot for every attached volume to every instance
:: Create a file with all attached volumes
::call ec2-describe-volumes|find /i "attached">"%EC2_HOME%\Working\ActiveVolumes.txt"
echo :: Create a file with all instances
pause
pause
call ec2-describe-instances|find /i "TAG"|find /i "Name">"%EC2_HOME%\Working\InstanceNames.txt"
echo :: Create snapshots of all attached volumes
pause
pause
for /F "tokens=2,3" %%d IN (' type "%EC2_HOME%\Working\ActiveVolumes.txt" ') do for /F "tokens=3,5*" %%a IN (' type "%EC2_HOME%\Working\InstanceNames.txt" ') do if %%a EQU %%e call ec2-create-snapshot "%%d" -d "%DATE_DIR%: Daily Backup for %%b (VolID:%%d InstID:%%e)"
echo Done
pause
goto :EOF
:routine
setlocal
set date1=%1
set qty=%2
set separator=%~3
if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)^&_
echo>>"%temp%\%~n0.vbs" d
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& (
set "YY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "daynum=%result:~-1%"
)
set "day=%YY%%separator%%MM%%separator%%DD%"