Guest User

Untitled

a guest
Apr 3rd, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Copy-Stuff
  2.     {
  3.         param([string] $OldFileBasename,
  4.               [string] $DestinationDrive)  
  5.        
  6.         $CurrentFile = "${OldFileBasename}-" + $Date.ToString('yyyy-MM-dd') + $Extension
  7.        
  8.         Copy-Item -ErrorAction SilentlyContinue -Path $SourceDir\$OldOriginalName -Destination $DestinationDrive\database\backup\$CurrentFile
  9.  
  10.         if (-not $?)
  11.             {
  12.                 Add-Content C:\database\backup.log "`rError copying $BackupFolder\$OldOriginalName to $DestinationDrive\database\backup\$CurrentFile"
  13.             }
  14.         else
  15.             {
  16.                 Write-Host -Fore Green "Successfully copied $BackupFolder\$OldOriginalName to $DestinationDrive\database\backup\$CurrentFile"
  17.                 Add-Content C:\database\backup.log "`rBackup created $DestinationDrive\database\backup\$CurrentFile"
  18.             }
  19.         $OldDate = $Date - [timespan] '10.0:0:0'
  20.         $OldDateString = $OldDate.ToString('yyyy-MM-dd')
  21.         $FileToDelete = "$DestinationDrive\database\backup\${OldFileBasename}-${OldDateString}${Extension}"
  22.        
  23.         if (Test-Path -PathType Leaf $FileToDelete)
  24.             {
  25.              Remove-Item $FileToDelete
  26.              if (-not $?)
  27.                     {
  28.                         Add-Content C:\database\backup.log "`rFailed to delete $FileToDelete ($Date)"
  29.                     }
  30.        
  31.              else
  32.                 {
  33.                     Add-Content C:\database\backup.log "`rSuccessfully deleted $FileToDelete ($Date)"
  34.                     Write-Host -Fore Green "Successfully deleted $FileToDelete"
  35.                 }
  36.             }
  37.         else
  38.             {
  39.                 Add-Content C:\database\backup.log "`rFile not found $FileToDelete ($Date)"
  40.                
  41.                 Write-Host -Fore red "Did not find a 10 days old backup (looked for '$FileToDelete')"
  42.             }
  43.     }
  44.  
  45. Set-StrictMode -Version Latest
  46. $ErrorActionPreference = 'Stop'
  47. $Log = 'C:\database\backup.log'
  48. $SourceDir    = 'C:\Database'
  49. $BackupFolder = 'C:\Database\database_backup'
  50. $Date         = Get-Date
  51. $Extension    = '.accdb'
  52. $OldOriginalName = 'MainDataStore.accdb'
  53. Copy-Stuff 'MainDataStore' 'C:'
  54. Copy-Stuff 'MainDataStore' 'B:'
  55. Copy-Stuff 'MainDataStore' 'E:'
  56. $OldOriginalName = 'MainDataStore_be.accdb'
  57. Copy-Stuff 'MainDataStore_be' 'C:'
  58. Copy-Stuff 'MainDataStore_be' 'B:'
  59. Copy-Stuff 'MainDataStore_be' 'E:'
Advertisement
Add Comment
Please, Sign In to add comment