From d663654d252f5586ae4391216bc7e6627d74607a Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Fri, 27 Apr 2018 12:53:33 -0400 Subject: [PATCH 01/28] Update README.md --- README.md | 60 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index b765965..92cf816 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,3 @@ - -**DO NOT USE:** Version 2.0 is in progress and will install and work much better. -- -- -- -- -- -- - # PowerShell-Backup-Script https://github.com/mpb10/PowerShell-Backup-Script @@ -15,9 +6,10 @@ A PowerShell script used to backup files. **Author: Matt Bittner** -**June 23th, 2017** +**April 27th, 2018** + +**v2.0.0** -**v1.1.0** # - [INSTALLATION](#installation) @@ -29,56 +21,10 @@ A PowerShell script used to backup files. # INSTALLATION -**Script download link:** https://github.com/mpb10/PowerShell-Backup-Script/archive/master.zip - -Note: This script requires Windows PowerShell and 7-Zip to function. PowerShell comes pre-installed with Windows 10 but otherwise can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=50395. 7-Zip can be downloaded here: http://www.7-zip.org/download.html - -Make sure your ExecutionPolicy is properly set by opening a PowerShell window with administrator privileges and typing `Set-ExecutionPolicy RemoteSigned`. - -**To Install:** Download the project .zip file, extract it to a folder, and run the `Backup_Installer.ps1` shortcut. The script will be installed to the folder `C:\Users\%USERNAME%\Backup Script`. A desktop shortcut and a Start Menu shortcut will be created. Run either of these to use the script. - -To update the script, delete the following folder, download the new version and install it: - - C:\Users\%USERNAME%\Backup Script\scripts -Make sure you don't delete any of the .txt files! - -# - -To uninstall this script, delete the Backup Script folders located at `C:\Users\%USERNAME%\Backup Script` and `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Backup Script`, as well as the desktop shortcut. - - # USAGE -Run either the desktop shortcut or the Start Menu shortcut. At the main menu, choose option `1` to select the folder to be backed up and the folder to which the backup is to be saved. By default the script will backup the user's `Documents` folder to `E:\Backups`. Make sure you choose the proper drive when backing up a folder. Alternatively, users can choose option `2` at the main menu to backup folders listed in the `backuplist.txt` file which is found at `C:\Users\%USERNAME%\Backup Script`. - -# - -**New in version 1.1.0**, users can save a list of folders to be backed up in the text file `C:\Users\%USERNAME%\Backup Script\backuplist.txt`. One line at a time, list the path of each folder that is to be backed up, with the first line being the path of where to save the backups. Once the `backuplist.txt` file is set, choose option 2 on the main menu. Confirm that the information is correct and then begin the process. - -# - -For advanced users, the `backup.ps1` script, which is found in the folder `C:\Users\%USERNAME%\Backup Script\scripts`, can be passed parameters so that this script can be used in conjunction with other scripts or forms of automation. Make sure you have `7z.exe` added to your PATH. - -**backup.ps1's parameters are as followed:** - - -InputPath - Folder to be backed up. - - -OutputPath - Location where to save the backup. - - # CHANGE LOG - 1.1.1 June 23rd, 2017 - Uploaded to Github. - Condensed installer to one PowerShell script. - Edited documentation. - - 1.1.0 June 12th, 2017 - Added backing up folders listed in backuplist.txt. - - # ADDITIONAL NOTES This script uses the 7-Zip program to compress folders for backing up. 7-Zip is licensed under the GNU LGPL license and its source code can be found at http://www.7-zip.org/. From 6383091050b5326275f2f92ce7aebd7e2e8f8e13 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Fri, 27 Apr 2018 12:53:54 -0400 Subject: [PATCH 02/28] Delete Backup_Script_Installer.ps1 --- scripts/Backup_Script_Installer.ps1 | 94 ----------------------------- 1 file changed, 94 deletions(-) delete mode 100644 scripts/Backup_Script_Installer.ps1 diff --git a/scripts/Backup_Script_Installer.ps1 b/scripts/Backup_Script_Installer.ps1 deleted file mode 100644 index 302c00d..0000000 --- a/scripts/Backup_Script_Installer.ps1 +++ /dev/null @@ -1,94 +0,0 @@ - -Function PauseScript { - Write-Host "`nPress any key to continue ...`n" -ForegroundColor "Gray" - $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") -} - -Write-Host "Beginning Backup Script installation ..." -ForegroundColor "Yellow" - -Write-Verbose "Creating install folders ..." - -$SettingsFolder = $ENV:USERPROFILE + "\Backup Script" -If ((Test-Path "$SettingsFolder") -eq $False) { - New-Item -Type Directory -Path "$SettingsFolder" -} - -$ScriptsFolder = $ENV:USERPROFILE + "\Backup Script\scripts" -If ((Test-Path "$ScriptsFolder") -eq $False) { - New-Item -Type Directory -Path "$ScriptsFolder" -} - -$StartFolder = $ENV:APPDATA + "\Microsoft\Windows\Start Menu\Programs\Backup Script" -If ((Test-Path "StartFolder") -eq $False) { - New-Item -Type Directory -Path "$StartFolder" -} - -$DesktopFolder = $ENV:USERPROFILE + "\Desktop" - -Function Check7Zip { - Write-Verbose "Checking 7-Zip installation ..." - $CheckInstallx64 = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object {$_.DisplayName -like "*7-Zip*"} | ForEach-Object {$_.DisplayName} - $CheckInstallx86 = Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object {$_.DisplayName -like "*7-Zip*"} | ForEach-Object {$_.DisplayName} - If ($CheckInstallx64 -like "*7-Zip*" -or $CheckInstallx86 -like "*7-Zip*") { - Write-Verbose "7-Zip is properly installed." - } - Else { - $MenuOption = 99 - While ($MenuOption -ne 1 -and $MenuOption -ne 2) { - Write-Host "7-zip is not installed according to the registry.`n" -ForegroundColor "Red" - Write-Host "Would you like to download and install it now? If you already have it installed, you can`nspecify the install location in the settings.txt file after this script is finished.`n" - Write-Host " 1 - Download and install 7-zip" - Write-Host " 2 - Skip 7-zip installation" - Write-Host " (NOTE: The script will not function without 7-zip.)`n" -ForegroundColor "Gray" - $MenuOption = Read-Host "Option" - - If ($MenuOption -eq 1) { - Write-Host "`nDownloading 7-zip now. Please install to: C:\Program Files\7-Zip" - If (([environment]::Is64BitOperatingSystem) -eq $True) { - $URL = "http://www.7-zip.org/a/7z1604-x64.exe" - $Output = $ENV:USERPROFILE + "\Backup Script\7z1604-x64.exe" - } - Else { - $URL = "http://www.7-zip.org/a/7z1604.exe" - $Output = $ENV:USERPROFILE + "\Backup Script\7z1604-x86.exe" - } - (New-Object System.Net.WebClient).DownloadFile($URL, $Output) - Start-Process "$Output" -Wait - Remove-Item "$Output" - } - ElseIf ($MenuOption -eq 2) { - Return - } - } - } -} - -Write-Verbose "Checking PowerShell version ..." - -If ($PSVersionTable.PSVersion.Major -lt 5) { - Write-Host "[NOTE]: Your PowerShell installation is not the most recent version." -ForegroundColor "Red" - Write-Host " It's recommended that you have PowerShell version 5 to use this script." -ForegroundColor "Red" - Write-Host " You can download PowerShell version 5 at:" -ForegroundColor "Red" - Write-Host " https://www.microsoft.com/en-us/download/details.aspx?id=50395" -ForegroundColor "Gray" -} -Else { - Write-Verbose "PowerShell is up to date." -} - -Write-Verbose "Copying install files ..." - -Copy-Item ".\scripts\backup.ps1" -Destination "$ScriptsFolder" -Copy-Item ".\scripts\Backup Script.lnk" -Destination "$ScriptsFolder" -Copy-Item ".\scripts\Backup Script.lnk" -Destination "$DesktopFolder" -Copy-Item ".\scripts\Backup Script.lnk" -Destination "$StartFolder" -Copy-Item ".\settings.txt" -Destination "$SettingsFolder" -Copy-Item ".\README.md" -Destination "$SettingsFolder" -Copy-Item ".\LICENSE" -Destination "$SettingsFolder" - -Check7Zip - -Write-Host "`nInstallation complete." -ForegroundColor "Yellow" - -PauseScript - -Exit From 992f3656f0d7d707153619b6d5cce38386a84ed8 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Fri, 27 Apr 2018 12:54:02 -0400 Subject: [PATCH 03/28] Delete Backup Script.lnk --- scripts/Backup Script.lnk | Bin 2093 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 scripts/Backup Script.lnk diff --git a/scripts/Backup Script.lnk b/scripts/Backup Script.lnk deleted file mode 100644 index 9e36a524201c72bdd82c7fca0667029f344fa16f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2093 zcmds1O-NKx6#iy19EoUxDayiL(g>EmG(lsCen-p6pJ|?E!3)&!se_|$nm0MlCWt7( zjkE~b1mYs1ML#P+Fl^Jhf}%~(CWIiZMa!V?JZGLWHj$e)-p9H3-FMIZ&Ue3a?rQ_! z^10aqi*}Ee6}JZp-*0>Bo1Q#-=gN(3Qzib;;9D1tm!h2Ou2p}h|KalCK=^a#8|7;t z=AHfM!I8SUhkJ4KTtIi6)?Om0wbd_M1l}YgRm>M#~O2NP=8o;gC zgW)Xda==$Zo~<3h&Yqj39(GWDHL@nCJGK`?Eo2(D85>AKBesD!ABhuk*w0gs@p`om zXv~YT5Sq8u@D`0R&fO}w1wNvZIg`|Wp}R{#!b}@UYuJd#Rb#>c;dz z*?jA{Eag6gg{>xRb&)_{&t63YH<)(|3iBlTDL9KhL@~ne3C@b?tI$76wlR97=p&V* z;5@p~%5jwE93Ya4i!>GbhWf&+>daf*9v}l#xY+3^Dq+TePV~3s>T{K9%tEq?U~xCccTm?3$lvEmTj-(@E!^HPtNo z_U9?BGMdGztHeR#=bt{p2qswydj5C0QG%JPdYP+KUT%PorQ!l+{Hp~KG0l`;x3X7w zqs750+YIgRYFhuX#x{d;o9hhn*W4<1g5!Id{9(6op6+;6zU02vF&9){JiYW_PS$#9 zyh1ZqI7%Ce4fXYBQbuheYR?ZfmzLIiyLbBe;LpWV?&^^*yBg=KgG)Pao%vAlsrOOE Izt#ohH#a#dTmS$7 From f7f4302b8967f475b7ec4504aaef0cbf3725cfe1 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Fri, 27 Apr 2018 12:54:17 -0400 Subject: [PATCH 04/28] Delete Backup_Script_Installer.lnk --- Backup_Script_Installer.lnk | Bin 2163 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Backup_Script_Installer.lnk diff --git a/Backup_Script_Installer.lnk b/Backup_Script_Installer.lnk deleted file mode 100644 index 87ac9bf0804c7c654938f953762047c8d12bd309..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2163 zcmds1O-K}B7=Cs$T#0CdEy}_sX$4CsP0(1PAKR5&{Mj693nu(oM_pWN}P0fS-IDS5$JDb)!9jLVj3*lFOFQW00J~LzC6g()x%8TW|?NV7e$~{S&U%tC2 z;ut|6Ok`kj*Irz95T`4=&?c<3FAj_P<>UhCaAl17DCNs8nGE0NI@gEfdoJC6L#3oQ;)G)wFao) z;A0^?Z>!-g=wpnhRqzOWL?v?usrAC8P6bIbW2CG>Bau*zaRc(<&s@V6<(T-^%g z_i9@IF{8GEa$D;kZD{Q3< z#0PqMC(=fBGG>pDgo=x+zTQ3itpCU28F%H-=RNiFmBFRmH_yE<``G=k>`&_g@(b!= BI$Zz& From 2bd12401dd369f47277ac9d0f413535f5196c740 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Fri, 27 Apr 2018 12:54:28 -0400 Subject: [PATCH 05/28] Delete settings.txt --- settings.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 settings.txt diff --git a/settings.txt b/settings.txt deleted file mode 100644 index e3d8c41..0000000 --- a/settings.txt +++ /dev/null @@ -1,2 +0,0 @@ -[settings] -7ZipInstallFolder=C:\Program Files\7-zip\7z.exe \ No newline at end of file From 2e1d5ae827ae170d37b55392e0521f32d080b9c4 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Tue, 8 May 2018 19:23:55 -0400 Subject: [PATCH 06/28] Create Installer.lnk --- install/Installer.lnk | 1 + 1 file changed, 1 insertion(+) create mode 100644 install/Installer.lnk diff --git a/install/Installer.lnk b/install/Installer.lnk new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/install/Installer.lnk @@ -0,0 +1 @@ + From a027e6073a46f9a97f5a4646ca1fb84a17f5d9f6 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Tue, 8 May 2018 19:24:10 -0400 Subject: [PATCH 07/28] Create installfiles.txt --- install/files/installfiles.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 install/files/installfiles.txt diff --git a/install/files/installfiles.txt b/install/files/installfiles.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/install/files/installfiles.txt @@ -0,0 +1 @@ + From 875ddb0c58407c6a06766e81f778d3595a8d8c60 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Tue, 8 May 2018 19:24:50 -0400 Subject: [PATCH 08/28] Rename scripts/backup.ps1 to backup.ps1 --- scripts/backup.ps1 => backup.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/backup.ps1 => backup.ps1 (100%) diff --git a/scripts/backup.ps1 b/backup.ps1 similarity index 100% rename from scripts/backup.ps1 rename to backup.ps1 From d65859f353d0d3e7b6df47446ccbfffa20cde303 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Tue, 8 May 2018 22:39:32 -0400 Subject: [PATCH 09/28] Add files via upload --- PowerShell-Backup - Portable Version.lnk | Bin 0 -> 2207 bytes backup.ps1 | 622 ++++++++++------------- 2 files changed, 278 insertions(+), 344 deletions(-) create mode 100644 PowerShell-Backup - Portable Version.lnk diff --git a/PowerShell-Backup - Portable Version.lnk b/PowerShell-Backup - Portable Version.lnk new file mode 100644 index 0000000000000000000000000000000000000000..d1d6dd4e0f1401b8ffd1b6e208db86c73bc71f28 GIT binary patch literal 2207 zcmds3O-NKx6#iy1W~9Oirbr8Wg|o19(gY2O{`{dPHS<{(yg(hFIygG7d6T1?Froxk zMHCSP;v%9&KPy8hrhSVH`q=~#gb<{)aM2>|JMYbmjX%|-_d`b&WF-+ah>@!?t4M?b&zgP*`lR5E9h>W`jkR$xTpderRJ!(qQZpo4zw2oDGD zM@0m4_-7Wi6%yK1G15%UG*dqr4^V)7N|dsVB5@R3L6LHvvX!!i@@?ein1@z9t2Wov zE2>%zE{J5lwN#c;FB*ldDr_|gfwq`^A)0W3c{iajPZB?cnUFP*8Bv8Jg5(#1!Ep+9 zGCCUC(Z;tuL@?MkIHr_6HLOeTN;)%t8uOO9N;G7SSdNc|RE9MAP4QhC*CG^?k3={~ zmND{=aJGUNW<5yH3XV`4oQY{gp%}I730sl)(=2zum%+S=m=SvLapp^Bw7^XEfuH+K z)~S~XbpWG2J8eyoNX)01$&L1}DdbvM4Q1tMn*VWqtcJ*~t~torwpR88?Hh`mgX`Fi zH@wK3a-M4#ul7HAc=GnR^tDpBg+|ZNO6dx9wY3k%^kO4uwF_!ouA;Bk4?XUjO&oL< z_I%z{K2cabweiy7xA`Ah@8$ok|0Pj)S&rsl7Pt6xp}@jjQ0sZ80N1#Q>v+Bdd2)2{ zBvDXhoinC&&dBL* - - -# ======================================================================================================= # -# ======================================================================================================= # - - <# .SYNOPSIS Automates the process of creating .zip backup files of user specified folders. .DESCRIPTION - This script uses the 7-zip archive utility to create .zip archive files of user specified folders. This script can be ran via the command line using parameters, or it can be ran without parameters to use its GUI. See README.md for more information. + This script uses the 7-zip archive utility to create .zip archive files of user specified folders. This script can be ran via the command line using parameters, or it can be ran without parameters to use its GUI. .PARAMETER InputPath Specify the folder that is to be backed up. @@ -52,407 +12,381 @@ .PARAMETER BackupList Backup folders listed in the backuplist.txt file. The first line is the folder to which the backups will be saved. -.EXAMPLE - C:\Users\%USERNAME%\Backup Script\scripts\backup.ps1 +.EXAMPLE + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 Runs the script in GUI mode. -.EXAMPLE - C:\Users\%USERNAME%\Backup Script\scripts\backup.ps1 -InputPath "C:\Users\mpb10\Documents" -OutputPath "E:\Backups" +.EXAMPLE + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -InputPath "C:\Users\mpb10\Documents" -OutputPath "E:\Backups" Backups the user mpb10's Documents folder to "E:\Backups". -.EXAMPLE - C:\Users\%USERNAME%\Backup Script\scripts\backup.ps1 -BackupList - Backs up the folders listed in "C:\Users\%USERNAME%\Backup Script\backuplist.txt" to the folder listed on the first line of the file. +.EXAMPLE + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -BackupList -OutputPath "E:\Backups" + Backs up the folders listed in "C:\Users\%USERNAME%\Scripts\Backup-Script\config\backuplist.txt" to "E:\Backups". -.NOTES - Requires Windows 7 or higher +.NOTES + Requires Windows 7 or higher and PowerShell version 5.0 or greater. Author: mpb10 Updated: November 27th, 2017 - Version: 1.2.0 - + Version: 2.0.0 .LINK https://github.com/mpb10/PowerShell-Backup-Script #> - # ======================================================================================================= # # ======================================================================================================= # -# ======================================================================================================= # -# ======================================================================================================= # +Param ( + [String]$InputPath, + [String]$OutputPath, + [String]$OutputFormat, + [Switch]$BackupList, + [Switch]$Install, + [Switch]$UpdateScript +) # ======================================================================================================= # # ======================================================================================================= # +# +# SCRIPT SETTINGS +# +# ======================================================================================================= # +$CheckForUpdates = $True -Param( - [String]$InputPath, - [String]$OutputPath, - [Switch]$BackupList -) # ======================================================================================================= # # ======================================================================================================= # +# +# LIBRARY +# +# ======================================================================================================= # +$InstallLocation = $ENV:USERPROFILE + "\Scripts\PowerShell-Backup" +$DesktopFolder = $ENV:USERPROFILE + "\Desktop" +$StartFolder = $ENV:APPDATA + "\Microsoft\Windows\Start Menu\Programs\PowerShell-Backup" +[Version]$RunningVersion = '2.0.0' +[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" +$CurrentDate = Get-Date -UFormat "%m-%d-%Y" + +# ======================================================================================================= # +# ======================================================================================================= # +# +# FUNCTIONS +# +# ======================================================================================================= # + # Function for simulating the 'pause' command of the Windows command line. Function PauseScript { - Write-Host "`nPress any key to continue ...`n" -ForegroundColor "Gray" - $Wait = $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") + If (($PSBoundParameters.Count) -eq 0) { + Write-Host "`nPress any key to continue ...`n" -ForegroundColor "Gray" + $Wait = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") + } } -# ======================================================================================================= # -# ======================================================================================================= # +Function DownloadFile { + Param( + [String]$URLToDownload, + [String]$SaveLocation + ) + (New-Object System.Net.WebClient).DownloadFile("$URLToDownload", "$TempFolder\download.tmp") + Move-Item -Path "$TempFolder\download.tmp" -Destination "$SaveLocation" -Force +} -$SettingsFolder = $ENV:USERPROFILE + "\Backup Script" -$SettingsFolderCheck = Test-Path $SettingsFolder -If ((Test-Path "$SettingsFolder") -eq $False) { - New-Item -Type directory -Path $SettingsFolder -} -$BackupListFile = $SettingsFolder + "\backuplist.txt" -$BackupListFileCheck = Test-Path $BackupListFile -If ((Test-Path "$BackupListFile") -eq $False) { - New-Item -Type file -Path $BackupListFile +Function Download7Zip { + DownloadFile "http://www.7-zip.org/a/7za920.zip" "$BinFolder\7za920.zip" + + Expand-Archive -Path "$BinFolder\7za920.zip" -DestinationPath "$BinFolder\7za920" + + Copy-Item -Path "$BinFolder\7za920\7za.exe" -Destination "$BinFolder" + Remove-Item -Path "$BinFolder\7za920.zip" + Remove-Item -Path "$BinFolder\7za920" -Recurse -Force } -$7zipInstallLocation = Get-Content "$SettingsFolder\settings.txt" | Where-Object { $_.Trim() -like "7ZipInstallFolder*" } -$7ZipInstallLocation = ($7ZipInstallLocation.Substring($7ZipInstallLocation.IndexOf('=') + 1)).Trim() -$Check7ZipInstallSettings = Test-Path "$7ZipInstallLocation\7z.exe" -$Check7ZipInstallX64 = Test-Path "C:\Program Files\7-Zip\7z.exe" -$Check7ZipInstallX86 = Test-Path "C:\Program Files (x86)\7-Zip\7z.exe" -If ($Check7ZipInstallSettings -eq $False -and $Check7ZipInstallX64 -eq $False -and $Check7ZipInstallX86 -eq $False -and (! (Get-Command 7z.exe -ErrorAction SilentlyContinue))) { - Write-Host "[ERROR]: Cannot find 7-Zip install location or 7z.exe" -ForegroundColor "Red" - Write-Host " Install 7-Zip or set the 7z.exe install location in the settings.txt file." -ForegroundColor "Red" - PauseScript - Exit -} -Else { - $ENV:Path += ";C:\Program Files (x86)\7-Zip;C:\Program Files\7-Zip;$7ZipInstallLocation" +Function ScriptInitialization { + $Script:BinFolder = $RootFolder + "\bin" + If ((Test-Path "$BinFolder") -eq $False) { + New-Item -Type Directory -Path "$BinFolder" | Out-Null + } + $ENV:Path += ";$BinFolder" + + $Script:TempFolder = $RootFolder + "\temp" + If ((Test-Path "$TempFolder") -eq $False) { + New-Item -Type Directory -Path "$TempFolder" | Out-Null + } + Else { + Remove-Item -Path "$TempFolder\download.tmp" -ErrorAction Silent + } + + $Script:ConfigFolder = $RootFolder + "\config" + If ((Test-Path "$ConfigFolder") -eq $False) { + New-Item -Type Directory -Path "$ConfigFolder" | Out-Null + } + + $Script:BackupListFile = $ConfigFolder + "\BackupList.txt" + If ((Test-Path "$BackupListFile") -eq $False) { + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/BackupList.txt" "$ConfigFolder\BackupList.txt" + } } -# ======================================================================================================= # -# ======================================================================================================= # +Function InstallScript { + If ($PSScriptRoot -eq "$InstallLocation") { + Write-Host "`nPowerShell-Backup files are already installed." + PauseScript + } + Else { + $MenuOption = Read-Host "`nInstall PowerShell-Backup to ""$InstallLocation""? [y/n]" + + If ($MenuOption -like "y" -or $MenuOption -like "yes") { + Write-Host "`nInstalling to ""$InstallLocation"" ..." + + $Script:RootFolder = $InstallLocation + ScriptInitialization + + If ((Test-Path "$StartFolder") -eq $False) { + New-Item -Type Directory -Path "$StartFolder" | Out-Null + } + Download7Zip + Copy-Item "$PSScriptRoot\backup.ps1" -Destination "$RootFolder" + + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/PowerShell-Backup.lnk" "$RootFolder\PowerShell-Backup.lnk" + Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$DesktopFolder\PowerShell-Backup.lnk" + Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$StartFolder\PowerShell-Backup.lnk" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/LICENSE" "$RootFolder\LICENSE.txt" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/README.md" "$RootFolder\README.md" -Function MainMenu { - $MenuOption = 99 - While ($MenuOption -ne 1 -and $MenuOption -ne 0) { - Clear-Host - Write-Host "`n================================================================" - Write-Host " Backup Script v1.2.0 " -ForegroundColor "Yellow" - Write-Host "================================================================" - Write-Host "`nPlease select an option:`n" -ForegroundColor "Yellow" - Write-Host " 1 - Set variables and begin backup process" - Write-Host " 2 - Backup folders listed in backuplist.txt" - Write-Host "`n 0 - Exit`n" -ForegroundColor "Gray" - $MenuOption = Read-Host "Option" - Write-Host "" - If ($MenuOption -eq 1) { - BackupProcess - $MenuOption = 99 - } - ElseIf ($MenuOption -eq 2) { - BackupFromList - $MenuOption = 99 - } - ElseIf ($MenuOption -eq 0) { - $HOST.UI.RawUI.BackgroundColor = $BackgroundColorBefore - $HOST.UI.RawUI.ForegroundColor = $ForegroundColorBefore - Clear-Host - Exit - } - Else { - Write-Host "`n[ERROR]: Provided parameter is not a valid URL.`n" -ForegroundColor "Red" + Write-Host "`nInstallation complete. Please restart the script." -ForegroundColor "Yellow" PauseScript + Exit } } } -# ======================================================================================================= # -# ======================================================================================================= # - - - -Function BackupProcess { - $MenuOption = 99 - While ($MenuOption -ne 1 -and $MenuOption -ne 2 -and $MenuOption -ne 3 -and $MenuOption -ne 9 -and $MenuOption -ne 0) { - Clear-Host - Write-Host "`n================================================================" - Write-Host " Backup Process " -ForegroundColor "Yellow" - Write-Host "================================================================" - Write-Host "`nPlease select a varible to edit using its corresponding ID:`n" -ForegroundColor "Yellow" - Write-Host ($Settings | Format-Table ID,SettingName,BlankCol,SettingValue | Out-String) - Write-Host " 9 - Begin backup process" - Write-Host "`n 0 - Return`n" -ForegroundColor "Gray" - $MenuOption = Read-Host "Option" - Write-Host "" +Function UpdateScript { + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/version-file" "$TempFolder\version-file.txt" + [Version]$NewestVersion = Get-Content "$TempFolder\version-file.txt" | Select -Index 0 + Remove-Item -Path "$TempFolder\version-file.txt" + + If ($NewestVersion -gt $RunningVersion) { + Write-Host "`nA new version of PowerShell-Backup is available: v$NewestVersion" -ForegroundColor "Yellow" + $MenuOption = Read-Host "`nUpdate to this version? [y/n]" - If ($MenuOption -eq 1) { - Write-Host "Enter the full path of the folder you wish to backup:`n" -ForegroundColor "Yellow" - $Script:InputPath = Read-Host "Input path" - If ($InputPath -like "*\") { - $Script:InputPath = $InputPath.Substring(0, $InputPath.Length - 1) - } + If ($MenuOption -like "y" -or $MenuOption -like "yes") { + DownloadFile "http://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/backup.ps1" "$RootFolder\backup.ps1" - $DateVar = Get-Date -UFormat "%m-%d-%Y_%H.%M" - $Script:ZipFileName = $InputPath.Substring($InputPath.LastIndexOf('\') + 1) + "_$DateVar.zip" - $InputPathObj.SettingValue = $InputPath - $ZipFileNameObj.SettingValue = $ZipFileName - $MenuOption = 99 - } - ElseIf ($MenuOption -eq 2) { - Write-Host "Enter the full path of the location to save the backup to:`n" -ForegroundColor "Yellow" - $Script:OutputPath = Read-Host "Output path" - If ($OutputPath -like "*\"){ - $Script:OutputPath = $OutputPath.Substring(0, $OutputPath.Length - 1) + If ($PSScriptRoot -eq "$InstallLocation") { + If ((Test-Path "$StartFolder") -eq $False) { + New-Item -Type Directory -Path "$StartFolder" | Out-Null + } + + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/Youtube-dl.lnk" "$RootFolder\PowerShell-Backup.lnk" + Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$DesktopFolder\PowerShell-Backup.lnk" + Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$StartFolder\PowerShell-Backup.lnk" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/LICENSE" "$RootFolder\LICENSE.txt" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/README.md" "$RootFolder\README.md" } - $OutputPathObj.SettingValue = $OutputPath - $MenuOption = 99 - } - ElseIf ($MenuOption -eq 3) { - Write-Host "Enter the compressed backup filename:`n" -ForegroundColor "Yellow" - $Script:ZipFileName = Read-Host "Compressed backup filename" - $ZipFileNameObj.SettingValue = $ZipFileName - $MenuOption = 99 - } - ElseIf ($MenuOption -eq 9) { - CompressBackup - EndMenu - Return - } - ElseIf ($MenuOption -eq 0) { - Return - } - Else { - Write-Host "`n[ERROR]: Provided parameter is not a valid URL.`n" -ForegroundColor "Red" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/UpdateNotes.txt" "$TempFolder\UpdateNotes.txt" + Get-Content "$TempFolder\UpdateNotes.txt" + Remove-Item "$TempFolder\UpdateNotes.txt" + + Write-Host "`nUpdate complete. Please restart the script." -ForegroundColor "Yellow" + PauseScript + Exit } } + ElseIf ($NewestVersion -eq $RunningVersion) { + Write-Host "`nThe running version of PowerShell-Backup is up-to-date." -ForegroundColor "Yellow" + } + Else { + Write-Host "`n[ERROR] Script version mismatch. Re-installing the script is recommended." -ForegroundColor "Red" -BackgroundColor "Black" + PauseScript + } } -# ======================================================================================================= # -# ======================================================================================================= # - - - -Function CompressBackup { - Write-Host "Compressing backup to: ""$OutputPath\$ZipFileName""" -ForegroundColor "Yellow" - $7zipCommand = "7z a ""$OutputPath" + "\$ZipFileName"" ""$InputPath" + "\*""" - Invoke-Expression $7zipCommand - Write-Host "`nFinished compressing backup to: ""$OutputPath\$ZipFileName""`n" -ForegroundColor "Yellow" +Function BackupFolder { + Param ( + [Parameter(Mandatory)] + [String]$Input, + [Parameter(Mandatory)] + [String]$Output + ) + + If ((Test-Path "$Input" -PathType Container) -eq $False) { + Write-Host "`n[ERROR] Provided input path does not exist or is not a folder." -ForegroundColor "Red" -BackgroundColor "Black" + PauseScript + Return + } + + If ((Test-Path "$Output" -PathType Container) -eq $False) { + Write-Host "`n[WARNING] The provided output folder of ""$Output"" does not exist." + $MenuOption = Read-Host " Create this folder? [y/n]" + + If ($MenuOption -like "y" -or $MenuOption -like "yes") { + New-Item -Type Directory -Path "$Output" | Out-Null + } + Else { + Write-Host "`n[ERROR] No valid output folder was provided." -ForegroundColor "Red" -BackgroundColor "Black" + PauseScript + Return + } + } + + $InputBottom = $Input.Replace(" ", "_") | Split-Path -Leaf + + If (($OutputFormat.Trim()) -like "*7z") { + $FileFormat = ".7z" + } + ElseIf (($OutputFormat.Trim()) -like "*gzip") { + $FileFormat = ".gzip" + } + ElseIf (($OutputFormat.Trim()) -like "*tar") { + $FileFormat = ".tar" + } + Else { + $FileFormat = ".zip" + } + + Write-Host "`nCompressing folder: ""$Input""`nCompressing to: ""$Output""`n" + + $7zipCommand = "7z a ""$Output\$InputBottom_$CurrentDate$FileFormat"" ""$Input\*""" + Invoke-Expression "$7zipCommand" } -# ======================================================================================================= # -# ======================================================================================================= # +Function BackupFromFile { + Param ( + [Parameter(Mandatory)] + [String]$Input + ) + +} -Function BackupFromList { - $TextFile = Get-Content $BackupListFile - $Script:OutputPath = ($TextFile[0]).Trim() - If ($OutputPath -like "*\"){ - $Script:OutputPath = $OutputPath.Substring(0, $OutputPath.Length - 1) +Function CommandLineMode { + If ($Install -eq $True) { + InstallScript + Exit + } + ElseIf ($UpdateScript -eq $True) { + UpdateScript + Exit } - If ($ParameterMode -eq $False) { - $MenuOption = 99 - While ($MenuOption -ne 1 -and $MenuOption -ne 2) { - Clear-Host - Write-Host "Backing up folders listed in: ""$BackupListFile""" -ForegroundColor "Yellow" - Write-Host "Backing up to: ""$OutputPath""`n" -ForegroundColor "Yellow" - Write-Host "Is this correct?`n" -ForegroundColor "Yellow" - Write-Host " 1 - Yes" - Write-Host " 2 - No`n" - $MenuOption = Read-Host "Option" - Write-Host "" - - If ($MenuOption -eq 1) { - $TextFile = $TextFile | Where-Object {$_ -ne $TextFile[0]} - $TextFile | ForEach-Object { - $Script:InputPath = $_ - $DateVar = Get-Date -UFormat "%m-%d-%Y_%H.%M" - $Script:ZipFileName = $InputPath.Substring($InputPath.LastIndexOf('\') + 1) + "_$DateVar.zip" - CompressBackup - } - Write-Host "Finished backing up folders listed in: ""$BackupListFile""`n" -ForegroundColor "Yellow" - EndMenu - Return - } - ElseIf ($MenuOption -eq 2) { - $Script:OutputPath = "E:\Backups" - Return - } - Else { - Write-Host "`n[ERROR]: Provided parameter is not a valid URL.`n" -ForegroundColor "Red" - PauseScript - } - } + If (($OutputPath.Length) -gt 0 -and (Test-Path "$OutputPath") -eq $False) { + New-Item -Type directory -Path "$OutputPath" | Out-Null + } + + If ($BackupList -eq $True -and ($OutputPath.Length) -gt 0) { + Write-Host "`n[ERROR]: The parameter -BackupList can't be used with -InputPath or -OutputPath.`n" -ForegroundColor "Red" -BackgroundColor "Black" + } + ElseIf ($BackupList -eq $True -and ($InputPath.Length) -gt 0) { + BackupFromFile "$InputPath" + Write-Host "`nBackups complete." -ForegroundColor "Yellow" + } + ElseIf ($BackupList -eq $True) { + BackupFromFile "$BackupListFile" + Write-Host "`nBackups complete." -ForegroundColor "Yellow" + } + ElseIf (($InputPath.Length) -gt 0 -and ($OutputPath.Length) -gt 0) { + BackupFolder "$InputPath" "$OutputPath" + Write-Host "`nBackup complete. Backed up to: ""$OutputPath""" -ForegroundColor "Yellow" + } + ElseIf (($InputPath.Length) -gt 0) { + BackupFolder "$InputPath" "$PSScriptRoot" + Write-Host "`nBackup complete. Backed up to: ""$PSScriptRoot""" -ForegroundColor "Yellow" } Else { - Write-Host "Backing up folders listed in: ""$BackupListFile""" -ForegroundColor "Yellow" - Write-Host "Backing up to: ""$OutputPath""`n" -ForegroundColor "Yellow" - $TextFile = $TextFile | Where-Object {$_ -ne $TextFile[0]} - $TextFile | ForEach-Object { - $Script:InputPath = $_ - $DateVar = Get-Date -UFormat "%m-%d-%Y_%H.%M" - $Script:ZipFileName = $InputPath.Substring($InputPath.LastIndexOf('\') + 1) + "_$DateVar.zip" - CompressBackup - } - Write-Host "Finished backing up folders listed in: ""$BackupListFile""`n" -ForegroundColor "Yellow" + Write-Host "`n[ERROR]: Invalid parameters provided." -ForegroundColor "Red" -BackgroundColor "Black" } + + Exit } -# ======================================================================================================= # -# ======================================================================================================= # +Function MainMenu { + +} -Function EndMenu { - Else { - $MenuOption = 99 - While ($MenuOption -ne 1 -and $MenuOption -ne 2) { - Write-Host "`n================================================================" - Write-Host " Script Complete " -ForegroundColor "Yellow" - Write-Host "================================================================" - Write-Host "`nPlease select an option:`n" -ForegroundColor "Yellow" - Write-Host " 1 - Run again" - Write-Host "`n 0 - Exit`n" - $MenuOption = Read-Host "Option" - Write-Host "" - If ($MenuOption -eq 1) { - $Script:InputPath = $ENV:USERPROFILE + "\Documents" - $Script:OutputPath = "E:\Backups" - $Script:DateVar = Get-Date -UFormat "%m-%d-%Y_%H.%M" - $Script:ZipFileName = "Documents_$DateVar.zip" - - $InputPathObj.SettingValue = $InputPath - $OutputPathObj.SettingValue = $OutputPath - $ZipFileNameObj.SettingValue = $ZipFileName - - Return - } - ElseIf ($MenuOption -eq 2) { - $HOST.UI.RawUI.BackgroundColor = $BackgroundColorBefore - $HOST.UI.RawUI.ForegroundColor = $ForegroundColorBefore - Clear-Host - Exit - } - Else { - Write-Host "Please enter a valid option." -ForegroundColor "Red" -BackgroundColor "Black" - Write-Host "" - PauseScript - Write-Host "" - } - } - } +Function SettingsMenu { + } - # ======================================================================================================= # # ======================================================================================================= # +# +# MAIN +# +# ======================================================================================================= # - -Function CommandLineMode { - - If ($BackupList -eq $True) { - BackupFromList - } - Else { - If ($InputPath.Length -gt 0) { - If ($InputPath -like "*\") { - $Script:InputPath = $InputPath.Substring(0, $InputPath.Length - 1) - } - - $DateVar = Get-Date -UFormat "%m-%d-%Y_%H.%M" - $Script:ZipFileName = $InputPath.Substring($InputPath.LastIndexOf('\') + 1) + "_$DateVar.zip" - } - Else { - Write-Host "[ERROR] Input path not specified." -ForegroundColor "Red" - Write-Host " Please specify the folder to backup with: -InputPath " -ForegroundColor "Red" - PauseScript - Exit - } - - If ($OutputPath.Length -gt 0) { - If ($OutputPath -like "*\"){ - $Script:OutputPath = $OutputPath.Substring(0, $OutputPath.Length - 1) - } - - CompressBackup - } - Else { - Write-Host "[ERROR] Output path not specified." -ForegroundColor "Red" - Write-Host " Please specify the location to backup to: -OutputPath " -ForegroundColor "Red" - PauseScript - Exit - } - } +If ($PSVersionTable.PSVersion.Major -lt 5) { + Write-Host "[ERROR]: Your PowerShell installation is not version 5.0 or greater.`n This script requires PowerShell version 5.0 or greater to function.`n You can download PowerShell version 5.0 at:`n https://www.microsoft.com/en-us/download/details.aspx?id=50395" -ForegroundColor "Red" -BackgroundColor "Black" + PauseScript + Exit } +If ($PSScriptRoot -eq "$InstallLocation") { + $RootFolder = $InstallLocation +} +Else { + $RootFolder = "$PSScriptRoot" +} +If ($Install -eq $False) { + ScriptInitialization +} -# ======================================================================================================= # -# ======================================================================================================= # - +If ($CheckForUpdates -eq $True -and $Install -eq $False) { + UpdateScript +} +If ((Test-Path "$BinFolder\7za.exe") -eq $False -and $Install -eq $False) { + Write-Host "`n7-Zip .exe not found. Downloading and installing to: ""$BinFolder"" ...`n" -ForegroundColor "Yellow" + Download7Zip +} -If ($PSBoundParameters.Count -gt 0) { - $ParameterMode = $True +If (($PSBoundParameters.Count) -gt 0) { + CommandLineMode } Else { - $ParameterMode = $False - $InputPath = $ENV:USERPROFILE + "\Documents" - $OutputPath = "E:\Backups" - $DateVar = Get-Date -UFormat "%m-%d-%Y_%H.%M" - $ZipFileName = "Documents_$DateVar.zip" - - $InputPathObj = New-Object Object - $InputPathObj | Add-Member -Type NoteProperty -Name ID -Value 1 - $InputPathObj | Add-Member -Type NoteProperty -Name SettingName -Value "Input path" - $InputPathObj | Add-Member -Type NoteProperty -Name BlankCol -Value "" - $InputPathObj | Add-Member -Type NoteProperty -Name SettingValue -Value $InputPath - - $OutputPathObj = New-Object Object - $OutputPathObj | Add-Member -Type NoteProperty -Name ID -Value 2 - $OutputPathObj | Add-Member -Type NoteProperty -Name SettingName -Value "Output path" - $OutputPathObj | Add-Member -Type NoteProperty -Name BlankCol -Value "" - $OutputPathObj | Add-Member -Type NoteProperty -Name SettingValue -Value $OutputPath - - $ZipFileNameObj = New-Object Object - $ZipFileNameObj | Add-Member -Type NoteProperty -Name ID -Value 3 - $ZipFileNameObj | Add-Member -Type NoteProperty -Name SettingName -Value "Backup name" - $ZipFileNameObj | Add-Member -Type NoteProperty -Name BlankCol -Value "" - $ZipFileNameObj | Add-Member -Type NoteProperty -Name SettingValue -Value $ZipFileName - - $Settings = $InputPathObj,$OutputPathObj,$ZipFileNameObj - - $BackgroundColorBefore = $HOST.UI.RawUI.BackgroundColor - $ForegroundColorBefore = $HOST.UI.RawUI.ForegroundColor - $HOST.UI.RawUI.BackgroundColor = "Black" - $HOST.UI.RawUI.ForegroundColor = "White" - MainMenu } + +Write-Host "End of Script" +PauseScript + + +# ======================================================================================================= # +# ======================================================================================================= # + + + + + + From cf1647613cad21742624df8e5732c9e1f6f6ac7d Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Tue, 8 May 2018 22:39:56 -0400 Subject: [PATCH 10/28] Add files via upload --- install/Installer.lnk | Bin 1 -> 3047 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/install/Installer.lnk b/install/Installer.lnk index 8b137891791fe96927ad78e64b0aad7bded08bdc..1e8358585bfb5ca3036409055f28f68555a8c518 100644 GIT binary patch literal 3047 zcmd^BOGs2v82-kLQ7W8ZinP#+I15W}K0sxN9=_1YSB_=D4b<_fgQGKfCm)+Iq6}9> z6cGgCBBDi)l@JuuzC{K-HbDd-1Zgc?rhWgtI^7sU&$z~eDvh4ZH+fgr@K6T^EOo3F-y74`aV|wv^kO2_PO-lQ(y{b%(S0>XBnSCT$i$a8 zT_^k)MlXUGgTb%%;!ITI2ajrZz&l}t^`Y`I;Al+ewH%R&&df}iJW;0?6Vw%kjvllHTx^)Ej$UL6tJTE-Y zT@H+vswF_hhB;(h=5QpPW0ZfZ;4g4eE0Hru%?+nJ6oi6f`iL>02Lh@-u7mSf9-i_% z91#+oQ@_$#n=T<=E1?)tBZgEZ;&Bp?OBx{^Ac-G^SCXV$Anhk@BmJ1ZJ?kL%p7VCp zH7j0kEtn9|cx!7>S{rB+v|d50i3_wu^i^nN)FnpUrsoVOY>OWij{1nmj}S)`jI!0e zLF%J5Lwvf;tZ`G)!?q8DxX3?Ll0hFTC{CE6fie}^7Il1#HO4kRlQhJCkt_=|Vz#2F z5sl=vWXWdVR}f>J83iA)hiPY!Hi^an+dj^$pqh1v_8EM{rg};OrkC=gmL#)2KZ*T$ zsDYdI$Ky|C;W|=TJ1WWJJ9n@@*77Q6A?%}3T*)OQG+l#*6JpQzAIdUwmaPaG%isyy33%f6$c%S>J>p|{Ta#^2t!Lo6E z#}kMQe(3G1FM9hQ4vnpRf0@UpG0SyP>Pmy(;O+{o6; hB)}JwlNMvmCL)mtIU6T=<65PBb=6|5*(Avz@EcluU;qFB literal 1 Icmd-A000XB3jhEB From 561f86fd9b4bf941ad1fc6c630c435a9d0f2a0fe Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Tue, 8 May 2018 22:40:35 -0400 Subject: [PATCH 11/28] Add files via upload --- install/files/PowerShell-Backup.lnk | Bin 0 -> 2385 bytes install/files/UpdateNotes.txt | 10 ++++++++++ install/files/version-file | 11 +++++++++++ 3 files changed, 21 insertions(+) create mode 100644 install/files/PowerShell-Backup.lnk create mode 100644 install/files/UpdateNotes.txt create mode 100644 install/files/version-file diff --git a/install/files/PowerShell-Backup.lnk b/install/files/PowerShell-Backup.lnk new file mode 100644 index 0000000000000000000000000000000000000000..20f6bb6a60b75059256e95d23e67e435ebd203b1 GIT binary patch literal 2385 zcmds3O-NKx6#m8xl?o@AA}#DCPGRXw6I3Mn^QWBrndWI0yg(hFIygF$Z&HUKj3~j4 zwJ0J8#6?7lepZ5DOq*6MDk$0n5rhzAwQ$iQ?K^Lr(XokK)W-Yf+;i`{_nq_I@0@$@ z)B&(LQdk2Kt47U2N;(v_ucQ~3J$Urm7Sna3sZLktD;vtw@Pp&F==^y7-R8hf_lL%p z%I6B7ed1j@_7xS~&BFf53Ozn)so_Df)tPoZciPe7>+1*%nmCAbq~hz-*@~;#GP0L* zf)>7&?pokOA36}gAWY8Miqmn6W4rCp!e+?mEja)jirc(Kn`67hW=4iMUujcAn6^SN z(2ElAQ*1-`qSe_7M*(rxHdHmXTq1OL+^VBM#>8soreszVk-9C!2Ku4VwgEpM@#Bi4 zpCTUv#cB~yy3EJ4YszB7p47(xzgEFd;Gk6^XOQYoG&d;-1_q6Ov)l0dRb$8i{X`ia zaoz715!@p`Q(0S-P{&Fzj?|1JRf%|r0_0HoDLW{_qv$em<&JJ2qagw4!UsatLRh`jH%pDzxGm_!b5sRBnWRl5}7r(Q; z2To!&tx-2;1klMf_}O<7t+s4!Ci}@e6(+FcK_RNGIC{xih_(V`M85O0?d3{@)i5!& z(W`J>h?+%@3UdE38XfJ+BB;`<$!yNWF8W!{s)zUjL>pc6O176+lbx$FqO!9bOhFqk z?u;gyClClZb#w7(SZ&fVd)GqwGn?jr%-yxX+}c`$oW|>APf)+1$jQBd{lSK3*)u8U z8YZjMCl62Eo|Lgx3b)Ys8EPqAzOJ_RaL6bOdaZt5by`}%mm5bOcg{r)r{wp1+EO}| zUp2G&^3k_B?_2NX{B8UNt?+su&%_*V@##XIWp}CC$XgJ&&P`m$v&zd;sDr14f=cVm zGOaU9?xUz3(d8Gz(SJ13VY&0MZhk%u$clEYn&zxqOYV5N` Date: Tue, 8 May 2018 22:40:49 -0400 Subject: [PATCH 12/28] Delete installfiles.txt --- install/files/installfiles.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 install/files/installfiles.txt diff --git a/install/files/installfiles.txt b/install/files/installfiles.txt deleted file mode 100644 index 8b13789..0000000 --- a/install/files/installfiles.txt +++ /dev/null @@ -1 +0,0 @@ - From cb233637c6d98d75350af68796f1fa30d797e7c6 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Tue, 8 May 2018 22:56:02 -0400 Subject: [PATCH 13/28] Add files via upload --- install/files/BackupList.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 install/files/BackupList.txt diff --git a/install/files/BackupList.txt b/install/files/BackupList.txt new file mode 100644 index 0000000..e1b8060 --- /dev/null +++ b/install/files/BackupList.txt @@ -0,0 +1,12 @@ +# This file specifies the locations of where to backup folders from and to. Under the +# '[Backup From]' section, list the paths of the folders you wish to have backed up, +# and under the '[Backup To]' section, list the paths of the folders where you wish +# to save the backups. List these folder paths one line at a time. + +# Lines starting with '#' are commented out and will be ignored by the script. + +[Backup From] +# C:\Users\%USERNAME%\Documents + +[Backup To] +# E:\Backups From c1a7e6295a9a2f085c5a47334d999d758d4e898e Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Wed, 9 May 2018 01:24:03 -0400 Subject: [PATCH 14/28] Update BackupList.txt --- install/files/BackupList.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/install/files/BackupList.txt b/install/files/BackupList.txt index e1b8060..73bf2a6 100644 --- a/install/files/BackupList.txt +++ b/install/files/BackupList.txt @@ -7,6 +7,7 @@ [Backup From] # C:\Users\%USERNAME%\Documents +# C:\Users\%USERNAME%\Downloads [Backup To] # E:\Backups From f2fecd002676fea27d25755eaaf0b4d6e98b4038 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Wed, 9 May 2018 01:25:05 -0400 Subject: [PATCH 15/28] Update BackupList.txt --- install/files/BackupList.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install/files/BackupList.txt b/install/files/BackupList.txt index 73bf2a6..e5003f1 100644 --- a/install/files/BackupList.txt +++ b/install/files/BackupList.txt @@ -6,8 +6,8 @@ # Lines starting with '#' are commented out and will be ignored by the script. [Backup From] -# C:\Users\%USERNAME%\Documents -# C:\Users\%USERNAME%\Downloads +# C:\Users\%USERNAME%\Documents (example path) +# C:\Users\%USERNAME%\Downloads (example path) [Backup To] -# E:\Backups +# E:\Backups (example path) From 858d0d6887e6977b4ec174117033368e811aac19 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Wed, 9 May 2018 01:25:19 -0400 Subject: [PATCH 16/28] Add files via upload --- backup.ps1 | 90 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 19 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 35172de..aeb2f94 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -52,7 +52,7 @@ Param ( # ======================================================================================================= # $CheckForUpdates = $True - +$Verbose7Zip = $True @@ -82,7 +82,7 @@ $CurrentDate = Get-Date -UFormat "%m-%d-%Y" # Function for simulating the 'pause' command of the Windows command line. Function PauseScript { - If (($PSBoundParameters.Count) -eq 0) { + If ((($PSBoundParameters).Count).ToInt32 -eq 0) { Write-Host "`nPress any key to continue ...`n" -ForegroundColor "Gray" $Wait = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") } @@ -226,23 +226,23 @@ Function UpdateScript { Function BackupFolder { Param ( [Parameter(Mandatory)] - [String]$Input, + [String]$InputFolder, [Parameter(Mandatory)] - [String]$Output + [String]$OutputFolder ) - If ((Test-Path "$Input" -PathType Container) -eq $False) { + If ((Test-Path "$InputFolder" -PathType Container) -eq $False) { Write-Host "`n[ERROR] Provided input path does not exist or is not a folder." -ForegroundColor "Red" -BackgroundColor "Black" PauseScript Return } - If ((Test-Path "$Output" -PathType Container) -eq $False) { - Write-Host "`n[WARNING] The provided output folder of ""$Output"" does not exist." + If ((Test-Path "$OutputFolder" -PathType Container) -eq $False) { + Write-Host "`n[WARNING] The provided output folder of ""$OutputFolder"" does not exist." $MenuOption = Read-Host " Create this folder? [y/n]" If ($MenuOption -like "y" -or $MenuOption -like "yes") { - New-Item -Type Directory -Path "$Output" | Out-Null + New-Item -Type Directory -Path "$OutputFolder" | Out-Null } Else { Write-Host "`n[ERROR] No valid output folder was provided." -ForegroundColor "Red" -BackgroundColor "Black" @@ -251,7 +251,7 @@ Function BackupFolder { } } - $InputBottom = $Input.Replace(" ", "_") | Split-Path -Leaf + $InputFolderBottom = $InputFolder.Replace(" ", "_") | Split-Path -Leaf If (($OutputFormat.Trim()) -like "*7z") { $FileFormat = ".7z" @@ -266,10 +266,25 @@ Function BackupFolder { $FileFormat = ".zip" } - Write-Host "`nCompressing folder: ""$Input""`nCompressing to: ""$Output""`n" + $OutputFileName = "$OutputFolder\$InputFolderBottom" + "_" + "$CurrentDate$FileFormat" + + $Counter = 0 + While ((Test-Path "$OutputFileName") -eq $True) { + $Counter++ + $OutputFileName = "$OutputFolder\$InputFolderBottom" + "_" + "$CurrentDate ($Counter)$FileFormat" + } + + Write-Host "`nCompressing folder: ""$InputFolder""`nCompressing to: ""$OutputFileName""`n" -ForegroundColor "Green" + + $7ZipCommand = "7za a ""$OutputFileName"" ""$InputFolder\*""" + Write-Verbose "7-Zip command: $7zipCommand" - $7zipCommand = "7z a ""$Output\$InputBottom_$CurrentDate$FileFormat"" ""$Input\*""" - Invoke-Expression "$7zipCommand" + If ($Verbose7Zip -eq $True) { + Invoke-Expression "$7ZipCommand" + } + Else { + Invoke-Expression "$7ZipCommand" | Out-Null + } } @@ -277,9 +292,45 @@ Function BackupFolder { Function BackupFromFile { Param ( [Parameter(Mandatory)] - [String]$Input + [String]$InputFile ) + If ((Test-Path "$InputFile") -eq $False) { + Write-Host "`n[ERROR] Provided input file does not exist." -ForegroundColor "Red" -BackgroundColor "Black" + PauseScript + Return + } + + $BackupListArray = Get-Content "$InputFile" | Where-Object {$_.Trim() -ne "" -and $_.Trim() -notlike "#*"} + + $BackupFromArray = $BackupListArray | Select-Object -Index (($BackupListArray.IndexOf("[Backup From]".Trim()))..($BackupListArray.IndexOf("[Backup To]".Trim())-1)) + $BackupToArray = $BackupListArray | Select-Object -Index (($BackupListArray.IndexOf("[Backup To]".Trim()))..($BackupListArray.Count - 1)) + + If ($BackupToArray.Count -eq 1) { + Write-Host "[ERROR] No output folder paths listed under '[Backup To]'." -ForegroundColor "Red" -ForegroundColor "Black" + PauseScript + Return + } + ElseIf ($BackupToArray.Count -gt 1) { + $BackupToArray = @($BackupToArray | Where-Object {$_ -ne $BackupToArray[0]}) + } + + If ($BackupFromArray.Count -gt 1) { + Write-Host "`nStarting batch job from file: ""$InputFile""" -ForegroundColor "Green" + + $BackupFromArray | Where-Object {$_ -ne $BackupFromArray[0]} | ForEach-Object { + $Counter = 0 + While ($BackupToArray.Count -gt $Counter) { + BackupFolder "$_" $BackupToArray[$Counter] + $Counter++ + } + } + } + Else { + Write-Host "[ERROR] No input folder paths listed under '[Backup From]'." -ForegroundColor "Red" -ForegroundColor "Black" + PauseScript + Return + } } @@ -299,26 +350,26 @@ Function CommandLineMode { } If ($BackupList -eq $True -and ($OutputPath.Length) -gt 0) { - Write-Host "`n[ERROR]: The parameter -BackupList can't be used with -InputPath or -OutputPath.`n" -ForegroundColor "Red" -BackgroundColor "Black" + Write-Host "`n[ERROR]: The parameter -BackupList can't be used with -OutputPath.`n" -ForegroundColor "Red" -BackgroundColor "Black" } ElseIf ($BackupList -eq $True -and ($InputPath.Length) -gt 0) { BackupFromFile "$InputPath" - Write-Host "`nBackups complete." -ForegroundColor "Yellow" + Write-Host "`nBackups complete.`n" -ForegroundColor "Yellow" } ElseIf ($BackupList -eq $True) { BackupFromFile "$BackupListFile" - Write-Host "`nBackups complete." -ForegroundColor "Yellow" + Write-Host "`nBackups complete.`n" -ForegroundColor "Yellow" } ElseIf (($InputPath.Length) -gt 0 -and ($OutputPath.Length) -gt 0) { BackupFolder "$InputPath" "$OutputPath" - Write-Host "`nBackup complete. Backed up to: ""$OutputPath""" -ForegroundColor "Yellow" + Write-Host "`nBackup complete. Backed up to: ""$OutputPath""`n" -ForegroundColor "Yellow" } ElseIf (($InputPath.Length) -gt 0) { BackupFolder "$InputPath" "$PSScriptRoot" - Write-Host "`nBackup complete. Backed up to: ""$PSScriptRoot""" -ForegroundColor "Yellow" + Write-Host "`nBackup complete. Backed up to: ""$PSScriptRoot""`n" -ForegroundColor "Yellow" } Else { - Write-Host "`n[ERROR]: Invalid parameters provided." -ForegroundColor "Red" -BackgroundColor "Black" + Write-Host "`n[ERROR]: Invalid parameters provided.`n" -ForegroundColor "Red" -BackgroundColor "Black" } Exit @@ -380,6 +431,7 @@ Else { Write-Host "End of Script" PauseScript +Exit # ======================================================================================================= # From e0bd0b8d286bff9e9b89d743fc97b6f2a8db04f5 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Wed, 9 May 2018 01:26:24 -0400 Subject: [PATCH 17/28] Add files via upload --- backup.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup.ps1 b/backup.ps1 index aeb2f94..628d2db 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -52,7 +52,7 @@ Param ( # ======================================================================================================= # $CheckForUpdates = $True -$Verbose7Zip = $True +$Verbose7Zip = $False From 8b3f9304e25393417474f957c55cff690a5dc9a1 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Wed, 9 May 2018 02:04:05 -0400 Subject: [PATCH 18/28] Add files via upload --- backup.ps1 | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 628d2db..7c44b27 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -25,7 +25,7 @@ .NOTES Requires Windows 7 or higher and PowerShell version 5.0 or greater. Author: mpb10 - Updated: November 27th, 2017 + Updated: May 9th, 2018 Version: 2.0.0 .LINK https://github.com/mpb10/PowerShell-Backup-Script @@ -70,6 +70,8 @@ $StartFolder = $ENV:APPDATA + "\Microsoft\Windows\Start Menu\Programs\PowerShell [Version]$RunningVersion = '2.0.0' [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" $CurrentDate = Get-Date -UFormat "%m-%d-%Y" +$BackupFolderStatus = $True +$BackupFromFileStatus = $True @@ -149,7 +151,7 @@ Function InstallScript { Else { $MenuOption = Read-Host "`nInstall PowerShell-Backup to ""$InstallLocation""? [y/n]" - If ($MenuOption -like "y" -or $MenuOption -like "yes") { + If ($MenuOption.Trim() -like "y" -or $MenuOption.Trim() -like "yes") { Write-Host "`nInstalling to ""$InstallLocation"" ..." $Script:RootFolder = $InstallLocation @@ -187,7 +189,7 @@ Function UpdateScript { Write-Host "`nA new version of PowerShell-Backup is available: v$NewestVersion" -ForegroundColor "Yellow" $MenuOption = Read-Host "`nUpdate to this version? [y/n]" - If ($MenuOption -like "y" -or $MenuOption -like "yes") { + If ($MenuOption.Trim() -like "y" -or $MenuOption.Trim() -like "yes") { DownloadFile "http://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/backup.ps1" "$RootFolder\backup.ps1" If ($PSScriptRoot -eq "$InstallLocation") { @@ -230,10 +232,12 @@ Function BackupFolder { [Parameter(Mandatory)] [String]$OutputFolder ) + $Script:BackupFolderStatus = $True If ((Test-Path "$InputFolder" -PathType Container) -eq $False) { Write-Host "`n[ERROR] Provided input path does not exist or is not a folder." -ForegroundColor "Red" -BackgroundColor "Black" PauseScript + $Script:BackupFolderStatus = $False Return } @@ -241,12 +245,13 @@ Function BackupFolder { Write-Host "`n[WARNING] The provided output folder of ""$OutputFolder"" does not exist." $MenuOption = Read-Host " Create this folder? [y/n]" - If ($MenuOption -like "y" -or $MenuOption -like "yes") { + If ($MenuOption.Trim() -like "y" -or $MenuOption.Trim() -like "yes") { New-Item -Type Directory -Path "$OutputFolder" | Out-Null } Else { Write-Host "`n[ERROR] No valid output folder was provided." -ForegroundColor "Red" -BackgroundColor "Black" PauseScript + $Script:BackupFolderStatus = $False Return } } @@ -274,7 +279,7 @@ Function BackupFolder { $OutputFileName = "$OutputFolder\$InputFolderBottom" + "_" + "$CurrentDate ($Counter)$FileFormat" } - Write-Host "`nCompressing folder: ""$InputFolder""`nCompressing to: ""$OutputFileName""`n" -ForegroundColor "Green" + Write-Host "`nCompressing folder: ""$InputFolder""`nCompressing to: ""$OutputFileName""" -ForegroundColor "Green" $7ZipCommand = "7za a ""$OutputFileName"" ""$InputFolder\*""" Write-Verbose "7-Zip command: $7zipCommand" @@ -294,10 +299,12 @@ Function BackupFromFile { [Parameter(Mandatory)] [String]$InputFile ) + $Script:BackupFromFileStatus = $True If ((Test-Path "$InputFile") -eq $False) { Write-Host "`n[ERROR] Provided input file does not exist." -ForegroundColor "Red" -BackgroundColor "Black" PauseScript + $Script:BackupFromFileStatus = $False Return } @@ -307,8 +314,9 @@ Function BackupFromFile { $BackupToArray = $BackupListArray | Select-Object -Index (($BackupListArray.IndexOf("[Backup To]".Trim()))..($BackupListArray.Count - 1)) If ($BackupToArray.Count -eq 1) { - Write-Host "[ERROR] No output folder paths listed under '[Backup To]'." -ForegroundColor "Red" -ForegroundColor "Black" + Write-Host "`n[ERROR] No output folder paths listed under '[Backup To]'." -ForegroundColor "Red" -BackgroundColor "Black" PauseScript + $Script:BackupFromFileStatus = $False Return } ElseIf ($BackupToArray.Count -gt 1) { @@ -327,8 +335,9 @@ Function BackupFromFile { } } Else { - Write-Host "[ERROR] No input folder paths listed under '[Backup From]'." -ForegroundColor "Red" -ForegroundColor "Black" + Write-Host "`n[ERROR] No input folder paths listed under '[Backup From]'." -ForegroundColor "Red" -BackgroundColor "Black" PauseScript + $Script:BackupFromFileStatus = $False Return } } @@ -345,28 +354,32 @@ Function CommandLineMode { Exit } - If (($OutputPath.Length) -gt 0 -and (Test-Path "$OutputPath") -eq $False) { - New-Item -Type directory -Path "$OutputPath" | Out-Null - } - If ($BackupList -eq $True -and ($OutputPath.Length) -gt 0) { Write-Host "`n[ERROR]: The parameter -BackupList can't be used with -OutputPath.`n" -ForegroundColor "Red" -BackgroundColor "Black" } ElseIf ($BackupList -eq $True -and ($InputPath.Length) -gt 0) { BackupFromFile "$InputPath" - Write-Host "`nBackups complete.`n" -ForegroundColor "Yellow" + If ($BackupFromFileStatus -eq $True) { + Write-Host "`nBackups complete.`n" -ForegroundColor "Yellow" + } } ElseIf ($BackupList -eq $True) { BackupFromFile "$BackupListFile" - Write-Host "`nBackups complete.`n" -ForegroundColor "Yellow" + If ($BackupFromFileStatus -eq $True) { + Write-Host "`nBackups complete.`n" -ForegroundColor "Yellow" + } } ElseIf (($InputPath.Length) -gt 0 -and ($OutputPath.Length) -gt 0) { BackupFolder "$InputPath" "$OutputPath" - Write-Host "`nBackup complete. Backed up to: ""$OutputPath""`n" -ForegroundColor "Yellow" + If ($BackupFolderStatus -eq $True) { + Write-Host "`nBackup complete. Backed up to: ""$OutputPath""`n" -ForegroundColor "Yellow" + } } ElseIf (($InputPath.Length) -gt 0) { BackupFolder "$InputPath" "$PSScriptRoot" - Write-Host "`nBackup complete. Backed up to: ""$PSScriptRoot""`n" -ForegroundColor "Yellow" + If ($BackupFolderStatus -eq $True) { + Write-Host "`nBackup complete. Backed up to: ""$PSScriptRoot""`n" -ForegroundColor "Yellow" + } } Else { Write-Host "`n[ERROR]: Invalid parameters provided.`n" -ForegroundColor "Red" -BackgroundColor "Black" From 6f4cbca98628e497b5f9f002bb7449f8b86d81f2 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Wed, 9 May 2018 02:05:25 -0400 Subject: [PATCH 19/28] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92cf816..ac01f57 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A PowerShell script used to backup files. **Author: Matt Bittner** -**April 27th, 2018** +**May 9th, 2018** **v2.0.0** From 9051b77e814b63cbcf04ce15255041c44f4d74f6 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Wed, 16 May 2018 22:58:47 -0400 Subject: [PATCH 20/28] Add files via upload --- backup.ps1 | 88 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 7c44b27..aa53e96 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -9,26 +9,41 @@ Specify the folder that is to be backed up. .PARAMETER OutputPath Specify the folder to which the backup will be saved. +.PARAMETER OutputFormat + Specify the archive file format to compress the backup to. Supported formats are .7z, .gzip, .tar, and .zip. The default is .zip .PARAMETER BackupList - Backup folders listed in the backuplist.txt file. The first line is the folder to which the backups will be saved. + Backup folders listed in the backuplist.txt file. +.PARAMETER Install + Install the script to "C:\Users\%USERNAME%\Scripts\PowerShell-Backup" and create desktop and Start Menu shortcuts. +.PARAMETER UpdateScript + Update the backup.ps1 script file to the most recent version. .EXAMPLE C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 Runs the script in GUI mode. .EXAMPLE - C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -InputPath "C:\Users\mpb10\Documents" -OutputPath "E:\Backups" - Backups the user mpb10's Documents folder to "E:\Backups". + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -InputPath "C:\Users\mpb10\Documents" -OutputPath "E:\Backups" -OutputFormat ".7z" + Backups the Documents folder to "E:\Backups" compressed to the .7z format. .EXAMPLE - C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -BackupList -OutputPath "E:\Backups" - Backs up the folders listed in "C:\Users\%USERNAME%\Scripts\Backup-Script\config\backuplist.txt" to "E:\Backups". + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -BackupList + Backs up the folders listed in "C:\Users\%USERNAME%\Scripts\PowerShell-Backup\config\BackupList.txt" +.EXAMPLE + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -BackupList -InputPath "C:\TestFolder\BackupList.txt" + Backs up the folders listed in "C:\TestFolder\BackupList.txt". +.EXAMPLE + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -Install + Installs the script to "C:\Users\%USERNAME%\Scripts\PowerShell-Backup" and creates desktop and Start Menu shortcuts. +.EXAMPLE + C:\Users\%USERNAME%\Scripts\Backup-Script\scripts\backup.ps1 -UpdateScript + Updates the backup.ps1 script file to the most recent version. .NOTES - Requires Windows 7 or higher and PowerShell version 5.0 or greater. + Requires PowerShell version 5.0 or greater. Author: mpb10 - Updated: May 9th, 2018 + Updated: May 16th, 2018 Version: 2.0.0 .LINK - https://github.com/mpb10/PowerShell-Backup-Script + https://github.com/mpb10/PowerShell-Backup #> # ======================================================================================================= # @@ -84,7 +99,7 @@ $BackupFromFileStatus = $True # Function for simulating the 'pause' command of the Windows command line. Function PauseScript { - If ((($PSBoundParameters).Count).ToInt32 -eq 0) { + If ($PSBoundParameters.Count -eq 0) { Write-Host "`nPress any key to continue ...`n" -ForegroundColor "Gray" $Wait = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") } @@ -290,6 +305,7 @@ Function BackupFolder { Else { Invoke-Expression "$7ZipCommand" | Out-Null } + PauseScript } @@ -391,7 +407,59 @@ Function CommandLineMode { Function MainMenu { - + $MenuOption = 99 + While ($MenuOption -ne 1 -and $MenuOption -ne 2 -and $MenuOption -ne 3 -and $MenuOption -ne 0) { + $URL = "" + Clear-Host + Write-Host "===================================================================================================" + Write-Host " PowerShell-Backup v$RunningVersion " -ForegroundColor "Yellow" + Write-Host "===================================================================================================" + Write-Host "`nPlease select an option:`n" -ForegroundColor "Yellow" + Write-Host " 1 - Backup specific folder" + Write-Host " 2 - Backup from list" + Write-Host " 3 - Settings" + Write-Host "`n 0 - Exit`n" -ForegroundColor "Gray" + $MenuOption = Read-Host "Option" + + Write-Host "`n===================================================================================================" + + Switch ($MenuOption) { + 1 { + Write-Host "`nPlease enter the full path of the folder you wish to backup:`n" -ForegroundColor "Yellow" + $InputPath = (Read-Host "Input Path").Trim() + Write-Host "`n---------------------------------------------------------------------------------------------------" + Write-Host "`nPlease enter the full path of the location you wish to save the backup:`n" -ForegroundColor "Yellow" + $OutputPath = (Read-Host "Output Path").Trim() + Write-Host "`n---------------------------------------------------------------------------------------------------" + Write-Host "`n[Optional] Enter the archive file format you wish to compress the backup to:`n" + $OutputFormat = (Read-Host "File Format").Trim() + Write-Host "`n---------------------------------------------------------------------------------------------------" + + BackupFolder "$InputPath" "$OutputPath" + PauseScript + + $MenuOption = 99 + } + 2 { + + + $MenuOption = 99 + } + 3 { + + + $MenuOption = 99 + } + 0 { + Clear-Host + Exit + } + Default { + Write-Host "`nPlease enter a valid option." -ForegroundColor "Red" + PauseScript + } + } + } } From a9d87c653203048cba79b6faa571e39247565ec0 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Mon, 4 Jun 2018 23:29:14 -0400 Subject: [PATCH 21/28] Added some logging and worked on GUI --- backup.ps1 | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index aa53e96..e7b7974 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -251,7 +251,6 @@ Function BackupFolder { If ((Test-Path "$InputFolder" -PathType Container) -eq $False) { Write-Host "`n[ERROR] Provided input path does not exist or is not a folder." -ForegroundColor "Red" -BackgroundColor "Black" - PauseScript $Script:BackupFolderStatus = $False Return } @@ -265,7 +264,6 @@ Function BackupFolder { } Else { Write-Host "`n[ERROR] No valid output folder was provided." -ForegroundColor "Red" -BackgroundColor "Black" - PauseScript $Script:BackupFolderStatus = $False Return } @@ -300,12 +298,13 @@ Function BackupFolder { Write-Verbose "7-Zip command: $7zipCommand" If ($Verbose7Zip -eq $True) { - Invoke-Expression "$7ZipCommand" + Invoke-Expression "$7ZipCommand" | Tee-Object "$TempFolder\powershell-backup_log.log" -Append } Else { - Invoke-Expression "$7ZipCommand" | Out-Null + Invoke-Expression "$7ZipCommand" | Out-File "$TempFolder\powershell-backup_log.log" -Append } - PauseScript + + Write-Host "`nCompression to ""$OutputFileName"" complete." -ForegroundColor "Yellow" } @@ -319,7 +318,6 @@ Function BackupFromFile { If ((Test-Path "$InputFile") -eq $False) { Write-Host "`n[ERROR] Provided input file does not exist." -ForegroundColor "Red" -BackgroundColor "Black" - PauseScript $Script:BackupFromFileStatus = $False Return } @@ -331,7 +329,6 @@ Function BackupFromFile { If ($BackupToArray.Count -eq 1) { Write-Host "`n[ERROR] No output folder paths listed under '[Backup To]'." -ForegroundColor "Red" -BackgroundColor "Black" - PauseScript $Script:BackupFromFileStatus = $False Return } @@ -352,10 +349,11 @@ Function BackupFromFile { } Else { Write-Host "`n[ERROR] No input folder paths listed under '[Backup From]'." -ForegroundColor "Red" -BackgroundColor "Black" - PauseScript $Script:BackupFromFileStatus = $False Return } + + Write-Host "`nBatch job complete." -ForegroundColor "Yellow" } @@ -436,17 +434,18 @@ Function MainMenu { Write-Host "`n---------------------------------------------------------------------------------------------------" BackupFolder "$InputPath" "$OutputPath" - PauseScript + PauseScript $MenuOption = 99 } 2 { + BackupFromFile "$BackupListFile" - + PauseScript $MenuOption = 99 } 3 { - + SettingsMenu $MenuOption = 99 } @@ -497,6 +496,12 @@ If ($CheckForUpdates -eq $True -and $Install -eq $False) { UpdateScript } +If ((Test-Path "$TempFolder\powershell-backup_log.log") -eq $True) { + If ((Get-ChildItem "$TempFolder\powershell-backup_log.log").Length -gt 25000000) { + Remove-Item -Path "$TempFolder\powershell-backup_log.log" + } +} + If ((Test-Path "$BinFolder\7za.exe") -eq $False -and $Install -eq $False) { Write-Host "`n7-Zip .exe not found. Downloading and installing to: ""$BinFolder"" ...`n" -ForegroundColor "Yellow" Download7Zip @@ -509,7 +514,6 @@ Else { MainMenu } - Write-Host "End of Script" PauseScript Exit From cab6199dcc36d82a7e89b9f8fd11a4d84b628e99 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Sun, 10 Jun 2018 16:11:54 -0400 Subject: [PATCH 22/28] Wrote more of the GUI Mostly finished the GUI. Testing now. --- backup.ps1 | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index e7b7974..4b28145 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -161,7 +161,6 @@ Function ScriptInitialization { Function InstallScript { If ($PSScriptRoot -eq "$InstallLocation") { Write-Host "`nPowerShell-Backup files are already installed." - PauseScript } Else { $MenuOption = Read-Host "`nInstall PowerShell-Backup to ""$InstallLocation""? [y/n]" @@ -187,7 +186,6 @@ Function InstallScript { DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/README.md" "$RootFolder\README.md" Write-Host "`nInstallation complete. Please restart the script." -ForegroundColor "Yellow" - PauseScript Exit } } @@ -225,7 +223,6 @@ Function UpdateScript { Write-Host "`nUpdate complete. Please restart the script." -ForegroundColor "Yellow" - PauseScript Exit } } @@ -234,7 +231,6 @@ Function UpdateScript { } Else { Write-Host "`n[ERROR] Script version mismatch. Re-installing the script is recommended." -ForegroundColor "Red" -BackgroundColor "Black" - PauseScript } } @@ -407,11 +403,10 @@ Function CommandLineMode { Function MainMenu { $MenuOption = 99 While ($MenuOption -ne 1 -and $MenuOption -ne 2 -and $MenuOption -ne 3 -and $MenuOption -ne 0) { - $URL = "" Clear-Host - Write-Host "===================================================================================================" - Write-Host " PowerShell-Backup v$RunningVersion " -ForegroundColor "Yellow" - Write-Host "===================================================================================================" + Write-Host "==========================================================================================" + Write-Host " PowerShell-Backup v$RunningVersion " -ForegroundColor "Yellow" + Write-Host "==========================================================================================" Write-Host "`nPlease select an option:`n" -ForegroundColor "Yellow" Write-Host " 1 - Backup specific folder" Write-Host " 2 - Backup from list" @@ -464,7 +459,44 @@ Function MainMenu { Function SettingsMenu { - + $MenuOption = 99 + While ($MenuOption -ne 1 -and $MenuOption -ne 2 -and $MenuOption -ne 0) { + Clear-Host + Write-Host "==========================================================================================" + Write-Host " Settings Menu " -ForegroundColor "Yellow" + Write-Host "==========================================================================================" + Write-Host "`nPlease select an option:`n" -ForegroundColor "Yellow" + Write-Host " 1 - Update backup.ps1 script file" + If ($PSScriptRoot -ne "$InstallLocation") { + Write-Host " 2 - Install script to: ""$InstallLocation""" + } + Write-Host "`n 0 - Return to Main Menu`n" -ForegroundColor "Gray" + $MenuOption = Read-Host "Option" + + Write-Host "`n===================================================================================================" + + Switch ($MenuOption) { + 1 { + UpdateScript + + PauseScript + $MenuOption = 99 + } + 2 { + InstallScript + + PauseScript + $MenuOption = 99 + } + 0 { + Return + } + Default { + Write-Host "`nPlease enter a valid option." -ForegroundColor "Red" + PauseScript + } + } + } } From e174e54c69571111b30fe28a8c755edbc93f73f0 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Sun, 10 Jun 2018 16:27:12 -0400 Subject: [PATCH 23/28] Add files via upload --- PowerShell-Backup.lnk | Bin 0 -> 2367 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 PowerShell-Backup.lnk diff --git a/PowerShell-Backup.lnk b/PowerShell-Backup.lnk new file mode 100644 index 0000000000000000000000000000000000000000..68e04ffe6d2cecccf4cc31589a9d8c31e805ace5 GIT binary patch literal 2367 zcmds3O-NKx6#m8xl?o@AA}#DCj$!Fb6I3Mn^QRn4r+JzMFHmQmIygF$Z&HUKj3~j4 zwJ0J8#6?7lepZ5DOq*6MDk$0n5rhzAwQ$iQ?K^Lr(XokI)W-Yf+;i`{_kHKP=bU@* zGyFK3oj-hcSY7T1kq=}uSIOB<>(@SWqf*!)EO&E~*P_xt7- z%BO0-ee!K4_Li33$-%ywYCSP&x#2;X)tPZUbK247@An0VOdLQa((&cVT=kV)8QH@* zA&cK?b8YaWA3g*z1e3G2;#2~0ywDCUVup>r^8LWU1m;y@ju#4MR+boFjj16*tS}7p zp&a}a+t9OwI#=x|CeMbZ+UB;4r0!0jI*MgXP_s9sLQQ7swip{2fJSTs0X|~Km0&+j ze+-tXr9j0B8#AtH%NzETHU{~%3Vs3yQOTS^I&r+UML{SyWDJ-+Mj)UX!v<(4=HXG- zy#W#7J^CY^wdE4(cnKw#nhB;V84pu{JjwuN2SxlSx{@O09A!IY9p&rTjY&JTc1CNd zJE3S=Etn8X@z&!}iob9RTTR&N;sSj&dlep>XWUIFjFb3J!BKR;i(bADv6srf3g>&t z*3TJX&XLSfa155lDCy)Oc`I4)t8aJ1 zNoJ-s>gJ3fy2v=dzLVUv6)Q2>Pi3hj$tNC^pw5b#mp%#;E6DZBcLBD&T#5KFLQWmD zDxNJt{gOom`Tv-Wj?NYFQfbv>?&f0`?X2{whx~$M8(Z^gZ!ddI_NmJF$v$#0;cUQ! zGnQ7KU@+{|&836jZ&Qr9x)#dsy=nf(++7QvTU%?8vv_0;TD=WO)aI{-`&v}2^%FLuhlQ8%g8AHeEsmFuKDPpw4&aRTPmiD zYG*fJI`Ss(UHjdp3NQ1CY|P^(A0G-V+~sN`?>yidH*q7+DlbnVA5RMfHP)GB zT4$ErJ~158RTm<$|1Z*Ex&5JWVIc#^iFK`-aMm3qH@e((%Vh-M4 Date: Sun, 10 Jun 2018 16:28:46 -0400 Subject: [PATCH 24/28] Small fixes from testing --- backup.ps1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backup.ps1 b/backup.ps1 index 4b28145..a00f151 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -186,6 +186,7 @@ Function InstallScript { DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/README.md" "$RootFolder\README.md" Write-Host "`nInstallation complete. Please restart the script." -ForegroundColor "Yellow" + PauseScript Exit } } @@ -222,7 +223,7 @@ Function UpdateScript { Remove-Item "$TempFolder\UpdateNotes.txt" Write-Host "`nUpdate complete. Please restart the script." -ForegroundColor "Yellow" - + PauseScript Exit } } @@ -404,9 +405,9 @@ Function MainMenu { $MenuOption = 99 While ($MenuOption -ne 1 -and $MenuOption -ne 2 -and $MenuOption -ne 3 -and $MenuOption -ne 0) { Clear-Host - Write-Host "==========================================================================================" - Write-Host " PowerShell-Backup v$RunningVersion " -ForegroundColor "Yellow" - Write-Host "==========================================================================================" + Write-Host "===================================================================================================" + Write-Host " PowerShell-Backup v$RunningVersion " -ForegroundColor "Yellow" + Write-Host "===================================================================================================" Write-Host "`nPlease select an option:`n" -ForegroundColor "Yellow" Write-Host " 1 - Backup specific folder" Write-Host " 2 - Backup from list" @@ -421,7 +422,7 @@ Function MainMenu { Write-Host "`nPlease enter the full path of the folder you wish to backup:`n" -ForegroundColor "Yellow" $InputPath = (Read-Host "Input Path").Trim() Write-Host "`n---------------------------------------------------------------------------------------------------" - Write-Host "`nPlease enter the full path of the location you wish to save the backup:`n" -ForegroundColor "Yellow" + Write-Host "`nPlease enter the full path of the folder you wish to save the backup:`n" -ForegroundColor "Yellow" $OutputPath = (Read-Host "Output Path").Trim() Write-Host "`n---------------------------------------------------------------------------------------------------" Write-Host "`n[Optional] Enter the archive file format you wish to compress the backup to:`n" @@ -462,9 +463,9 @@ Function SettingsMenu { $MenuOption = 99 While ($MenuOption -ne 1 -and $MenuOption -ne 2 -and $MenuOption -ne 0) { Clear-Host - Write-Host "==========================================================================================" - Write-Host " Settings Menu " -ForegroundColor "Yellow" - Write-Host "==========================================================================================" + Write-Host "===================================================================================================" + Write-Host " Settings Menu " -ForegroundColor "Yellow" + Write-Host "===================================================================================================" Write-Host "`nPlease select an option:`n" -ForegroundColor "Yellow" Write-Host " 1 - Update backup.ps1 script file" If ($PSScriptRoot -ne "$InstallLocation") { From 6195924c4204ad12bec7408afaefc7e3281fa5b2 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Sun, 10 Jun 2018 16:37:29 -0400 Subject: [PATCH 25/28] Delete PowerShell-Backup.lnk --- PowerShell-Backup.lnk | Bin 2367 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 PowerShell-Backup.lnk diff --git a/PowerShell-Backup.lnk b/PowerShell-Backup.lnk deleted file mode 100644 index 68e04ffe6d2cecccf4cc31589a9d8c31e805ace5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2367 zcmds3O-NKx6#m8xl?o@AA}#DCj$!Fb6I3Mn^QRn4r+JzMFHmQmIygF$Z&HUKj3~j4 zwJ0J8#6?7lepZ5DOq*6MDk$0n5rhzAwQ$iQ?K^Lr(XokI)W-Yf+;i`{_kHKP=bU@* zGyFK3oj-hcSY7T1kq=}uSIOB<>(@SWqf*!)EO&E~*P_xt7- z%BO0-ee!K4_Li33$-%ywYCSP&x#2;X)tPZUbK247@An0VOdLQa((&cVT=kV)8QH@* zA&cK?b8YaWA3g*z1e3G2;#2~0ywDCUVup>r^8LWU1m;y@ju#4MR+boFjj16*tS}7p zp&a}a+t9OwI#=x|CeMbZ+UB;4r0!0jI*MgXP_s9sLQQ7swip{2fJSTs0X|~Km0&+j ze+-tXr9j0B8#AtH%NzETHU{~%3Vs3yQOTS^I&r+UML{SyWDJ-+Mj)UX!v<(4=HXG- zy#W#7J^CY^wdE4(cnKw#nhB;V84pu{JjwuN2SxlSx{@O09A!IY9p&rTjY&JTc1CNd zJE3S=Etn8X@z&!}iob9RTTR&N;sSj&dlep>XWUIFjFb3J!BKR;i(bADv6srf3g>&t z*3TJX&XLSfa155lDCy)Oc`I4)t8aJ1 zNoJ-s>gJ3fy2v=dzLVUv6)Q2>Pi3hj$tNC^pw5b#mp%#;E6DZBcLBD&T#5KFLQWmD zDxNJt{gOom`Tv-Wj?NYFQfbv>?&f0`?X2{whx~$M8(Z^gZ!ddI_NmJF$v$#0;cUQ! zGnQ7KU@+{|&836jZ&Qr9x)#dsy=nf(++7QvTU%?8vv_0;TD=WO)aI{-`&v}2^%FLuhlQ8%g8AHeEsmFuKDPpw4&aRTPmiD zYG*fJI`Ss(UHjdp3NQ1CY|P^(A0G-V+~sN`?>yidH*q7+DlbnVA5RMfHP)GB zT4$ErJ~158RTm<$|1Z*Ex&5JWVIc#^iFK`-aMm3qH@e((%Vh-M4 Date: Sun, 10 Jun 2018 16:38:21 -0400 Subject: [PATCH 26/28] Add files via upload --- install/files/PowerShell-Backup.lnk | Bin 2385 -> 2385 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/install/files/PowerShell-Backup.lnk b/install/files/PowerShell-Backup.lnk index 20f6bb6a60b75059256e95d23e67e435ebd203b1..637c98b865dbf3fe2b63ab6ad53fc9f25a39b27a 100644 GIT binary patch delta 13 Vcmca8bWv!-L=MK3$&)zt0{|xM1z`XH delta 13 Vcmca8bWv!-L=MLE$&)zt0{|xb1!MpK From b9cfd334213ef6022de90ceb08226b6920da4ac9 Mon Sep 17 00:00:00 2001 From: Matt Bittner Date: Sun, 10 Jun 2018 16:38:36 -0400 Subject: [PATCH 27/28] Add files via upload --- PowerShell-Backup - Portable Version.lnk | Bin 2207 -> 2207 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/PowerShell-Backup - Portable Version.lnk b/PowerShell-Backup - Portable Version.lnk index d1d6dd4e0f1401b8ffd1b6e208db86c73bc71f28..c7363b967c23df9ba08252a6f1428d5a0fe773be 100644 GIT binary patch delta 13 VcmbO)IA3tXeRjr_$q(4~0{|s=1(g5* delta 13 VcmbO)IA3tXeRjt5$q(4~0{|t41(*N; From aa30aae19238aebe441e740609a08cc8ec40eeb6 Mon Sep 17 00:00:00 2001 From: mpb10 Date: Mon, 13 Aug 2018 23:36:11 -0400 Subject: [PATCH 28/28] Updated README.md and finished setup for release. --- README.md | 47 ++++++++++++++++++++++++++++++++--- backup.ps1 | 30 +++++++++++----------- install/files/UpdateNotes.txt | 2 ++ 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ac01f57..ae7e8ed 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # PowerShell-Backup-Script https://github.com/mpb10/PowerShell-Backup-Script -A PowerShell script used to backup files. +A PowerShell script used to back up files and folders. -**Author: Matt Bittner** +**Author: mpb10** -**May 9th, 2018** +**August 13th, 2018** **v2.0.0** @@ -21,12 +21,51 @@ A PowerShell script used to backup files. # INSTALLATION +**Script download link:** https://github.com/mpb10/PowerShell-Backup/releases/download/v2.0.0/PowerShell-Backup-v2.0.0.zip + +**Requires:** PowerShell 5.0 or greater* + + *Version 5.0 of PowerShell comes pre-installed with Windows 10 but otherwise can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=50395 + +# + +**To Install:** + +1. Ensure that you have PowerShell Version 5.0 or greater installed. +2. Download the release .zip file and extract it to a folder. +3. Run the 'Installer' shortcut located in the `\install` folder (or run the the script using the 'PowerShell-Backup - Portable Version' shortcut, navigate to the settings menu, and choose the `2 - Install script to:` option). + +A desktop shortcut and a Start Menu shortcut will be created. Run either of those to use the script. The install location is `C:\Users\%USERNAME%\Scripts\PowerShell-Backup`. + +# + +To uninstall this script and its files, delete the two folders `C:\Users\%USERNAME%\Scripts\PowerShell-Backup` and `%APPDATA%\Microsoft\Windows\Start Menu\Programs\PowerShell-Backup` and the desktop shortcut. + # USAGE +Run either the desktop shortcut or the Start Menu shortcut. Use option 1 of the main menu to backup a single folder. Use option 2 and the `Backuplist.txt` file to backup multiple folders at once in a batch job. + +Upon being ran for the first time, the script will generate the `BackupList.txt` file in the `\config` folder. To use option `2 - Backup from list` of the main menu, list folder paths under their respective stanzas in the `BackupList.txt` file, save it, and then run option 2 of the script. + # CHANGE LOG + 2.0.0 August 13th, 2018 + Re-wrote the script in the likeness of PowerShell-Youtube-dl. Cleaned up code. + Can backup individual folders or use the BackupList.txt file to run batch jobs. + Implemented some logging to the temp folder. + + 1.1.1 June 23rd, 2017 + Uploaded to Github. + Condensed installer to one PowerShell script. + Edited documentation. + + 1.1.0 June 12th, 2017 + Added ability to back up folders listed in backuplist.txt. + # ADDITIONAL NOTES -This script uses the 7-Zip program to compress folders for backing up. 7-Zip is licensed under the GNU LGPL license and its source code can be found at http://www.7-zip.org/. +**NOTE:** This script utilizes 7-zip command line version 9.20 executable file. This version of 7-zip has been identified as being vulnerable to multiple code execution exploits via crafted archive files. Since the executable is only used to create archives, the danger these vulnerabilities pose are negligable as long as the 7-zip executable is only used by the script to create archives. This version of 7-zip is only used because of its ability to be easily downloaded and installed. To easily mitigate the vulnerabilities found in version 9.20, simply download 7-zip version 18.05 or higher and copy the file `7z.exe` to the `\bin` directory. + +This script uses the 7-Zip program to compress folders for backing up. 7-Zip is licensed under the GNU LGPL license and its source code can be found at https://www.7-zip.org/. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/backup.ps1 b/backup.ps1 index a00f151..14c1d3d 100644 --- a/backup.ps1 +++ b/backup.ps1 @@ -40,7 +40,7 @@ .NOTES Requires PowerShell version 5.0 or greater. Author: mpb10 - Updated: May 16th, 2018 + Updated: August 13th, 2018 Version: 2.0.0 .LINK https://github.com/mpb10/PowerShell-Backup @@ -99,7 +99,7 @@ $BackupFromFileStatus = $True # Function for simulating the 'pause' command of the Windows command line. Function PauseScript { - If ($PSBoundParameters.Count -eq 0) { + If ($CommandLine -eq $False) { Write-Host "`nPress any key to continue ...`n" -ForegroundColor "Gray" $Wait = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") } @@ -152,7 +152,7 @@ Function ScriptInitialization { $Script:BackupListFile = $ConfigFolder + "\BackupList.txt" If ((Test-Path "$BackupListFile") -eq $False) { - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/BackupList.txt" "$ConfigFolder\BackupList.txt" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/install/files/BackupList.txt" "$ConfigFolder\BackupList.txt" } } @@ -179,11 +179,11 @@ Function InstallScript { Copy-Item "$PSScriptRoot\backup.ps1" -Destination "$RootFolder" - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/PowerShell-Backup.lnk" "$RootFolder\PowerShell-Backup.lnk" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/install/files/PowerShell-Backup.lnk" "$RootFolder\PowerShell-Backup.lnk" Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$DesktopFolder\PowerShell-Backup.lnk" Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$StartFolder\PowerShell-Backup.lnk" - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/LICENSE" "$RootFolder\LICENSE.txt" - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/README.md" "$RootFolder\README.md" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/LICENSE" "$RootFolder\LICENSE.txt" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/README.md" "$RootFolder\README.md" Write-Host "`nInstallation complete. Please restart the script." -ForegroundColor "Yellow" PauseScript @@ -195,7 +195,7 @@ Function InstallScript { Function UpdateScript { - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/version-file" "$TempFolder\version-file.txt" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/install/files/version-file" "$TempFolder\version-file.txt" [Version]$NewestVersion = Get-Content "$TempFolder\version-file.txt" | Select -Index 0 Remove-Item -Path "$TempFolder\version-file.txt" @@ -204,21 +204,21 @@ Function UpdateScript { $MenuOption = Read-Host "`nUpdate to this version? [y/n]" If ($MenuOption.Trim() -like "y" -or $MenuOption.Trim() -like "yes") { - DownloadFile "http://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/backup.ps1" "$RootFolder\backup.ps1" + DownloadFile "http://github.com/mpb10/PowerShell-Backup/raw/master/backup.ps1" "$RootFolder\backup.ps1" If ($PSScriptRoot -eq "$InstallLocation") { If ((Test-Path "$StartFolder") -eq $False) { New-Item -Type Directory -Path "$StartFolder" | Out-Null } - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/Youtube-dl.lnk" "$RootFolder\PowerShell-Backup.lnk" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/install/files/Youtube-dl.lnk" "$RootFolder\PowerShell-Backup.lnk" Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$DesktopFolder\PowerShell-Backup.lnk" Copy-Item "$RootFolder\PowerShell-Backup.lnk" -Destination "$StartFolder\PowerShell-Backup.lnk" - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/LICENSE" "$RootFolder\LICENSE.txt" - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/README.md" "$RootFolder\README.md" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/LICENSE" "$RootFolder\LICENSE.txt" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/README.md" "$RootFolder\README.md" } - DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/version-2.0.0/install/files/UpdateNotes.txt" "$TempFolder\UpdateNotes.txt" + DownloadFile "https://github.com/mpb10/PowerShell-Backup/raw/master/install/files/UpdateNotes.txt" "$TempFolder\UpdateNotes.txt" Get-Content "$TempFolder\UpdateNotes.txt" Remove-Item "$TempFolder\UpdateNotes.txt" @@ -531,7 +531,7 @@ If ($CheckForUpdates -eq $True -and $Install -eq $False) { If ((Test-Path "$TempFolder\powershell-backup_log.log") -eq $True) { If ((Get-ChildItem "$TempFolder\powershell-backup_log.log").Length -gt 25000000) { - Remove-Item -Path "$TempFolder\powershell-backup_log.log" + Get-Content "$TempFolder\powershell-backup_log.log" | Select-Object -Skip 50000 | Out-File "$TempFolder\powershell-backup_log.log" } } @@ -541,14 +541,14 @@ If ((Test-Path "$BinFolder\7za.exe") -eq $False -and $Install -eq $False) { } If (($PSBoundParameters.Count) -gt 0) { + $CommandLine = $True CommandLineMode } Else { + $CommandLine = $False MainMenu } -Write-Host "End of Script" -PauseScript Exit diff --git a/install/files/UpdateNotes.txt b/install/files/UpdateNotes.txt index 9a3b826..ed43a5d 100644 --- a/install/files/UpdateNotes.txt +++ b/install/files/UpdateNotes.txt @@ -6,5 +6,7 @@ 1. Re-wrote the script in the likeness of PowerShell-Youtube-dl. Cleaned up code. 2. Can backup individual folders or use the BackupList.txt file to run batch jobs. + + 3. Implemented some logging to the temp folder. =================================================================================================== \ No newline at end of file