Avatar of bts86
bts86
 asked on

Powershell Arguements

I am trying to utilize a powershell plugin for amazon s3 to schedule synchronizations of backup files from a local folder to s3.

I can make it work if I make a script for each folder I want to sync but what I'd like to do is pass an argument from the command line to select the local and remote folders that the job should sync.

I'm sure this is pretty basic, but my scripting abilities are minimal.

Here is what I have, but does not work:

*********************************************************
$server=$args[0]
Set-Logging -LogPath S:\ps-log -LogLevel info
Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn
$s3 = Get-CloudS3Connection -Key XXXXXXXX -Secret XXXXXXXXX
$dest = $s3 | Select-CloudFolder -Path "phxbackup02/VMbackups/" + $server + "@10.99.0.25"
$src = Get-CloudFilesystemConnection | Select-CloudFolder "S:\Local_Backup\" + $server + "@10.99.0.25\"
Set-CloudOption -UseChunks 1 -ChunkSizeKB 1024000
$src | Copy-CloudSyncFolders $dest -IncludeSubfolders -DeleteOnTarget
*********************************************************************

My problems are on lines 5-6

I just want to be able to change 1 piece of both paths as the $server variable, for example, if I use the command .\script.ps1 "DC01"

Do I need to create 2 more variables for the source and destination paths?
Something like $s3path = "phxbackup02/VMbackups/" + $server + "@10.99.0.25" ?
Powershell

Avatar of undefined
Last Comment
bts86

8/22/2022 - Mon
Qlemo

It should already work that way. Source and destination path both contain the server name provided as a parameter to the script as you showed.
.\script.ps1 "DC01"  will backup "S:\Local_Backup\DC01@10.99.0.25\" to "phxbackup02/VMbackups/DC01@10.99.0.25"
ASKER CERTIFIED SOLUTION
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bts86

ASKER
Ive tried both suggested ways and still have the same result.

Here is the error I receive:

Select-CloudFolder : The path specified doesn't exist.
At C:\backupsyncs3.ps1:6 char:40
+ $src = Get-CloudFilesystemConnection | Select-CloudFolder "S:\Local_Backup\$serv ...
+                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (S:\Local_Backup\@10.99.0.25\:String) [Select-CloudFolder], Exception
    + FullyQualifiedErrorId : The path specified doesn't exist.,CloudBerryLab.Explorer.PSSnapIn.Commands.SelectCloudFo
   lder


It doesn't seem to be inserting the variable.


Would it be correct syntax if I used this:
$s3path = ("phxbackup02/VMbackups/" + $server + "@10.99.0.25")
$localpath = ("S:\Local_Backup\" + $server + "@10.99.0.25\")
$dest = $s3 | Select-CloudFolder -Path $s3path
$src = Get-CloudFilesystemConnection | Select-CloudFolder $localpath

Open in new window

Qlemo

It does insert the variable, otherwise you would see the var name literally in the path string. $server just is empty.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bts86

ASKER
Ive got it working using variables for the paths. Maybe the PS snapin does not like concatenation.

Here is what I used to make it work:
$server=$args[0]
Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn
Set-Logging -LogPath S:\ps-log\cloudberry.log -LogLevel info
$s3 = Get-CloudS3Connection -Key xxxxxxxxxxxxxxxxx -Secret xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$s3path = ("phxbackup02/VMbackups/" + $server + "@10.99.0.25")
$localpath = ("S:\Local_Backup\" + $server + "@10.99.0.25\")
$dest = $s3 | Select-CloudFolder -Path $s3path
$src = Get-CloudFilesystemConnection | Select-CloudFolder $localpath
Set-CloudOption -UseChunks 1 -ChunkSizeKB 1024000
$src | Copy-CloudSyncFolders $dest -IncludeSubfolders -DeleteOnTarget

Open in new window


Thanks for the help, will split the credit.