Advertisement
Guest User

Untitled

a guest
Sep 9th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. function Create-Zip
  2. {
  3.  
  4. Param
  5. (
  6. [Parameter(Mandatory=$true)]
  7.  
  8. $Folder
  9. )
  10.  
  11. Begin
  12. {
  13. $pathToZipExe = "$($Env:ProgramFiles)\7-Zip\7z.exe";
  14. }
  15. Process
  16. {
  17. $aZipfile = get-item "$($Folder.fullname)\*.bak"
  18.  
  19. foreach ($file in $aZipfile) {
  20.  
  21. $zippath = "$($file.directory)\$($file.basename).zip"
  22. $arguments = "a", "-tzip", "$zippath", "$($file.fullname)";
  23. & $pathToZipExe $arguments;
  24.  
  25. }
  26.  
  27.  
  28. }
  29. End
  30. {
  31. }
  32. }
  33.  
  34. function Check-BackupName {
  35.  
  36. Param
  37. (
  38. [Parameter(Mandatory=$true)]
  39.  
  40. $Folder
  41. )
  42.  
  43. $ifresult = $False
  44. $elseresult = $True
  45.  
  46. $zip = get-item "$($folder)\*.zip"
  47.  
  48. foreach ($i in $zip){
  49.  
  50. $testbakfile = (get-item "$($folder)\$($i.BaseName).bak")
  51.  
  52. if ($i.BaseName -eq $testbakfile.BaseName) {
  53.  
  54. $ifresult = "$True"
  55. }
  56.  
  57. else {$elseresult = "$False"}
  58.  
  59. }
  60.  
  61. if ($ifresult -and $elseresult) {Write-Output $True}
  62. else {Write-Output $False}
  63.  
  64.  
  65.  
  66. }
  67.  
  68. function Check-BackupSize {
  69.  
  70. Param
  71. (
  72. [Parameter(Mandatory=$true)]
  73.  
  74. $Folder
  75. )
  76.  
  77. $ifresult = $False
  78. $elseresult = $True
  79. "folder is $folder"
  80.  
  81. $zip = get-item "$($folder)\*.zip"
  82. "zip is $zip"
  83.  
  84. foreach ($i in $zip){
  85. "i is $i"
  86.  
  87. $testzipfile = (get-item "$($folder)\$($i.BaseName).zip")
  88.  
  89. if ($i.Length -gt 1MB) {
  90.  
  91. $ifresult = "$True"
  92. }
  93.  
  94. else {$elseresult = "$False"}
  95.  
  96. }
  97.  
  98. if ($ifresult -and $elseresult) {Write-Output $True}
  99. else {Write-Output $False}
  100.  
  101. }
  102.  
  103.  
  104. $folderlist = Get-Childitem "E:\DB BackupsTest" | Where-Object {$_.Psiscontainer}
  105.  
  106. foreach ($i in $folderlist){
  107.  
  108. Create-Zip -Folder $i
  109.  
  110. if (Check-BackupName -Folder $i) -and (Check-BackupSize -Folder $i) {
  111.  
  112. Move-Item $i\*.zip \\ias-cor-nas3\Backups
  113.  
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement