Created
January 5, 2026 15:41
-
-
Save abra-chan/27e803fdab97eee7e58736b15cb6f127 to your computer and use it in GitHub Desktop.
VOD Backup Script for Windows (PowerShell)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define paths | |
| $SourceDir = "C:\Users\example\Desktop\stream\edited" | |
| $DestDir = "Z:\External Storage\Seagate\content" | |
| $EmailTo = "example@gmail.com" | |
| $SmtpServer = "smtp.gmail.com" # Replace with your SMTP server | |
| $EmailFrom = "example-noreply@gmail.com" # Replace with your from email | |
| $Credentials = New-Object System.Management.Automation.PSCredential("username", (ConvertTo-SecureString "password" -AsPlainText -Force)) # Replace with SMTP credentials if needed | |
| # Check if the NAS volume is mounted (assuming mounted as Z:\) | |
| if (-not (Test-Path "Z:\")) { | |
| $Subject = "Error: NAS Volume Not Mounted" | |
| $Body = "The NAS volume is not mounted." | |
| Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $Subject -Body $Body -SmtpServer $SmtpServer -Credential $Credentials -UseSsl | |
| exit 1 | |
| } | |
| # Loop through files in the source directory | |
| Get-ChildItem -Path $SourceDir -File | ForEach-Object { | |
| $File = $_ | |
| $Basename = $File.Name | |
| $DestFile = Join-Path $DestDir $Basename | |
| # Copy the file | |
| try { | |
| Copy-Item -Path $File.FullName -Destination $DestFile -ErrorAction Stop | |
| } catch { | |
| $Subject = "Error: File Copy Failed" | |
| $Body = "Failed to copy $($File.FullName) to $DestFile." | |
| Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $Subject -Body $Body -SmtpServer $SmtpServer -Credential $Credentials -UseSsl | |
| continue | |
| } | |
| # Compute MD5 checksums | |
| $SrcHash = (Get-FileHash -Path $File.FullName -Algorithm MD5).Hash | |
| $DestHash = (Get-FileHash -Path $DestFile -Algorithm MD5).Hash | |
| # Verify checksums | |
| if ($SrcHash -eq $DestHash -and $SrcHash -ne $null) { | |
| # Delete original if verification succeeds | |
| try { | |
| Remove-Item -Path $File.FullName -ErrorAction Stop | |
| } catch { | |
| $Subject = "Error: File Deletion Failed" | |
| $Body = "Failed to delete $($File.FullName) after successful copy." | |
| Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $Subject -Body $Body -SmtpServer $SmtpServer -Credential $Credentials -UseSsl | |
| } | |
| } else { | |
| $Subject = "Error: MD5 Checksum Mismatch" | |
| $Body = "MD5 checksum mismatch for $($File.FullName)." | |
| Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $Subject -Body $Body -SmtpServer $SmtpServer -Credential $Credentials -UseSsl | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment