Last active
October 14, 2015 19:57
-
-
Save sovcik/23773e163ba07a44afc0 to your computer and use it in GitHub Desktop.
Powershell script creating snapshots from folders using 7zip archiver.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param ( | |
| # if parameter "-i" Input Path was not specified, folder from which script has been invoked will be used | |
| [string]$i = "#", | |
| # if parameter "-f" Include File was not specified, all files/folders will be processed | |
| [string]$f = "#", | |
| # parameter "-o" Output Folder is required | |
| [string]$o = "#", | |
| # parameter "-a" specifying archiver command | |
| [string]$a = 'c:\Program Files\7-zip\7z.exe' | |
| ) | |
| if(!(Test-Path $a )){ | |
| write-output "Specified archiver program does not exist: '$a'" | |
| write-output "Use parameter -a <full_archiver_name> to specify one." | |
| exit 1 | |
| } | |
| if(!(Test-Path $f )){ | |
| write-output "Specified include file does not exist: '$f'" | |
| write-output "Use parameter -f <include_file_name> to specify one." | |
| exit 2 | |
| } | |
| if(!(Test-Path -Path $i )){ | |
| write-output "Specified input folder does not exist: '$i'" | |
| write-output "Use parameter -i <input folder> to specify one." | |
| exit 2 | |
| } | |
| if($o -eq "" -or !(Test-Path -Path $o )){ | |
| write-output "Specified output folder does not exist: '$o'" | |
| write-output "Use parameter -o <output folder> to specify one." | |
| exit 2 | |
| } | |
| # change current folder to input folder so 7zip will include only relative paths | |
| cd $i | |
| # archive type - 7zip supports zip archives too, | |
| # but they do not support "delete" commend when extracting delta archive, | |
| # so it is better to use 7z archives | |
| $arctype = '-t7z' | |
| $fExt = '.7z' | |
| # update switches | |
| $upSwitches = 'p0q3x2z0' | |
| # get file handle | |
| $fi = Get-Item $f | |
| # full include filename including cmdline switches | |
| $incFile = $('-ir@' + $fi.FullName) | |
| # base archive name | |
| $baseArcName = $($o + "\" + $fi.BaseName) | |
| # archive file containing changed files | |
| $deltaArcName = $($baseArcName + " changes " + $([datetime]::now.tostring("yyMMddTHHmmss")) ) | |
| # run archiver | |
| & $a 'u' '-r' $arctype $($baseArcName+$fExt) $('-u'+$upSwitches+'!'+$deltaArcName+$fExt) $incFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment