log rotate and archive with windows

I support a few applications which run on windows and there isn’t really any great way of rotating the logs like there is with linux. While the logs are all configured to go to off host log solutions such as Azure logs or elasticsearch I like to keep the local logs around for a period of time as well. Depending on your rules some fidelity or information may be lost when the logs are ingested into these solutions. I have tried using some of the built-in compression functionality with windows but some of the log files are so large they generate out of memory errors. I have found 7zip to be the best tool for these large files. The compression rate and performance is better.

One such application where I want to compress all logs older than 7 days and then keep for 90 days is bitvise.

You must install 7zip on the computer first, but then you can run the script below on demand or on a schedule. e.g. every night or weekend.

#Get all log files older than 7 days and compress to archive then delete source
cd “C:\Program Files\Bitvise SSH Server\Logs”
foreach ($file in Get-ChildItem -Filter *.log -Path “C:\Program Files\Bitvise SSH Server\Logs” | Where-Object { $_.LastWriteTime -lt (get-date).AddDays(-7)})
{
& “C:\Program Files\7-Zip\7z.exe” -sdel -mx=5 a “$file`.7z” “$file”
}

#Get all old 7zip archives and delete when older than 90 days
Get-ChildItem -Filter *.7z -Path “C:\Program Files\Bitvise SSH Server\Logs” | Where-Object { $_.LastWriteTime -lt (get-date).AddDays(-90)} | Remove-Item -Force -Verbose

how to grow a Hyper-V cluster shared volume CSV

how to grow a Hyper-V cluster shared volume, this can be run live and online.

1. You need to grow the parent disk. Normally this will be on a SAN. I wont put detailed steps here since it varies depending on your hardware but normally this is a simple process. Please note if your volume has 4k sectors you wont be able to grow larger than 16TB.

2. Load failover cluster manager and find out which node owns the disk. The disk probably already shows the larger size but the volume itself will still be the smaller size. Connect to the CSV owner.

3. Start an admin CMD window and run diskpart.

4. type “List volume” to list all volumes and find the one you want to grow:

DISKPART> list volume

Volume ### Ltr Label Fs Type Size Status Info
———- — ———– —– ———- ——- ——— ——–
Volume 0 System Rese NTFS Partition 350 MB Healthy System
Volume 1 C NTFS Partition 110 GB Healthy Boot
Volume 2 CSVFS Partition 4095 GB Healthy
C:\ClusterStorage\Volume4\
Volume 3 CSVFS Partition 5119 GB Healthy
C:\ClusterStorage\Volume5\
Volume 4 CSVFS Partition 5119 GB Healthy
C:\ClusterStorage\Volume6\
Volume 5 CSVFS Partition 9 TB Healthy
C:\ClusterStorage\Volume1\
5. type “Select volume x” where x is the volume you want to grow. in our case this is volume 5.
DISKPART> select volume 5

Volume 5 is the selected volume.
6. Type “extend” and press enter to grow the volume. You can then list the volumes again to check the size or verify in failover cluster manager.
DISKPART> extend

DiskPart successfully extended the volume.

DISKPART> list volume

Volume ### Ltr Label Fs Type Size Status Info
———- — ———– —– ———- ——- ——— ——–
Volume 0 System Rese NTFS Partition 350 MB Healthy System
Volume 1 C NTFS Partition 110 GB Healthy Boot
Volume 2 CSVFS Partition 4095 GB Healthy
C:\ClusterStorage\Volume4\
Volume 3 CSVFS Partition 5119 GB Healthy
C:\ClusterStorage\Volume5\
Volume 4 CSVFS Partition 5119 GB Healthy
C:\ClusterStorage\Volume6\
* Volume 5 CSVFS Partition 14 TB Healthy
C:\ClusterStorage\Volume1\

DISKPART>
7. Enjoy all the extra space.