forked from voiplab/Misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_backup_7z_to_yandex_disk_via_webdav
33 lines (28 loc) · 1.13 KB
/
upload_backup_7z_to_yandex_disk_via_webdav
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
#Uploading last backup to Yandex Disk via WebDAV
Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host
$pathToYandexDisk = "Z:\"
$pathToBackups = "D:\Backup\"
try
{
if (-Not([System.IO.Directory]::Exists($pathToYandexDisk)))
{
Write-Host "Mounting Yandex Disk"
net use Z: "https://webdav.yandex.ru/backup/" /User:!!!USERNAME!!!@yandex.ru !!!PASSWORD!!!
}
Start-Sleep -s 2
if([System.IO.Directory]::Exists($pathToYandexDisk))
{
Get-ChildItem -Path $pathToBackups -Filter "*.7z" | Sort-Object LastAccessTime -Descending | Select-Object -First 1 | % {
$pathToLastBackup = "$pathToBackups\$_"
$pathToYandexDiskBackup = "$pathToYandexDisk\$_"
Write-Host "Uploading : $pathToLastBackup -> $pathToYandexDiskBackup"
[System.IO.File]::Copy($pathToLastBackup,$pathToYandexDiskBackup)
Write-Host "Done : $pathToLastBackup -> Yandex.Disk"
net use Z: /delete
}
}
}
catch
{
net use Z: /delete
}