Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Copy-Stuff
- {
- param([string] $OldFileBasename,
- [string] $DestinationDrive)
- $CurrentFile = "${OldFileBasename}-" + $Date.ToString('yyyy-MM-dd') + $Extension
- Copy-Item -ErrorAction SilentlyContinue -Path $SourceDir\$OldOriginalName -Destination $DestinationDrive\database\backup\$CurrentFile
- if (-not $?)
- {
- Add-Content C:\database\backup.log "`rError copying $BackupFolder\$OldOriginalName to $DestinationDrive\database\backup\$CurrentFile"
- }
- else
- {
- Write-Host -Fore Green "Successfully copied $BackupFolder\$OldOriginalName to $DestinationDrive\database\backup\$CurrentFile"
- Add-Content C:\database\backup.log "`rBackup created $DestinationDrive\database\backup\$CurrentFile"
- }
- $OldDate = $Date - [timespan] '10.0:0:0'
- $OldDateString = $OldDate.ToString('yyyy-MM-dd')
- $FileToDelete = "$DestinationDrive\database\backup\${OldFileBasename}-${OldDateString}${Extension}"
- if (Test-Path -PathType Leaf $FileToDelete)
- {
- Remove-Item $FileToDelete
- if (-not $?)
- {
- Add-Content C:\database\backup.log "`rFailed to delete $FileToDelete ($Date)"
- }
- else
- {
- Add-Content C:\database\backup.log "`rSuccessfully deleted $FileToDelete ($Date)"
- Write-Host -Fore Green "Successfully deleted $FileToDelete"
- }
- }
- else
- {
- Add-Content C:\database\backup.log "`rFile not found $FileToDelete ($Date)"
- Write-Host -Fore red "Did not find a 10 days old backup (looked for '$FileToDelete')"
- }
- }
- Set-StrictMode -Version Latest
- $ErrorActionPreference = 'Stop'
- $Log = 'C:\database\backup.log'
- $SourceDir = 'C:\Database'
- $BackupFolder = 'C:\Database\database_backup'
- $Date = Get-Date
- $Extension = '.accdb'
- $OldOriginalName = 'MainDataStore.accdb'
- Copy-Stuff 'MainDataStore' 'C:'
- Copy-Stuff 'MainDataStore' 'B:'
- Copy-Stuff 'MainDataStore' 'E:'
- $OldOriginalName = 'MainDataStore_be.accdb'
- Copy-Stuff 'MainDataStore_be' 'C:'
- Copy-Stuff 'MainDataStore_be' 'B:'
- Copy-Stuff 'MainDataStore_be' 'E:'
Advertisement
Add Comment
Please, Sign In to add comment