📜 ⬆️ ⬇️

Automate the copying of large files.

Probably some of the colleague administrators faced such a problem when, due to lack of system resources, the windows platform refuses to copy large files with built-in tools (usually these are 60 + Gb backup files), say from one disk to another, the Robocopy utility does not help either from Sysinternals. I propose to solve this problem using the KillCopy utility, and in order to not have to work with your hands, we will create a simple script, since the utility allows you to work with it from the command line:


@ECHO off

ECHO ==========================
ECHO Keys:
ECHO r -retry on any error
ECHO n-start KillCopy in minimized state
ECHO m -move files
ECHO x -don't delete! List filelist
ECHO u-try resume if target file exists.
ECHO ==========================
')
SET BCKP_FLDR = <folder where we copy>
SET DST_FLDR = <folder where we copy>

rem set the path in which the list of copied files will be created, and also set the killcopy parameters.
SET BCKP_LIST = C: \ backuplist.txt
SET copyParm = -rnmxu

rem set the path where the history file and the killcopy log are stored
SET CHECK_FILE = C: \ Progra ~ 1 \ KillSoft \ KillCopy \ history.txt
SET CHECK_LOG = C: \ Scripts \ killcopycheck.txt

echo Getting Directories list ...

dir "% BCKP_FLDR%" / b / s / a: d> "% BCKP_LIST%"

echo Starting KillCopy% DATE%% TIME%

echo Copying files ...
kc.exe% BCKP_LIST%% DST_FLDR%% copyParm%

rem parsim history file:
echo Parsing Killcopy Log ...
findstr / i. "% CHECK_FILE%" >> "% CHECK_LOG%"

echo Sending log via e-mail ...
wscript c: \ scripts \ Email_ME.vbs "% CHECK_LOG%" "Killcopy Check Result"

rem echo Deleting temporary files ...
del / q "% CHECK_LOG%"
del / q "% BCKP_LIST%"
del / q "% CHECK_FILE%"



Below I attach a standard vbs-script for emailing copy results:
Dim ArgObj
Set ArgObj = WScript.Arguments

Dim sFileName
Dim sMsgSubject

sFileName = ArgObj.Item (0)
sMsgSubject = ArgObj.Item (1)

Function GetTxtFileContent (sFilePath)
Dim fso, txtStream
Dim sRes

Set fso = CreateObject ("Scripting.FileSystemObject")
Set txtStream = fso.OpenTextFile (sFilePath, 1)
sRes = txtStream.ReadAll

GetTxtFileContent = sRes
End function

Set objEmail = CreateObject ("CDO.Message")
objEmail.From = "from"
objEmail.To = “to”
objEmail.BodyPart.Charset = "koi8-r"
objEmail.Subject = sMsgSubject
objEmail.Textbody = GetTxtFileContent (sFileName)
objEmail.Configuration.Fields.Item _
(" Schemas.microsoft.com/cdo/configuration/sendusing ") = 2
objEmail.Configuration.Fields.Item _
(" Schemas.microsoft.com/cdo/configuration/smtpserver ") = _
"Server smtp address"
objEmail.Configuration.Fields.Item _
(" Schemas.microsoft.com/cdo/configuration/smtpserverport ") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

I hope my experience will help colleagues in their daily work.

Source: https://habr.com/ru/post/37659/


All Articles