I want to delete ec2 snapshots that are older than 7 days. I can create a txt file of all available snapshots using ec2-describe-snapshots, but I'm having trouble pulling the old snapshots from that file.
Here is a typical line from the txt file:
SNAPSHOT snap-2031781c vol-e0b9c189 completed 2013-10-13T18:45:19+0000 100% 572608710214 100 Created
by CreateImage(i-72a6d046) for ami-eace57da from vol-e0b9c189
All of my systems are Windows 7/2008/2012. I tried using this script from another post without luck:
for /f "delims=" %%a in ('robocopy "%cd%" "%temp%" * /minage:7 /l /np /fp /njh /njs /ndl /ns^|findstr /riv /c:"^$" /c:"\aws\working\AllSnapShots.txt"') > c:\aws\working\Remove-Snaps.txt
Related
I made a batch script to find and compress and move backup with daily schedule:
#echo off
robocopy C:\TempBackup C:\TempBackup\X *.BAK* /w:0 /r:0 /np /fft /maxage:1 /maxlad:1
7z a -tzip X "X\*" -r
for /f "tokens=1-5 delims=/: " %%a in ('robocopy "|" . /njh ^| find ":"') do set "CURRDATE=%%a%%b%%c" & set "CURRTIME=%%d%%e"
RENAME X.zip X_%CURRDATE%%CURRTIME%.zip
move /y C:\TempBackup\*.zip C:\Daily_Backup
rd /q /s C:\TempBackup\X
del /q C:\Tempbackup\*.BAK*
:stop
This script has only one problem that I only find 1 compressed file for the current day in Daily_Backup folder instead of 1 file for each day that the script runs.
I have tried to delete the temp files and display the deleted file and read only file names.
The below code i used for deleting the files and displaying the read only files.
#echo off
cd %temp%
for /d %%D in (*) do rd /s /q "%%D"
del /f /q *
del /f /q
but for me after deleting the files it should list and display the deleted file names.i guess we have to create some object/variable and store the file names.
is there any option to get it stored the file names and get it later?
This will list your readonly files.
for /f tokens^=* %i in ('robocopy /l /e /xa:R %temp% "nothing ..//" /njh /ndl /ns /nc /pf /njs')do #echo %i
Try moving everything to a seperate folder first and then
dir /b /path/to/folder
to get the files you are able to delete and
dir /b %tmp%
to get the files you are unable to delete.
I safe some Files at my Local Drive(Laptop) and also have Files saved at my Network Storage at Work.
I want that both Folders have the same Files, If I create/delete or change an File in one Folder, the other Folder should get Updated when I use the BATCH.
It should use the newest Version on an Document.
So I tried it with ROBOCOPY Folder01 Folder02 /MIR /R:3 /W.20, it worked but only in one Way, from Folder01 to Folder02, so if I created an File in Folder02 and used the Batch, the File got deleted.
Then I tried to copy both Folders into one TEMP Folder and then copy the TEMP-Files to both Folders. I used
ROBOCOPY Folder01 TEMP /XO /E /R:3 /W:20
ROBOCOPY Folder02 TEMP /XO /E /R:3 /W:20
ROBOCOPY TEMP Folder01 /MIR /R:3 /W.20
ROBOCOPY TEMP Folder02 /MIR /R:3 /W.20
this was almost perfect, always the newest Document was used and everything was there, but when I delete a File from Folder01, which still exists in Folder02, it will come back next time I use my BATCH.
Sorry for my English
Greetings, Tobias
Try this solution provided by #Sachadee with Xcopy
:://Synchro.bat
:://SachaDee 2014
#echo off&cls
:: We set Folders to synchonized
set "Folders= C:\HackooTest E:\Backup\Folder1 E:\Backup\Folder2 E:\Backup\Folder3"
for %%a in (%Folders%) do (
for %%b in (%Folders%) do (
if not "%%a"=="%%b" (
set "VAR%%a%%b=%%a %%b"
)
)
)
for /f "tokens=2,3 delims== " %%a in ('set VAR') Do (
echo xcopy "%%a" "%%b" /E /D /C /Y /I
)
pause
I have a directory and there are about ~1000 files in there.
I want to get the file names which last updated since 7 days? And write this file names to another file.
I'm using windows 2012 and I want to do that with batch script. How may I do that?
UPDATE:
I tried
#echo off
setlocal enableextensions disabledelayedexpansion
set "folder=c:\some\where"
( for /f "tokens=*" %%a in ('
robocopy "%folder%" "%folder%" * /l /nocopy /is /maxage:7 /njh /njs /nc /ns /ndl
') do echo(%%a
) > outputFile.txt
However, I receive this error:
ERROR : No Destination Directory Specified.
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.
For more usage information run ROBOCOPY /?
**** /MIR can DELETE files as well as copy them !
#echo off
setlocal enableextensions disabledelayedexpansion
set "folder=c:\some\where"
( for /f "tokens=*" %%a in ('
robocopy "%folder%" "%folder%" * /l /nocopy /is /maxage:7 /njh /njs /nc /ns /ndl
') do echo(%%a
) > outputFile.txt
This uses robocopy command to retrieve the list of the required files. It will only list /l, without copying anything /nocopy, all the files, including those considered the same file /is, with a max age of 7 days /maxage:7, without headers /njh, summary /njs, file class /nc, size /ns or directory listing /ndl.
The output of the command will include some blank columns that are removed with the for loop.
Have a need where we need to delete zip files that exist under a specific folder at 100 days old. All other zip files in the other folders, we can delete that are 30 days old. This would be easy if the files were a specific name, unfortunately we can only do this by folder name.
In the end result we will be using one of these techniques with FORFILES as we don't have to do a lot of logic programming in script.
Searched and did find how to do this and works OK, but the processing of the script is very slow.. Pretty much at this point, everything in the "NOT" somefolder condition is what takes quite a while to complete. Have done this with VBScript and PowerShell, but really want to get back to Batch Scripting for this.
BAT script to search directory for folders that match an input name
and as dbenham admits, again this is very slow. Also, did not like the fact that it does not show all folders in the "not" condition for the ones it does not find
He also states, that if you want to do extensive file/folder searching redirecting to a output file, maybe the best solution
This does work, but does not show the "not found" or the folders it would list..
dir /s /a-d c:\windows\*system32* >nul && (echo found it) || (echo not found)
This works to find all folders with system32 on a drive
dir /b /ad /s "c:\system32"
This works to look for folders that DO HAVE system32 within the results which are pretty quick too
FOR /f "tokens=*" %%G IN ('dir /b /ad /s c:\ ^| findstr /I /C:"system32"') DO echo %%G
We want to show all folders that DO NOT HAVE system32 within and in testing and redirecting to result.txt file, it created a 11.9MB file and will take quite a while to complete especially on a whole drive
FOR /f "tokens=*" %%G IN ('dir /b /ad /s c:\ ^| findstr /I /V /C:"system32"') DO echo %%G
How do I search for the directory of a file given its name using a batch script?
Not quite sure about this one
for /r c:\ %%F in (system32) if exist "%%F" echo %%~dpF
Playing around we get
For /F %%A IN('dir /s /a-d "c:\windows\*system32*") do && (echo found it) || (echo not found)
Are there any other ideas or Suggestions out there?
This will search in c:\files and below, and delete zip files by the following criteria:
In the folder called Special folder it will delete them if they are 100 days or older
otherwise it will delete them if they are 30 days or older.
Any zip file in the folders below the Special folder will be deleted at 30 days and older.
Test it before use.
#echo off
for /r "c:\files" %%a in (*.zip) do (
for %%b in ("%%~dpa\.") do (
if /i "%%~nxb"=="Special folder" (
forfiles /p "%%~dpa." /m "%%~nxa" /d -100 /c "cmd /c del #path"
) else (
forfiles /p "%%~dpa." /m "%%~nxa" /d -30 /c "cmd /c del #path"
)
)
)
pause