Between two windows BAT script file transfer server

1. scripting capabilities: 

  To achieve transfer between the two file servers, for example, uploading a file from the server A to the server B

2. Implementation steps:

  2.1 server link, find the specified path, read the uploaded file, copy the file to a file name

    (Where possible need for screening a particular file, or the number of files is determined, this process would be more convenient)

  2.2 execution copy files

  2.3 delete unnecessary files

    (Considered here, it may be an online backup, leaving only part of the data file, need to delete unneeded data files, in this process)

 

3. code shows

@echo off

REM *** copy file parameter set
SET the Passwd = "password"
SET = the User "username"
SET the LogPath = "log storage path"
SET FullbakPath = "A server needs to copy the file path to the server B"

REM *** database connection settings
   (database link here to do because this is part of the script file you want to keep the number of days required to delete the file first seven days
     since the date of addition and subtraction bat single to do too much trouble, so the use of the database value method)
the SET DB_SERVER = "database RUL of"
SET the DB_NAME = "database instance"
SET DB_USER = "user database"
SET DB_PASS = "database password"

REM *** database before the 7th set
REM *** used here because other sqlserver corresponding adjustment oracle mysql database please yourself and other
set sql = "SELECT CONVERT (NVARCHAR , DATEADD (DAY, -7, CONVERT (DATETIME, CAST (YMD AS NVARCHAR), 101)), 112) FROM M_DATE_CONTROL WHERE KEY_CD = 2 "

REM *** service link
net use \\ 127.0.0.1 \ backfull% Passwd  % / user:% User%

REM *** Setting the date, set the Log log file name of
the SET DATE =% DATE: ~ 0,4 %% DATE: ~ 5,2 %% DATE: ~ 8,2%
the SET JOBLOG = DBBACK.log

echo ********** START (%date:~0,10% %time:~0,8%) ********** >> %LogPath%\%date%\%JOBLOG%

Here you will meet the attachment to read a text document, for subsequent use
(for / F "tokens = *" %% I in ( 'the dir / AD / B / S% FullbakPath% \ *. *') Do (
    echo NXI ~ %%
))> fullbak.log

Here is the main step of the copy file, read from the text document, and then copy, there is a determination of the number of files, can be self-adjusting
for / f "tokens = 2 delims =:" %% a in ( 'find / C / V "" fullbak.log ') do (
  IF EQU. 7 for %% A / F %% I in (fullbak.log) do FullbakPath the xcopy%% \ %% I \\ 127.0.0.1 \ backfull \% DATE% \ / S / E / I / Y
)

File deletion operations performed here, seven days before the deleted file
for / f "skip = 2" %% i in ( 'osql.exe -S% DB_SERVER% -U% DB_USER% -P% DB_PASS% -d% DB_NAME% %% SQL -Q is') do (
  SET the RESULT = %% I
  GOTO: the RESULT
)

Determine whether a file exists, delete it exists
: the RESULT
IF exist \\ 127.0.0.1 \ backfull \% the RESULT% RD / S / q \\ 127.0.0.1 \ backfull \% the RESULT%

echo ********** END (%date:~0,10% %time:~0,8%) ********** >> %LogPath%\%date%\%JOBLOG%

pause

More than write a text document, also please forgive me.

  

Guess you like

Origin www.cnblogs.com/sun-chao/p/11417962.html