Creating batch script to keep a set number of items

Tom Waller

Estimable
Jan 14, 2015
20
0
4,570
3
Hi guys,

I need some help/guidance with a batch script I need to make.
We have 1 location where our Veeam backup, stores the daily backups. This consists of a weeks backup.
We also have a copy of these backups in another location run by a script I created in notepad (which works)

Is there any way a batch script can be created to limit the amount of backup files that enters that copy folder at one time like the previous backup location. We often have to go in and manually remove older backup files which aren't needed once every so often so a batch file would be useful.

Hope this makes sense..
Much appreciated

Thanks In advance
 

little_me

Estimable
May 9, 2015
152
0
4,910
57
not sure if you want to limit number of files or remove older than n days files.
In either case, you can google a LOT of examples, short and small.
https://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days/6149776#6149776
Code:
forfiles /p "v:" /s /m *.* /d -3 /c "cmd /c del @path"
You should do /d -3 (3 days earlier) This works fine for me. So all the complicated batches could be in the trash bin. Also forfiles don't support UNC paths, so make a network connection to a specific drive.
 

little_me

Estimable
May 9, 2015
152
0
4,910
57
not sure if you want to limit number of files or remove older than n days files.
In either case, you can google a LOT of examples, short and small.
https://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days/6149776#6149776
Code:
forfiles /p "v:" /s /m *.* /d -3 /c "cmd /c del @path"
You should do /d -3 (3 days earlier) This works fine for me. So all the complicated batches could be in the trash bin. Also forfiles don't support UNC paths, so make a network connection to a specific drive.
 

Tom Waller

Estimable
Jan 14, 2015
20
0
4,570
3
Ah legend, cheers mate, adjusted it slightly and just ran a test. Works as hoped!
 
Thread starter Similar threads Forum Replies Date
PepeTheDog Apps General Discussion 1
S Apps General Discussion 6
A Apps General Discussion 5
T Apps General Discussion 1
S Apps General Discussion 4
T Apps General Discussion 1
M Apps General Discussion 1
M Apps General Discussion 1
R Apps General Discussion 1
M Apps General Discussion 2
G Apps General Discussion 1
M Apps General Discussion 2
C Apps General Discussion 4
A Apps General Discussion 1
D Apps General Discussion 4
D Apps General Discussion 3
D Apps General Discussion 1
L Apps General Discussion 6
ntadmin101 Apps General Discussion 1
P Apps General Discussion 5

ASK THE COMMUNITY