我正在尝试使用 Cloudberry Explorer 的 PowerShell 管理单元自动将文件上传到 Glacier,但似乎无法将文件复制到我的首选目标。由于某种原因,源目录结构在 Glacier 保管库中进行了镜像。例如,发生以下情况:
- 源路径:c:\folder1\subfolder1\yyyyMMdd.tar.bz2
- 实际目标路径:us-east-1/vaultName/c:\folder1\subfolder1\yyyyMMdd.tar.bz2
- 首选目标路径:us-east-1/vaultName/yyyyMMdd.tar.bz2
关于如何改变这种行为有什么想法吗?
代码:
#get name of oldest subfolder. subfolder names are based on date they were generated yyyyMMdd
$oldestFolder = Get-ChildItem C:\folder1\subfolder1 -directory -name | Sort-Object -descending | select -last 1
$dateToProcess = $oldestFolder
$srcFolder = "C:\folder1\subfolder1\"
$dstFolder = $srcFolder
# Compress directory before transmission
$block = [scriptblock]::Create("7z a -ttar $dstFolder$dateToProcess.tar $srcFolder$dateToProcess; 7z a -tbzip2 $dstFolder$dateToProcess.tar.bz2 $dstFolder$dateToProcess.tar; del $dstFolder$dateToProcess.tar")
& $block
add-pssnapin CloudBerryLab.Explorer.PSSnapIn
# Create connection
$conn = Get-CloudGlacierConnection -UseSSL -Key [Access key] -Secret [Secret Key]
# Set options
Set-CloudOption -GlacierChunkSizeMB 4
Set-CloudOption -GlacierParallelUpload 1
$vault = $conn | Select-CloudFolder -Path "us-east-1/vaultName"
$destination = $vault
# Select source folder
$src = Get-CloudFilesystemConnection | Select-CloudFolder $srcFolder
# Upload files to Glacier by filter
$src | Copy-CloudItem -Destination $destination -Filter "$dateToProcess.tar.bz2"
答案1
而不是以下这段脚本:
$block = [scriptblock]::Create("7z a -ttar $dstFolder$dateToProcess.tar $srcFolder$dateToProcess; 7z a -tbzip2 $dstFolder$dateToProcess.tar.bz2 $dstFolder$dateToProcess.tar; del $dstFolder$dateToProcess.tar")
应该有以下内容:
$block = [scriptblock]::Create("7z a -ttar $dstFolder$dateToProcess.tar $srcFolder$dateToProcess; 7z a -tbzip2 $dateToProcess.tar.bz2 $dstFolder$dateToProcess.tar; del $dateToProcess.tar")
使用以下命令将“c:\folder1\subfolder1”添加到您的文件名中:
7z a -tbzip2 $dateToProcess.tar.bz2$目标文件夹$日期处理.tar