Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This batch file uses powershell to get yesterdays date.</p> <pre><code>@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 </code></pre> <p>Here is a VBS batch script to calculate different days. You can change the -1 to 0 for today, or -100 for 100 days ago, or +200 for 200 days from now, etc.</p> <pre><code>@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%"&gt;"%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"&gt;"%EC2_HOME%\Working\ActiveVolumes.txt" echo :: Create a file with all instances pause pause call ec2-describe-instances|find /i "TAG"|find /i "Name"&gt;"%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 &gt;"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%) echo&gt;&gt;"%temp%\%~n0.vbs" d=weekday(s) echo&gt;&gt;"%temp%\%~n0.vbs" WScript.Echo year(s)^&amp;_ echo&gt;&gt;"%temp%\%~n0.vbs" right(100+month(s),2)^&amp;_ echo&gt;&gt;"%temp%\%~n0.vbs" right(100+day(s),2)^&amp;_ echo&gt;&gt;"%temp%\%~n0.vbs" d for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a del "%temp%\%~n0.vbs" endlocal&amp; ( 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%" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload