This repository has been archived on 2024-09-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
powershell_backupscript/lib/backupscript-clone.psm1
2021-01-15 12:19:10 +01:00

46 lines
No EOL
1.3 KiB
PowerShell

function Backup-Create () {
Param(
[Parameter(Mandatory=$True)]
[string]
$source,
[Parameter(Mandatory=$True)]
[string]
$dest,
[Parameter(Mandatory=$false)]
[string]
$name,
[Parameter(Mandatory=$false)]
[object]
$options
)
$copy_opt = "--stats=0 --log-level INFO --log-format `"shorfile`" "
Set-Message "Sync files from $source to $dest"
if ( -not (Test-Path "$global:bin_path\rclone.exe") ) {
Throw "Rclone executable not found"
}
$copy_opt = -join($copy_opt, $(ConvertTo-CmdlineOptions $options))
$command = -join($global:bin_path, "\rclone.exe", " sync", " `"$source`"", " `"$dest`"", " $copy_opt", " 2>&1")
Set-Message "$command"
Invoke-Expression $command -ErrorAction Ignore | % {
if ($_ -ne ""){
$type, $mdg = ($_ -split ':')[0]
$msg = -join ($_ -split ':')[1..2]
switch ( $type.trim() ){
"INFO" {
Set-Message $msg.trim()
}
"WARN" {
Set-Warning $msg.trim()
}
"ERROR" {
Set-Error $msg.trim()
}
}
}
}
}
Export-ModuleMember -Function Backup-Create