1С бэкап базы с помощью PowerShell

Создаем папку C:\distr\it_dept

Создаем текстовый документ и размещаем его в C:\distr\backup_it_dept_dt.ps1

$date = get-date
$DateStr = $date.ToString("yyyy-MM-dd")

Write-Host($DateStr)

$server1c = "ИмяСервера1С"
$base1c = "ИмяБазы1С"
$user = '"Пользователь 1С"'
$pwd = '"ПарольПользователя"'
$backup_dest = "C:\distr"
$dest = $backup_dest + "\" + $base1c + "\" + $base1c + "_" + $DateStr + ".dt"
$log  = $backup_dest + "\" + $base1c + "\" + $base1c + "_" + $DateStr + ".log"

$cestart = '"C:\Program Files\1cv8\common\1cestart.exe"'
$params = ' CONFIG /S' + $server1c + '\' + $base1c + ' /N' + $user + ' /P' + $pwd + ' /Out' + $log + ' /DumpIB' + $dest

# $bak_command = $cestart + $params

$Connector = New-Object -comObject V83.ComConnector
$Agent = $Connector.ConnectAgent($server1c)
$Cluster = $Agent.GetClusters().GetValue(0)
$Agent.Authenticate($Cluster, "", "")
$Processes = $Agent.GetWorkingProcesses($Cluster);
# echo $Processes

$Bases = $Agent.GetInfoBases($Cluster)
# echo $Bases

ForEach ($Base in $Bases) {
    # write-host($Base.name)
    if($Base.name -eq $base1c){
        # write-host($Base.name)
        $Sessions = $Agent.GetInfoBaseSessions($Cluster, $Base);
        ForEach ($Session in $Sessions){
        $Agent.TerminateSession($Cluster, $Session);
        }
    }
}

Start-Process $cestart $params

Планировщик заданий

  • Действие: Запуск команды

powershell

  • Программа или сценарий
  • Добавить аргументы

-ExecutionPolicy bypass -File "C:\distr\backup_it_dept_dt.ps1"

Проверяем