windows - Fill backup drive with newest files -


i have 12tb (and growing) library, distributed on 3 hdds, of video files , them external harddrive. using windows 10 pro.

my backup drive has 8tb , backup newest 8tb of video files. far have tried 10 sync tools none of them allowed me copy files according creation date.

also robocopy haven't found way copy latest 8tb of files.
suggestions?

i have 2 batch scripts have asked for. main difference between them is, 1st script using where locate files use timestamp of last change. use timestamp e.g. last access or time of creation have use 2nd script attached uses dir.

1. batch script using where locate files:

it takes minimum 2 arguments:
usage: batch.bat <dst> <src_1> [<src_...> <src_n>]

it uses where /r <src_n> * /t command build list of files in subdirectories timestamp of last change in following format:

<size>   <date>          <time>    <file name>   5397   11.07.2017      14:32:09  c:\users\...\foo.txt  10860   12.07.2017      11:25:15  c:\users\...\bar.log 

the timestamp of last change if need time of creation or last access take 2nd batch script below using dir there possibility choose between different timestamps.

this output written (without column size) temporary file under temp dir %temp% (will deleted automatically after script) every source passed via argument list. complete temporary file sorted date , time, newest first.

this sorted output used copy destination folder.

example:

current directory in cmd c:\...\desktop):
batch.bat "backup_folder" "f:\folder" "f:\folder space"

current directory somewhere:
batch.bat "c:\...\desktop\backup_folder" "f:\folder" "f:\folder space"

the c:\...\desktop\backup_folder contain 2 folders folder , folder space contain files of these source folders after scripts operation.

in case batch script copy 8 tb of newest files because drive full , batch script exit because recognizes copy errors.

the batch script:

@echo off setlocal enabledelayedexpansion  rem check if @ least 2 arguments passed set invargs=0 if [%1] == [] set invargs=1 if [%2] == [] set invargs=1 if %invargs% == 1 (    echo usage: %0 ^<dst^> ^<src_1^> ^<src_...^> ^<src_n^>    goto :eof )  rem store carriage return character in cr (used spinner function, see below) /f %%a in ('copy /z "%~dpf0" nul') set "cr=%%a"  rem set temp file name set "uniquefile=%temp%\%0_%random%.tmp"  rem set destination path , shift next argument set "dstpath=%~1" shift  rem store src_1 src_n arguments src array set idx=0 :again rem if %1 blank, finished if not [%1] == [] (    if not exist "%~1" (       echo following source folder doesn't exist:       echo    "%~1"!       echo program terminate!       goto :end    )     pushd "%~1"    set "src[%idx%]=!cd!"    if [!src[%idx%]:~-1!] == [\] (       set src[%idx%]=!src[%idx%]:~0,-1!    )    set /a idx=%idx%+1    popd     rem shift arguments , examine %1 again    shift     goto :again )  rem build command string: rem /r "src_1" * /t ^& /r "src_..." * /t ^& /r "src_n" * /t ^& break" set "command=" /f "tokens=2 delims==" %%s in ('set src[') (    set "command=!command!where /r "%%s" * /t ^& " ) set "command=!command!break"  echo "command: ^<!command!^>"  rem clear temp file , write files copy in break>"%uniquefile%" /f "tokens=2,3,4,* delims= " %%f in ('!command!') (    call :spinner    echo %%f %%g %%h %%i>>"%uniquefile%" )  rem open built file list echo file list opened... %uniquefile% rem ask user if copying should start echo should files copied %dstpath%? (y/n) set input= set /p input=answer?:%=% if not [%input%] == [y] (    if not [%input%] == [y] (       goto :end    ) )  set "dstpathpart=" rem sort files newest first (last changed timestamp) /f "tokens=3,* delims= " %%f in ('type "%uniquefile%" ^| sort /r') (    rem build destination part source folder names    call :builddestinationpath dstpathpart "%%f %%g"     rem prepend destination folder    set "dstfile=!dstpath!\!dstpathpart!"     rem make directories doesn't exists    %%f in ("!dstfile!") set "directory=%%~dpf"    if not exist "!directory!" ( mkdir "!directory!" )     rem copy files , echo    echo copy /y "!file!" "!dstfile!"    copy /y "!file!" "!dstfile!"    echo.     rem if copying failed exit program    if errorlevel 1 (       echo copying failed... maybe there no more space on disk!       echo program terminate!       goto :end    ) ) goto :end   rem function definitions :builddestinationpath /f "tokens=2 delims==" %%s in ('set src[') (    rem go folder e.g.: c:\src_1\ --> c:\    pushd "%%s"    cd ..    rem file contains full path of command    set "file=%~2"     rem remove trailing space    if "!file:~-1!" == " " (       call set "file=%%file:~0,-1%%"    )     rem remove src folder file make relative    rem e.g. c:\src_1\foo\bar\file1.txt --> src_1\foo\bar\file1.txt    call set "dstpathpart_temp=%%file:!cd!=%%"     rem switch origin folder    popd     rem if folder name changed substring taken right take next    if not [!dstpathpart_temp!] == [!file!] (       set "%~1=!dstpathpart_temp!"       goto :next    ) ) :next goto :eof  :spinner set /a "spinner=(spinner + 1) %% 4" set "spinchars=\|/-" <nul set /p ".=building file list... !spinchars:~%spinner%,1!!cr!" goto :eof  :end del "%uniquefile%" goto :eof 

2. batch script using dir locate files:

it takes 1 more argument need minimum 3 arguments:
usage: batch.bat <timeordering> <dst> <src_1> [<src_...> <src_n>]

it generate same list explained above of dir command. dir command takes following parameter <timeordering> parameter of script:

/tc creation /ta last access /tw last written 

the batch script:

@echo off setlocal enabledelayedexpansion  rem check if @ least 2 arguments passed set invargs=0 if [%1] == [] set invargs=1 if [%2] == [] set invargs=1 if [%3] == [] set invargs=1 if %invargs% == 1 (    echo usage: %0 ^<timeordering^> ^<dst^> ^<src_1^> ^<src_...^> ^<src_n^>    goto :eof )  rem store carriage return character in cr (used spinner function, see below) /f %%a in ('copy /z "%~dpf0" nul') set "cr=%%a"  rem set temp file name set "uniquefile=%temp%\%0_%random%.tmp"  rem set timeordering , destination path , shift next argument set "timeordering=%~1" shift set "dstpath=%~1" shift  rem store src_1 src_n arguments src array set idx=0 :again rem if %1 blank, finished if not [%1] == [] (    if not exist "%~1" (       echo following source folder doesn't exist:       echo    "%~1"!       echo program terminate!       goto :end    )     pushd "%~1"    set "src[%idx%]=!cd!"    if [!src[%idx%]:~-1!] == [\] (       set src[%idx%]=!src[%idx%]:~0,-1!    )    set /a idx=%idx%+1    popd     rem shift arguments , examine %1 again    shift     goto :again )   rem clear temp file , write files copy in break>"%uniquefile%" rem call commands sources: rem call :getfileinformation /tc "src_1\*" rem                          /tw rem                          /ta /f "tokens=2 delims==" %%s in ('set src[') (    call :getfileinformation %timeordering% "%%s\*" "%uniquefile%"" )  rem open built file list echo unsorted file list opened... %uniquefile% rem ask user if copying should start echo should files copied %dstpath%? (y/n) set input= set /p input=answer?:%=% if not [%input%] == [y] (    if not [%input%] == [y] (       goto :end    ) )  set "dstpathpart=" rem sort files newest first (last changed timestamp) /f "tokens=3,* delims= " %%f in ('type "%uniquefile%" ^| sort /r') (    rem build destination part source folder names    call :builddestinationpath dstpathpart "%%f %%g"     rem prepend destination folder    set "dstfile=!dstpath!\!dstpathpart!"     rem make directories doesn't exists    %%f in ("!dstfile!") set "directory=%%~dpf"    if not exist "!directory!" ( mkdir "!directory!" )     rem copy files , echo    echo copy /y "!file!" "!dstfile!"    copy /y "!file!" "!dstfile!"    echo.     rem if copying failed exit program    if errorlevel 1 (       echo copying failed... maybe there no more space on disk!       echo program terminate!       goto :end    ) ) goto :end   rem function definitions :builddestinationpath /f "tokens=2 delims==" %%s in ('set src[') (    rem go folder e.g.: c:\src_1\ --> c:\    pushd "%%s"    cd ..    rem file contains full path of command    set "file=%~2"     rem remove trailing space    if "!file:~-1!" == " " (       call set "file=%%file:~0,-1%%"    )     rem remove src folder file make relative    rem e.g. c:\src_1\foo\bar\file1.txt --> src_1\foo\bar\file1.txt    call set "dstpathpart_temp=%%file:!cd!=%%"     rem switch origin folder    popd     rem if folder name changed substring taken right take next    if not [!dstpathpart_temp!] == [!file!] (       set "%~1=!dstpathpart_temp!"       goto :next    ) ) :next goto :eof  :getfileinformation /f "delims=" %%a in ('dir /s /b /a-d %~1 "%~2"') (    /f "tokens=1,2 delims= " %%b in ('dir %~1 "%%a" ^| findstr /l /c:"%%~nxa"') (       echo %%b %%c %%a>>"%~3"       call :spinner    ) ) goto :eof  :spinner set /a "spinner=(spinner + 1) %% 4" set "spinchars=\|/-" <nul set /p ".=building file list... !spinchars:~%spinner%,1!!cr!" goto :eof  :end del "%uniquefile%" goto :eof 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -