-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
deploy-sample-net8.ps1
55 lines (48 loc) · 1.68 KB
/
deploy-sample-net8.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# deploy-sample-net8.ps1
param (
[string]$sourcePath,
[string]$destinationPath,
[string]$server,
[string]$username,
[string]$privateKeyPath
)
# 复制文件到服务器
function Copy-Files {
param (
[string]$source,
[string]$destination,
[string]$server,
[string]$username,
[string]$privateKey
)
# 使用SCP命令上传文件
$scpCommand = "scp -i `${privateKey} -r `${source} `${username}@`${server}:${destination}"
Invoke-Expression $scpCommand
}
# 排除特定文件
function Exclude-Files {
param (
[string]$source,
[string]$destination
)
$filesToExclude = @("Web.Config", "appsettings.json")
foreach ($file in $filesToExclude) {
$sourceFile = Join-Path -Path $source -ChildPath $file
if (Test-Path -Path $sourceFile) {
# 将文件移动到临时路径,以便稍后恢复
$tempPath = Join-Path -Path $env:TEMP -ChildPath $file
Move-Item -Path $sourceFile -Destination $tempPath
}
}
Copy-Files -source $source -destination $destination -server $server -username $username -privateKey $privateKeyPath
# 恢复被排除的文件
foreach ($file in $filesToExclude) {
$tempPath = Join-Path -Path $env:TEMP -ChildPath $file
if (Test-Path -Path $tempPath) {
$destinationFile = Join-Path -Path $destination -ChildPath $file
Move-Item -Path $tempPath -Destination $destinationFile
}
}
}
# 调用函数
Exclude-Files -source $sourcePath -destination $destinationPath