Friday, May 7, 2010

Handy BackUp AnyThing AnyWhere …

Ok, this script comes from the mess with my files.

I have a computer, where I do stuff the most of the time; & I have also an external storage, to bring my stuff with me when I went other places.

I use ©Explorer and not the ©BriefCase on my ©Windows system, mostly because of ‘Win’+‘E’ dialing.

That’s why I came out with this version of my personal BackUpManager.
BackUpManager
It works on ©Windows sever system compatible (cause of the use of ‘CHOICE’) & does good manual synchronization. Ha yes it’s highly Handy, drag’n drop it where you want do the back up, then drag’n drop Files/Directories over it; & it does the job.

BackUpManager use

It came with a log @ %TEMP%\BackUpManager.Log

Enjoy :

'BackUpManager.Cmd'

REM UtDate @ 2010/05/08 17H54 GMT.
REM v1
REM Works with 7
:START
    ECHO OFF
    SETLOCAL ENABLEEXTENSIONS
    SETLOCAL ENABLEDELAYEDEXPANSION
    TITLE "Status Mirroring !DATE! !TIME!."
    SET /A LINES_MENU="9">NUL

    REM FEATURES :
    REM ¯¯¯¯¯¯¯¯¯¯
    REM Self sizing Windows command interpreter.
    REM
    REM Temp path.
    SET TMP_PATH=!TEMP!
    REM
    REM This file path.
    SET WORKING_FILE=%~0
    REM
    REM Back up path.
    REM Change it to back up toward a fixed path no matter where this file is.
    SET WORKING_PATH=%~DP0
    REM
    REM Notepad++ path.
    SET NPP_PATH="C:\Users\hell\Desktop\Notepad++\notepad++.exe"
    REM
    REM Log path.
    SET LOG_FILE="!WORKING_PATH!PPP_BackUp_ONE.Log"
    REM
    REM Copy options :
    REM Copy subdirectories, including Empty ones.
    REM Copy File : Data; Attributes; Timestamps.
    REM Copy Directory : Timestamps.
    REM Delete destination files/directories that no longer exist in source for Directory_Case.
    REM Do multi-threaded copies with 128 threads (default).
    REM Copy symbolic links versus the target.
    REM
    REM File Selection Options :
    REM Exclude this file and the log issue with this file if so.
    REM Exclude Junction points.
    REM
    REM Retry Options :
    REM Don't display percentage copied.
    REM
    REM Logging Options :
    REM output status to LOG file (append to existing log).

    REM UNFEATURED
    REM ¯¯¯¯¯¯¯¯¯¯
    REM Rappel : Windows command interpreter does not conceive to make a good use of recursive call stack, so recursive loop would be limited in one way or another.
    REM Rappel : 'Access denied' message appears when administrator's right for the targeting path/file are require.
    REM Self updatable to new paths
    REM Create log file @ reset values, if it not exists.
    REM
    REM Copy options :
    REM Delete destination files/directories that no longer exist in source for File_Case.
    REM Copy all encrypted files in EFS RAW mode.
    REM Copy File : Security=NTFS ACLs; Owner info; Auditing info.
    REM Fixing stuff.
    REM Turn off very long path (> 256 characters) support.
    REM Monitoring source.
    REM Inter-Packet Gap (ms), to free bandwidth on slow lines.
    REM
    REM File Selection Options :
    REM Copy only files with the Archive attribute set.
    REM Exclude Changed files.
    REM Exclude Newer files.
    REM Exclude Older files.
    REM Exclude Lonely files and directories.
    REM Include Same files.
    REM Include Tweaked files.
    REM Exclude files bigger than n bytes.
    REM Exclude files smaller than n bytes.
    REM Exclude files older than n days/date.
    REM Exclude files newer than n days/date.
    REM Exclude files unused since n.
    REM Exclude files used since n.
    REM Assume FAT File Times (2-second granularity).
    REM Compensate for one-hour DST time differences.
    REM
    REM Retry Options :
    REM Retries on failed copies.
    REM Wait time between retries.
    REM
    REM Logging Options :
    REM List only - don't copy, timestamp or delete any files.
    REM Report all extra files, not just those selected.
    REM Produce verbose output, showing skipped files.
    REM Include source file Time Stamps in the output.
    REM Include Full Pathname of files in the output.
    REM Print sizes as bytes.
    REM Don't log file sizes.
    REM Don't log file classes.
    REM Don't log file names.
    REM Don't log directory names.
    REM Show Estimated Time of Arrival of copied files.
    REM No Job Header.
    REM No Job Summary.
    REM
    REM Job Options :
    REM take parameters from the named JOB file.
    REM SAVE parameters to the named job file.
    REM QUIT after processing command line (to view parameters).
    REM NO Source Directory is specified.
    REM NO Destination Directory is specified.
    REM Include the following Files.

    REM diagram @ ToMakeItOutAllForAll : OWN_BACKUP.dia

    IF NOT "%~1"=="" (
        REM Set the wait for an entry @ menu prompt.
        SET TIME_OUT="3"
        REM Set the default menu action after the wait .
        SET MENU_DEFAULT=e
        SET /A Count="!LINES_MENU!+4">NUL
        ECHO _______________________________________________________________________________________________________________________>>!LOG_FILE!
        ECHO ###################################################### S T A R T #### listing : #######################################>>!LOG_FILE!
        FOR %%A IN (%*) DO (
            REM Just 4lines 4esthetic reasons : display of the Windows command interpreter is calculate  by counting 5lines per entry
            REM '5' like 5 lines display by entry.
            SET /A Count="!Count!+5">NUL
            ECHO #"%%~A">>!LOG_FILE!
        )
        REM Set the console buffer's display (actually would also set the display layout).
        MODE CON COLS=120 LINES=!Count!
        ECHO Working target path : !WORKING_PATH!
        CALL :BACKUP_TIME %*
    ) ELSE (
        REM Set the wait for an entry @ menu prompt.
        SET TIME_OUT="10"
        REM Set the default menu action after the wait .
        SET MENU_DEFAULT=2
        REM Set the console buffer's display (actually would also set the display layout).
        MODE CON COLS=120 LINES=!LINES_MENU!
    )
    CALL :MENU_MIRRORING
GOTO :EOF
:BACKUP_TIME
    REM BackUp/UpDate/Synchronise
    (
        FOR %%A IN (%*) DO (
            ECHO _______________________________________________________________________________________________________________________>>!LOG_FILE!
            ECHO ####################################################### N E X T entry : ###############################################>>!LOG_FILE!
            SET AFF=%%A
            ECHO _______________________________________________________________________________________________________________________
            ECHO !DATE! !TIME!
            ECHO !AFF:~0,119!
            (
                IF NOT "%%~DPA"=="!WORKING_PATH!" (
                    (
                        IF EXIST %%A (
                            IF DEFINED TAMPON (
                                SET TAMPON=
                            )
                            FOR /F "USEBACKQ TOKENS=*" %%Z IN (`^(DIR /A:D "%%~A" 1^>NUL^)2^>^&1`) DO (
                                SET TAMPON=%%Z
                            )
                            (
                                IF DEFINED TAMPON (
                                    REM Just 4lines 4esthetic reasons : display of the Windows command interpreter is calculate  by counting 5lines per entry
                                    ECHO FILE CASE
                                    SET CMD_EXEC=ROBOCOPY ^"%%~DPA^" ^"!WORKING_PATH!^" ^"%%~NXA^" /COPY:DAT /R:0 /W:0 /MT:128 /SL /NP /XF ^"!WORKING_FILE!^" !LOG_FILE! /LOG+:!LOG_FILE!
                                    SET CMD_EXEC=!CMD_EXEC:^\^"=^"!>>!LOG_FILE!
                                    !CMD_EXEC!
                                ) ELSE (
                                    REM Just 4lines 4esthetic reasons : display of the Windows command interpreter is calculate  by counting 5lines per entry
                                    ECHO DIRECTORY CASE
                                    ROBOCOPY %%A "!WORKING_PATH!%%~NXA" *.* /E /COPY:DAT /DCOPY:T /PURGE /R:0 /W:0 /MT:128 /SL /NP /XF "!WORKING_FILE!" !LOG_FILE! /LOG+:!LOG_FILE!
                                )
                            )
                        ) ELSE (
                            REM Just 4lines 4esthetic reasons : display of the Windows command interpreter is calculate  by counting 5lines per entry
                            ECHO Actually path %%A doesn't work !>>!LOG_FILE!
                            ECHO Actually path DOES NOT WORK @ ALL !
                        )
                    )
                ) ELSE (
                    REM Just 4lines 4esthetic reasons : display of the Windows command interpreter is calculate  by counting 5lines per entry
                    ECHO Actually "%%~DPA" Source Path is the same as Target Path !>>!LOG_FILE!
                    ECHO Actually "%%~DPA" Source Path is the same as Target Path !
                )
            )
        )
    )
    ECHO _______________________________________________________________________________________________________________________>>!LOG_FILE!
    ECHO ######################################################## E N D ########################################################>>!LOG_FILE!
    ECHO.
    ECHO !DATE! !TIME!
GOTO :EOF
:MENU_MIRRORING_FRESH
    REM Set the console buffer's display (actually would also set the display layout).
    MODE CON COLS=120 LINES=!LINES_MENU!
:MENU_MIRRORING
    ECHO !TIME_OUT! seconds to pull :
    ECHO ?- r ? to reset the LogFile.
    ECHO ?- p ? to pause.
    ECHO ?- e ? to exit.
    ECHO ?- 1 ? to see !LOG_FILE! in N++ .
    ECHO ?- 2 ? to see !LOG_FILE! in N++ in new instance.
    ECHO ?- 3 ? to see !LOG_FILE! in Console.
    ECHO ?- 4 ? to see !LOG_FILE! in Notepad.
    (
        FOR /F "USEBACKQ" %%Z in (`CHOICE /T !TIME_OUT! /C rep1234 /D !MENU_DEFAULT! /N`) DO (
            CALL :MENU_MIRRORING_ITEM_%%Z
        )
    )
:MENU_MIRRORING_ITEM_E
:MENU_MIRRORING_ITEM_e
GOTO :EOF
:MENU_MIRRORING_ITEM_P
:MENU_MIRRORING_ITEM_p
    ECHO En pause
    PAUSE>NUL
    CALL :MENU_MIRRORING_FRESH
GOTO :EOF
:MENU_MIRRORING_ITEM_R
:MENU_MIRRORING_ITEM_r
    SET /A TAMPON="!LINES_MENU!+8">NUL
    REM Set the console buffer's display (actually would also set the display layout).
    MODE CON COLS=120 LINES=!TAMPON!
    CALL :RESET
    CALL :MENU_MIRRORING
GOTO :EOF
:RESET
    REM Reset LOG_FILE
    ECHO Reset !LOG_FILE! 2 :
    ECHO ______________________________________________________________________________________________________________________>!LOG_FILE!
    ECHO ______________________________________________________________________________________________________________________
    ECHO ^|####################################################################################################################^|>>!LOG_FILE!
    ECHO ^|####################################################################################################################^|
    ECHO ^|#                                                                                                                  #^|>>!LOG_FILE!
    ECHO ^|#                                                                                                                  #^|
    ECHO ^|#                                                  LOG START HERE                                                  #^|>>!LOG_FILE!
    ECHO ^|#                                                  LOG START HERE                                                  #^|
    ECHO ^|#                                                                                                                  #^|>>!LOG_FILE!
    ECHO ^|#                                                                                                                  #^|
    ECHO ^|############################################################################### !DATE!  !TIME! GMT+13 #^|>>!LOG_FILE!
    ECHO ^|############################################################################### !DATE!  !TIME! GMT+13 #^|
    ECHO ^|####################################################################################################################^|
GOTO :EOF
:MENU_MIRRORING_ITEM_1
    REM Launch LOG_FILE in  new instance N++
    ECHO !NPP_PATH! !LOG_FILE!
    START "N++ !LOG_FILE!" /D !TMP_PATH! /B !NPP_PATH! !LOG_FILE!
GOTO :EOF
:MENU_MIRRORING_ITEM_2
    REM Launch LOG_FILE in N++ multi instance
    ECHO !NPP_PATH! -multiInst !LOG_FILE!
    START "N++ multi instance !LOG_FILE!" /D !TMP_PATH! /B !NPP_PATH! -multiInst !LOG_FILE!
GOTO :EOF
:MENU_MIRRORING_ITEM_3
    REM Launch LOG_FILE on CMD
    CLS
    REM Set the console buffer's display (actually would also set the display layout).
    MODE CON COLS=120 LINES=32000
    MORE !LOG_FILE!
    PAUSE>NUL
GOTO :EOF
:MENU_MIRRORING_ITEM_4
    REM Launch LOG_FILE in NotePad
    ECHO !SYSTEMROOT!\NOTEPAD.EXE !LOG_FILE!
    START "NotePad !LOG_FILE!" /D !TMP_PATH! /B !SYSTEMROOT!\NOTEPAD.EXE !LOG_FILE!
GOTO :EOF

0 comments:

Post a Comment