How to Remove Files/Folder Older than X days in Windows using Command Prompt

Problem:

Often, we need to clean up files and folders that are older than x number of days before they eat up all the disk space.  So we need a script/command to delete the old files/folder.

Solution:

   1: @echo off

   2: :: set folder path

   3: set target_path=C:\Users\xxxx\AppData\Local\Temp

   4:  

   5: :: set min age of files and folders to delete

   6: set max_days=7

   7:  

   8: :: remove files from %target_path%

   9: forfiles -p %target_path% -m *.* -d -%max_days% -c "cmd  /c del /q @path"

  10:  

  11: :: remove sub directories from %dump_path%

  12: forfiles -p %target_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"

 

References:

https://www.howtogeek.com/131881/how-to-delete-files-older-than-x-days-on-windows/

https://elderec.org/2012/02/scripting-delete-files-and-folders-older-than-x-days/

Advertisements

SQL Connection Issue in AWS EC2 After Releasing Elastic IP

Background

We recently consolidated websites/servers hosted on AWS EC2. 

On ServerA, we released a couple of elastic IP address.  Using EC2 –> Networking –> Manage Private IP Addresses, I unassigned those orphaned private IPs.

Problem

After reboot, we found that ServerA can no longer connect to another SQL server.

Solution

It turns out that I forgot one thing.  We used to have those orphaned private IPs as static IPs, instead of DHCP on the ServerA OS network setting.  Thus, I removed those obsolete private IPs from network adapter setting IPv4.   

The lesson is that any extra obsolete private IPs on the server network setting could lead to SQL connection issues.