In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to use batch processing to achieve document backup V2.3, the editor thinks it is very practical, so share it with you as a reference, I hope you can get something after reading this article.
The code is as follows:
@ echo off
:
:: file backup V2.3 (for WinXP only) Code by JM 2006-11-4 QQ:13132002
:: source: http://www.cn-dos.net/forum/viewthread.php?tid=20747
::
:: 1. Freely specify the directory (or file), location, backup time and task name to be backed up
Can check whether the input is correct or not
:: 3. Generate backup log
:: 4. Add backup tasks many times
:: 5. Batch stop specified backup tasks
Can automatically delete batch programs and registry information generated by this program and no longer in use
Restore files from backup files to source files and keep the original attributes of each file unchanged
::
Principle: update the file only when the modification time of the source file is newer than that of the target file
::
Areas to be modified or improved:
::
:: is the ① unified tag a file or a folder
② forbids backing up files to this folder and its subfolders
::
:: update history
::
:: 06.11.4
::
The function of recording backup file update list has been added to further improve the log function.
::
:: 06.10.19
::
:: because the at command can only be run with administrator privileges, this update increases the verification of user permissions; added
The / c parameter of xcopy makes it possible to back up when there is a replication error (although the probability of this is very low).
:: as many files as possible; streamlined some of the code
::
:: 06.9.14
::
The code for extracting file attributes is optimized, which greatly improves the efficiency of generating backup batches.
Thank pengfei for providing the code; fixed several errors and omissions; and put the code in blocks for later
:: maintenance; this is V2.3
::
:: 06.9.3
::
Due to the excessive simplification last time, the code will go wrong. A fatal error has been modified today. Thank you.
:: pengfei testing; added some operation hints and error detection
::
:: 06.8.5
::
:: added the parameter of backing up the empty directory and simplified part of the code
:: 06.8.1
::
:: realized copying files and folders with the same command; fixed several errors
:: 06.7.29
::
:: simplified the code for getting attributes, thanks to willsort for providing
:: 06.7.28
:: improves the operation of restoring the backed-up files, making the recovery operation to the files or folders
:: both apply; this is V2.2
::
:: 06.7.1
:: improved the date detection
:: 06.6.29
The function of restoring files has been added, and the attributes of the generated files have been adjusted; this is V2.1
:: 06.6.20
The code that displays the remaining space of each partition disk has been modified to show only the remaining space of the disk
: instead of gilding the lily to display the remaining space of the CD
:: 06.6.15
:: added date and time input error detection (thanks to bagpipe for providing code)
:: 06.6.12
The code for querying the remaining space of each partition has been modified so that the disk volume can be typeset accurately when the disk volume name is Chinese.
Thank willsort for his in-depth analysis and providing the code; when the backup task is created, it can automatically open the backup
:: folder and create logs to view the backup creation results; completely delete useless files; streamline the department
: sub-code
:: 06.6.10
Fixed a bug; streamlined some of the code
:: 06.6.9
Changing the backup log code will reduce the backup log volume by nearly half; change the file name to realize automatic
:: the function key to complete this function (thanks for the reminder from electronixtar), but requires a specific key in the registry
:: value is the default setting (for discussion, please refer to http://www.cn-dos.net/forum/viewthread.php?
:: tid=21091&fpage=1)
:: 06.6.6
Part of the code has been modified to avoid tedious input when daily backup is needed.
:: automatic completion of file names (thanks to willsort for his idea and code); this is V1.9
:: 06.6.4
The following functions have been added: when saving backup files, if you want to append or overwrite the folder, etc.
:: operation, you can first view the contents of the folder before making a decision; added backup risk tips
:: 06.6.3
The part of the code where the file is saved after backup is modified so that the program can automatically adapt to backup
:: the objects are files and folders, so that the directory structure of the folder after backup can be maintained, thank you
:: willsort provides code; when backup files are about to be saved to an existing directory, permission has been added
:: allow options to be appended to this directory
:: 06.6.2
:: the following features have been added and modified: you can choose whether to run the backup task program automatically when you boot
Automatically delete items that are no longer used in the current scheduled task when you start running the program or stop a backup task
Backup task program, and delete the corresponding registry key value to reduce system garbage; changed the backup task routine
:: the save location of the order; removed the chicken rib code that converts lowercase to uppercase; enhanced when the path input is empty
:: test (thanks to willsort for providing the code); fixed several errors; streamlined some of the code, which is V1.8
:: 06.5.31
: in the registry (location: HKEY_LOCAL_MACHINE\ Software\ Microsoft\ Windows\
:: CurrentVersion\ Run) added the key to automatically run the backup program (based on the backup task name)
:: key value) to minimize the missed backup; if the content is updated, it will be typed automatically after the backup is completed.
:: open backup log; fixed several errors; this is V1.7
:: 06.5.30
The backup process has been improved so that the contents of backup tasks can be changed when the list of backup tasks is listed
:: when creating a backup task, force the scheduled task service to start and copy immediately; display each disk
:: when the remaining space of the partition, the function of displaying disk volume label name has been added, and the matters needing attention interface has been changed.
The foreground color and background color in make the tone appear bright and soft
:: 06.5.28
Added the ability to back up on a specified day of the week; added the ability to submit a report when a scheduled task went wrong
:: the function of notification; improved the logging function so that the log will be rewritten only when the file is updated; improved attention
:: content in the event; added the ability to delete all scheduled tasks; this is V1.6
:: 06.5.26
Added that it is not allowed to set the save path to the same path as the source file, or to a directory of the source file
:: function; added notice prompt function; corrected several errors; part of the code refers to China DOS
:: alliance forum (http://www.cn-dos.net/forum) netizen bagpipe post, make some code get
: to streamlined; this is V1.5
:: 06.5.25
Added the function of dragging the saved directory of backup files to the window for execution; added batch stop assignment
:: the function of the backup task; fixed several errors; simplified some code; this is V1.4
:: 06.5.24
:: added the function of dragging files to be backed up to the window for execution; thanks to China DOS Alliance Forum
:: (http://www.cn-dos.net/forum) moderator willsort provides the code; this is V1.3
:: 06.5.23
:: fixed a key error so that the backup can proceed smoothly; in China DOS Alliance Forum
With the enthusiastic help of http://www.cn-dos.net/forum) moderator willsort and other netizens, Cheng has been enhanced
Thank you for your ability to detect errors and correct some spelling mistakes
:: 06.5.22
The code that displays the remaining space in each zone has been modified to make the frame and line of the display interface automatically adapt to the remaining space bar
:: characters of different lengths
:: 06.5.21
The function of stopping the designated backup task has been added to further improve the function of this program.
:: the file after the backup is set to the "system + read-only" attribute, which improves the backup to some extent.
Security of:: file; fixed several bugs; optimized part of the code; this is v1.2
:: 06.5.20
:: the algorithm in the first two days has the disadvantage of incomplete backup. Today, change the copy command to xcopy command.
This enables the program to back up all files in the specified directory except the empty directory (including the
:: the nesting of files containing files in subdirectories and subdirectories), and the code has been simplified; the code for the first two days
:: when generating a backup task batch, because the automatically named program name is fixed, if there are different
If you back up the task, the last task will delete the last task, and the name of the backup task will be changed today
:: specified manually; added the ability to add backup tasks multiple times; this is v1.1
:: 06.5.19
Added the system detection function so that the program can only run under the XP operating system; write input errors
:: detect the code so that the input errors can be changed in time; unify the interactive interface and look more beautiful; this
To add the function of specifying backup operations on certain days of the week, but it has not been realized, so it has to be temporarily implemented.
: give up and leave it to the next few versions; optimize some redundant code
:: 06.5.18
When backing up the important data on my computer, I feel the cumbersome of backing up by hand, while the online
The backup software has many limitations, and I happen to be learning DOS batch programming by myself, so I spent half a day
:: to conceive the core functions of this program and write preliminary code; this is V1.0
:
Rem if not "% 1" = "$"% comspec% / f:on / c 0 $& & goto: eof
:: block out the last sentence and use Tab\ Shift+Tab to achieve the same function.
Mode con lines=26
Title file backup-file backup
Color 1f
Cls
Rem = check whether the system supports this program =
: check_system
Ver | find "XP" > nul | | goto system_error
Rem = detect whether the current user has administrator privileges =
: check_popedom
Net users% username% | findstr / I "\ * administrator" > nul | | goto popedom_error
Call: del_nouse
Rem = enter the path of the file to be backed up and check whether the input is correct =
: input_source
Mode con lines=26
Cls
Color 1f
Title File backup-Please enter the source file path
Echo ╭─╮
Echo ╭─┤ selects the file ├─╮ to back up
Echo │ ╰─╯ │
Echo │ │
Echo │ this program can back up specified files to │ within a specified period of time.
Echo │ │
Echo │ setting. Please drag the file (or folder) to be backed up to this window (recommended │
Echo │ │
Echo │ practice), or manually enter the absolute path or relative │ of the file to be backed up
Echo │ │
Echo │ path (do not enter illegal symbols), and then enter to confirm. │
Echo │ │
The echo │ autocomplete file name can be selected multiple times by pressing Tab\ Shift+Tab. │
Echo │ │
Echo │ does not erroneously delete data. Please check │ before using this software.
Echo │ │
Echo │ matters! Remember! remember! (press R to restore files) │
Echo │ │
Echo ╰──╯
Echo.
Echo View Note Please press 1 to exit and press 0
Echo ──
For echo to view existing backup tasks, press 2
Echo.
Set source=:
Set / p source= enter the path where you want to back up the file:
Set "source=%source:" =% "
:: the above sentence is to determine whether quotation marks exist in% source%, and if so, remove them.
If "% source%" = ":" goto input_source
If "% source%" = = "0" exit
If "% source%" = = "1" goto notice
If "% source%" = = "2" goto backup_task
If / I "% source%" = = "r" goto revert
If not exist "source%" goto source_noexist
For% I in ("% source%") do if "% ~ fi" = = "% ~ di\" goto forbid_to_backup
:: determine whether files or folders are to be backed up, and set flags for future operations
Pushd "% source%" > nul 2 > nul & & (popd & set folder=yes) | | (set folder=)
Goto input_destination
: backup_task
Cls
Color 1f
Title File backup-existing backup task
Echo.
At
Echo
Echo.
Echo ╔══╗
Echo ║ if you want to stop a backup task, enter the ID number of the task, and then press enter to ║
Echo ║ ║
Multiple ID numbers of echo ║ are separated by spaces. To stop all scheduled tasks, press A ║.
Echo ║ ║
Press 0 to exit echo ║, and press any key ║ except 0, An and ID to return to the previous step.
Echo ╚══╝
Echo.
Set ID=
Set / p ID= enter the ID of the backup task that is no longer needed:
If "% ID%" = = "0" exit
If / I "% ID%" = = "a" at / delete / yes & & (call: del_nouse & & goto backup_task)
The purpose of the following statement is: if a backup task is stopped, check the bat file generated by this program on the hard disk
Which are not in the at task list; if so, delete the bat and delete the corresponding string value in the registry
:: if not, no deletion is made
(for% I in (% ID%) do at% I / del / yes > nul 2 > nul) & (
Call: del_nouse
Goto backup_task
) | | goto input_source |
Rem = enter the file save path and check if the input is correct
: input_destination
Cls
Color 1f
Title File backup-Please enter the destination file path
Echo.
Echo.
Echo ╭─╮
Echo ╭─┤ chooses save location ├─╮
Echo │ ╰─╯ │
Echo │ operating instructions: │
Echo │ │
Echo │ Please enter the absolute path or relative path │ of the saved location
Echo │ │
Echo │ (Note: colons and backslashes must be entered in half-angle; │
Echo │ │
Echo │ do not enter an illegal pathname symbol), or put a │
Echo │ │
Drag the folder that exists in echo │ to this window, and then press enter to confirm. │
Echo │ │
Echo │ ╭─╮ │
For echo ╰─┤ to view the remaining space in each partition, press 9 ├─╯
Echo ╰─╯
Echo.
Echo to return to the previous step, press 1 to exit, press 0
Echo ──
Echo.
Set destination=:
Set / p destination= Please enter the path to save the backup file:
Set "destination=%destination:" =% "
:: the above sentence is to judge whether there are quotation marks in% destination%, if so, remove them.
If "% destination%" = ":" goto input_destination
If "% destination%" = = "0" exit
If "% destination%" = = "1" goto input_source
If "% destination%" = = "9" goto freesize
:: the following sentence takes the file name of the save location for the file or folder
For / d% I in ("% source%.*") do set destination=%destination%\% ~ nxi
For I in ("destination%") do set destination=%%~fi
Set subarea=%destination:~0,1%
For% I in ("% destination%") do if "% ~ fi" = = "% ~ di\" goto forbid_to_build_1
Echo "% destination%" | findstr / I / c: "% source%" & & goto forbid_to_build_2
If not exist% subarea%:\ nul goto subarea_noexist
:: the following sentence takes the file name of the log as the file (folder) to be backed up
For I in ("source%") do set name_log=%%~ni
If exist "% destination%\% name_log%_log.log" goto whether_add
If exist "destination%" goto whether_over
: over_write
Attrib / s / d-s-h-r "% destination%\ *. *" > nul 2 > nul
Rd / Q / s "destination%" > nul 2 > nul
Md "destination%" > nul 2 > nul
(echo.
Echo backup log) > "% destination%\% name_log%_log.log"
Attrib / s / d + s + r "% destination%\ *. *" > nul 2 > nul
: input_date
Cls
Color 1f
Title File backup-Please enter backup date
Echo ╭─╮
Echo ╭─┤ Please enter backup date ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ 1. If you back up on certain days of the month, enter any │ from 1 to 31
Echo │ │
Echo │ numbers, such as 1re3 │ 4; if you only back up on the 1st of each month, enter "1,"; │
Echo │ │
Echo │ 2. If the backup is made on certain days of the week, enter the code │ for the day of the week.
Echo │ │
Echo │ (M ·T ·W ·J ·F ·S ·Su); if there are more dates specified, check the task │.
Echo │ │
When echo │ list, the date column will be displayed with an ellipsis; │
Echo │ │
Echo │ 3. Numbers and letters cannot be mixed; there is no │ at the beginning and end of a numeric line or a letter line.
Echo │ │
Echo │ any symbols separated by commas; please fill in strictly according to this format! │
Echo │ │
Echo ╰──╯
Echo.
Echo to return to the previous step, press 1 to exit, press 0
Echo ──
Echo backs up every day, press A
Echo.
Set copydate=
Set / p copydate= Please enter the backup date:
If "% copydate%" = "" goto input_date
If "% copydate%" = = "," goto input_date
If "% copydate%" = = "0" exit
If "% copydate%" = = "1" goto input_destination
If "% copydate%" = = "1," goto input_time
If / I "% copydate%" = = "a" goto all_date
:: check whether the date is entered correctly
Set num=0
Set char=%copydate%
For / f "tokens=1 delims=,"% I in ("% char%") do (
Echo "% I" | findstr / I "M T W Th F S Su" > nul & & goto check_alphabetical_date | | goto check_numerical_date
)
: check_alphabetical_date
Call: check_alp
: loop_alp
Set char=%char:*,=%
: check_alp
For / f "tokens=1 delims=,"% I in ("% char%") do (
Echo "M T W Th F S Su" | findstr / I "% I" > nul | | goto date_error
Echo "% char%" | find "," > nul & & goto loop_alp "
)
Goto input_time
: check_numerical_date
Call: check_num
: loop_num
Set / a num+=1
Set char=%char:*,=%
: check_num
For / f "tokens=1 delims=," I in ("char%") do set input=%%i
If input% GTR 31 goto date_error
If num% GTR 30 goto date_error
Echo% char% | find "," > nul | | if% num% LEQ 30 goto input_time | | goto date_error
Goto loop_num
: input_time
Cls
Color 1f
Title File backup-Please enter time
Echo.
Echo ╭─╮
Echo ╭─┤ Please enter backup time ├─╮
Echo │ ╰─╯ │
Echo │ operating instructions: │
Echo │ │
Echo │, please enter backup time in format. Use space │ for multiple times.
Echo │ │
Echo │ separation. This time is based on a 24-hour (from 00:00 to 23:59) │
Echo │ │
The hour: minute format of the echo │. │
Echo │ │
Echo │ for example: want to enter │ at 08:30 and 4 p.m., respectively
Echo │ │
Echo │ line backup, please enter 8:30 16:00 on the same line (note: two │
Echo │ │
Echo │ has a space between time steps) │
Echo │ │
Echo ╰──╯
Echo.
Echo to return to the previous step, press 1 to exit, press 0
Echo ──
Echo.
Set copytime=
Set / p copytime= Please enter backup time:
If "% copytime%" = "" goto input_time
If "% copytime%" = = "0" exit
If "% copytime%" = = "1" goto input_date
:: check whether the time input is correct
For / f "tokens=*" I in ("copytime%") do set char=%%i
Call: check_time
Set num=0
: back
Set / a num+=1
Set char=%char:* =%
: check_time
For / f "tokens=1,2 delims=:"% I in ("% char%") do (
If I GTR 24 goto time_error
If j GTR 60 goto time_error
Echo% char% | find "" > nul | | goto input_name
)
Goto back
Rem = enter backup task name =
: input_name
Cls
Color 1f
Title file backup-backup task name
Echo.
Echo ╭─╮
Echo ╭─┤ backup Task name ├─╮
Echo │ ╰─╯ │
Echo │ operating instructions: │
Echo │ │
Echo │, please enter the name of the backup task, and then press enter to confirm. │
Echo │ │
Echo │ this program will back up │ on the system installation disk:\ Program Files\
Echo │ │
Generate "backup task name _ backup.bat" │ under echo │ task program
Echo │ │
Backup and restore │ for echo │ and backup task name _ revert.bat
Echo │ │
Echo │ re-batch. To change some of the features of this backup task, │
Echo │ │
Echo │ please use the text editing tool to edit the batch file. │
Echo │ │
Echo ╰──╯
Echo.
Echo to return to the previous step, press 1 to exit, press 0
Echo ──
Echo.
Echo.
Set name=
Set / p name= Please enter the name of the backup task:
If "% name%" = "" goto input_name
If "% name%" = = "0" exit
If "% name%" = = "1" goto input_time
If exist "% ProgramFiles%\ backup task program\% name%_backup.bat" goto name_exist
Call: list
Echo ╔══╗
Press 0 to exit echo ║, 1 to return to the previous step, and B ║ to give up and start a new backup.
Echo ║ ║
Echo ║ to continue next, press any key except 0, 1, and B ║
Echo ╚══╝
Echo.
Set choice=
Set / p choice= Please select the operation code (0/1/B/ other keys):
If "% choice%" = = "0" exit
If "% choice%" = = "1" goto input_name
If / I "% choice%" = = "b" (
Attrib / s / d-s-h-r "% destination%\ *. *" > nul 2 > nul
Rd / Q / s "destination%" > nul 2 > nul
Goto input_source
)
Goto build_backup
: notice
Cls
Mode con lines=40
Color 8e
Title File backup-Note
Echo.
Echo.
Echo ╔══╗
Echo ║ ║
Echo ║ 1. When the program prompts that a path already exists, it is strongly recommended that you check ║ before making an overwrite operation
Echo ║ ║
Echo ║ looks at the contents of this directory, lest the program erroneously delete all the contents of this directory, and bring you ║
Echo ║ ║
The catastrophic loss of echo ║. Backup is risky, please be careful! ║
Echo ║ ║
Echo ║ 2. In the path name, except that the colon and backslash symbols are allowed to follow the drive letter, other bits ║
Echo ║ ║
The echo ║ setting can no longer contain the following 11 symbols in half-angle state, which are:\, /,:, *,?, ║
Echo ║ ║
Echo ║ ", (,), |. Entering any of these symbols will cause an unexpected error ║.
Echo ║ ║
Echo ║ error; in this procedure, the naming of the file name should also comply with the above provisions! ║
Echo ║ ║
Echo ║ 3. If you enter only the path in the format "drive letter + colon", the program will treat the path as the specified ║
Echo ║ ║
The current path of the echo ║ disk is processed instead of specifying the root directory of the disk. For example, suppose the system installs ║
Echo ║ ║
Echo ║ on disk C, if you only enter C: in the path, it will not be considered as the root directory of disk C, but the ║ of disk C.
Echo ║ ║
Echo ║ current path, default is "C:\ ducuments and settings\ current user name"; ║
Echo ║ ║
Echo ║ 4. If the path entered does not have a drive letter, it is treated as a relative path; ║
Echo ║ ║
Echo ║ 5. The working principle of this procedure is as follows: by comparing the time of backup files and source files, ║
Echo ║ ║
Echo ║ to decide whether to copy or not, so any changes to the file modification time after backup fuck ║
Echo ║ ║
Echo ║ will prevent the program from updating the changed data of the source file in time. Do not ║ the backed-up file.
Echo ║ ║
Echo ║ to rename, add or delete subfiles and other operations! ║
Echo ║ ║
Echo ╚══╝
Echo.
Echo presses any key to return to the previous step.
Pause > nul
Goto input_source
: whether_over
Cls
Color 0c
Title File backup-path already exists
Echo.
Echo.
Echo.
Echo.
Echo.
Echo _
Echo.
Echo the path "% destination%" you entered already exists, overwrite or append?
Echo.
Echo _
Echo.
Echo ╔══╗
Echo ║ press O to overwrite, A to append, V to view the saved directory, 1 to return to the previous step, and 0 to exit ║
Echo ╚══╝
Echo.
Echo.
Set choice=
Set / p choice= Please select (O/A/V/0/1):
If / I "% choice%" = = "o" cls & & goto over_write
If / I "% choice%" = = "a" goto input_date
If / I "% choice%" = = "v" call: view_directory & & goto whether_over
If "% choice%" = = "0" exit
If "% choice%" = = "1" goto input_destination
Goto whether_over
: whether_add
Cls
Color 0c
Title File backup-path already exists
Echo.
Echo.
Echo.
Echo.
Echo.
Echo _
Echo.
There seems to be a previous backup under echo "% destination%", overwrite or append?
Echo.
Echo _
Echo.
Echo ╔══╗
Echo ║ press V to view the saved directory, O to overwrite, A to append, 1 to return to the previous step, and 0 to exit ║
Echo ╚══╝
Echo.
Echo.
Set choice=
Set / p choice= Please select (V/O/A/0/1):
If / I "% choice%" = = "o" goto over_write
If / I "% choice%" = = "a" cls & & goto input_date
If / I "% choice%" = = "v" call: view_directory & & goto whether_add
If "% choice%" = = "0" exit
If "% choice%" = = "1" goto input_destination
Goto whether_add
: freesize
:: assume that the length of the string freesize ranges from 0 to 7 (assuming that the maximum disk size is 999g, which translates to 7 digits in M)
:: first fill in seven spaces before the freesize, and then directly take the last seven characters of the string to get the right alignment
The number freesize of::. Similarly, assume that the length of the string volume is 020 (the volume label name can be up to 32 bits long, but
:: in order to take into account the display of typesetting, only the last 20 digits).
Cls
Color 2e
Title file backup device-remaining space for each partition
Setlocal EnableDelayedExpansion
Echo.
Echo.
Echo ╔══╗
Echo ║ disk partition disk volume label name remaining space (MB) ║
Echo ║ _ ║
For d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
If exist% d:\ nul (
For / f "tokens=3"% z in ('dir /-c% d:\') do set freesize=%%z
If not "! freesize!" = = "0" (
Set / a freesizecoat engine freesizefreestanding engine 0jcmlwy3color nul 1049 >
Set freesize=! freesize!
Set freesizeware freesheet 7!
For / f "tokens=3*"% v in ('vol% dvv') do set volume=%%w
Set volume=! volume!
Set volumetric flowers 20!
Echo ║% d:! volume!! freesize! ║
)
)
)
Echo ╚══╝
Echo.
Echo.
Echo.
Echo.
Echo presses any key to return to the previous step.
Pause > nul
Goto input_destination
Rem = create a backup task script, taking into account the generation of multiple batch files =
: build_backup
Call: list
Title File backup-generating backup program.
If not exist "% ProgramFiles%\ backup Task Program" md "% ProgramFiles%\ backup Task Program"
Set batch_directory=%ProgramFiles%\ backup task program
Attrib / s / d-r-h-s "% batch_directory%\ *. *" > nul 2 > nul
:: because all batch content is received with only one sentence > "% batch_directory%\% name%_backup.bat"
:: so all the parentheses are escaped with ^
(
Echo @ echo off
Echo mode con cols=35 lines=10
Echo color 1f
Echo title File backup -% name%_backup
Echo.
Echo rem feature description
Echo.
Echo rem this program generates Code by JM 2006-10-19 QQ:13132002 from "File backup V2.3".
Echo.
Echo rem build on date% time:~0,-3% by username%
Echo.
Echo rem principle: compare the modification date of the original file and the backup file, if the modification time of the original file is later than that of the backup file
Echo rem copies the original file to overwrite the backup file; if there is no difference in time, no processing is made.
Echo.
Echo if not exist "% source%" ^ (
Echo title file is missing
Echo color 0c
Echo echo.
Echo echo _ _
Echo echo.
Echo echo file 'source%'
Echo echo.
Echo ecoh does not exist and may have been renamed, moved or deleted
Echo echo.
Echo echo _ _
Echo ping 127.1-n 5 ^ > nul
Echo exit ^)
Echo if not exist "destination%" md "destination%"
) > "% batch_directory%\% name%_backup.bat"
Set xcopy_parameter=
If "% folder%" = = "yes" (set xcopy_parameter=/e / s) else (goto file_backup)
(
Echo attrib / s / d-s-h-r "% destination%\ *. *" ^ > nul 2 ^ > nul
Echo set times=
Echo setlocal enabledelayedexpansion
Echo for / f "delims="%% I in ^ ('xcopy / c / d / h / I / g / r% xcopy_parameter% / x / y "% source%"% destination% "^) do ^ (
Echo if "%% I" = = "0 files copied" ^ (exit ^) else ^ (
Echo if not defined times call: head
Echo if ^! file_ time ^ ^! Lss% ~ ti set file_time=%%%%~ ti ^ & set file_route=%%%%~dpnxi
Echo if not "%% ~ ti" = "" ^ (echo%% ~ dpnxi%% ~ ti^ > ^ > "% destination%\% name_log%_log.log"
Echo ^) else ^ (echo. ^ & echo%% i^) ^ > ^ > "% destination%\% name_log%_log.log"
Echo ^)
Echo if "%% I" = = "1 file copied" goto end
Echo ^)
Echo ^ (
Echo echo.
The last file updated by echo echo is:% file_route%%, and the update operation occurred at% file_time%%.
Echo ^) ^ > ^ > "% destination%\% name_log%_log.log"
Echo: end
Echo attrib / s / d + s + r "% destination%\ *. *" ^ > nul 2 ^ > nul
Echo start ""% destination%\% name_log%_log.log "
Echo goto: eof
Echo.
) > > "% batch_directory%\% name%_backup.bat"
Call: build_head
Goto build_revert
: file_backup
(
Echo xcopy / c / d / h / I / g / Q / x / y "% source%"% destination%" ^ | findstr / b / e / c: "0 files copied" ^ > Null ^ & goto: eof
Echo attrib-s-h-r "% destination%\ *. *" ^ > nul 2 ^ > nul
Echo echo.^ > ^ > "% destination%\% name_log%_log.log"
Echo for / f "skip=1 tokens=1,2"% I in ^ ('dir / Amurd / tw "% source%" ^ ^ | find "-"' ^) do ^ (
Echo echo ^ file last updated:%% I%% j^ > ^ > "% destination%\% name_log%_log.log"
Echo ^)
Echo attrib + s + r "% destination%\ *. *" ^ > nul 2 ^ > nul
Echo start ""% destination%\% name_log%_log.log "
) > > "% batch_directory%\% name%_backup.bat"
Rem = create a file recovery script =
: build_revert
:: restore the full path of the file (folder) after backup
For I in ("source%") do set SourceFileName=%%~nxi
:: determine whether% source% is a file or a folder
If "% folder%" = = "yes" (set SourceFiles=%destination%) else (set SourceFiles=%destination%\% SourceFileName%)
(
Echo @ echo off
Echo mode con lines=25
Echo color 1f
Echo title File backup -% name%_revert
Echo.
Echo rem feature description
Echo.
Echo rem this program generates Code by JM 2006-10-19 QQ:13132002 from "File backup V2.3".
Echo.
Echo rem build on date% time:~0,-3% by username%
Echo.
Echo rem principle: when creating a backup task, record the original attributes of the source file. When you need to restore a file
Echo rem copies the backed-up files to overwrite the source files, and removes the attributes of all files after overwriting. Finally,
Echo rem reads the original properties from the recovery program and resets them.
Echo if not exist "% destination%" ^ (
Echo title file is missing
Echo color 0c
Echo echo.
Echo echo.
Echo echo.
Echo echo.
Echo echo.
Echo echo.
Echo echo _
Echo echo.
The echo echo file 'destination%' does not exist and may have been renamed, moved, or deleted
Echo echo.
Echo echo _
Echo ping 127.1-n 5 ^ > nul
Echo exit ^)
Echo echo.
Echo echo.
Echo echo.
Echo echo.
Echo echo.
Echo echo.
Echo echo _
Echo echo.
Please wait while echo echo recovers files from'% destination%'to'% source%'.
Echo echo.
Echo echo _
) > "% batch_directory%\% name%_revert.bat"
If "% folder%" = = "yes" echo if not exist "% source%" md "% source%" > > "% batch_directory%\% name%_revert.bat"
Echo attrib / s / d-h-r-s "% source%" ^ > nul 2 ^ > nul > > "% batch_directory%\% name%_revert.bat"
If "% folder%" = = "yes" (goto folder_copy) else (goto file_copy)
: file_copy
For / f "tokens=*"% I in ("% source%") do (set file_root=%%~dpi)
(
Echo xcopy / c / h / Q / r% xcopy_parameter% / x / y "% SourceFiles%"% file_root%" ^ > nul 2 ^ > nul
Echo attrib-h-r-s "% source%" ^ > nul 2 ^ > nul
) > > "% batch_directory%\% name%_revert.bat"
Goto get_attrib
: folder_copy
(
Echo xcopy / c / e / h / I / g / Q / r / s / x / y "% SourceFiles%"% source%" ^ > nul 2 ^ > nul
Echo del / a / f "% source%\% name_log%_log.log" ^ > nul 2 ^ > nul
) > > "% batch_directory%\% name%_revert.bat"
Rem = get attributes of files (folders) =
: get_attrib
:: choose the / s parameter in dir according to the file (folder) to prevent multiple column paths when% suorce% is a file
:: but when% source% is a file, dir / a / b "% source%" does not show the absolute path
If "% folder%" = = "yes" (set dir_='dir / a / b / s "% source%"') else (set dir_= "% source%")
Setlocal enabledelayedexpansion
For / f "tokens=*"% I in (% dir_%) do (
Set var=%%~ai
Set attrib_=
If not "! var:~1,1!" = = "-" set attribitary flowers var VRAVRO 1!
If not "! var:~3,1!" = = "-" set attribals created attribals! +! var:~3,1!
If not "! var:~4,1!" = = "-" set attribals created attribals! +! var:~4,1!
If not "! attribounded!" = "" echo attrib! attribounded! "% I" > > "% batch_directory%\% name%_revert.bat"
)
: add_to_reg
Cls
Color 1f
Title File backup-Boot option
Echo.
Echo ╭─╮
Echo ╭─┤ Boot self-run option ├─╮
Echo │ ╰─╯ │
Echo │ operating instructions: │
Echo │ │
Echo │ this operation is about to add backup tasks to boot self-running │
Echo │ │
Echo │ options. To cancel the boot self-run feature, please start │ at
Echo │ │
Enter "msconfig" in echo │\ run to open the system configuration utility │
Echo │ │
"echo │ program", cancel the │ named after the backup task name at "start"
Echo │ │
Echo │ starts the project, or in the registry [HKEY_LOCAL_MACHINE\ │
Echo │ │
Echo │ SOFTWARE\ Microsoft\ Windows\ CurrentVersion\ │
Echo │ │
Delete the corresponding string value under echo │ Run. │
Echo │ │
Echo ╰──╯
Echo.
Echo accepts, please hit enter directly to skip, press S
Echo ──
Echo.
Set choice=
Set / p choice= Please enter the operation code (S / enter):
If / I "% choice%" = = "s" goto run_at
Rem = add a self-boot entry to the registry for automatic backup when powered on =
Reg add HKLM\ SOFTWARE\ Microsoft\ Windows\ CurrentVersion\ Run / v% name% / t REG_SZ / d "% batch_directory%\% name%_backup.bat" / f > nul 2 > nul
: run_at
:: force the scheduled task service to be enabled
Sc config Schedule start= AUTO > nul 2 > nul
Sc start Schedule > nul 2 > nul
Rem = Import at scheduled tasks =
For I in (copytime%) do (
At I / every:%copydate% "% batch_directory%\% name%_backup.bat" > nul 2 > nul
)
Attrib / s / d-s-r "% destination%\ *. *" > nul 2 > nul
(
Echo.
Echo ━━
Echo.
Echo created a backup task on date% time:~0,8%
Echo backup object:% source%
Echo backup files are saved at% destination%
Echo backup program location:% batch_directory%\% name%_backup.bat
Echo file recovery program location:% batch_directory%\% name%_revert.bat
Echo.
Echo ━━
Echo.
Echo _
) > > "% destination%\% name_log%_log.log"
Cls
Color 1f
Title file backup-backup in progress.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
Echo ╭─┤ is backing up the file ├─╮
Echo │ ╰─╯ │
Echo │ operating instructions: │
Echo │ │
Echo │ backup time is proportional to file size and number of files, please │
Echo │ │
Echo │ waits patiently. │
Echo │ │
Echo ╰──╯
Xcopy / c / h / I / g / Q / r% xcopy_parameter% / x / y "% source%"% destination%" > nul 2 > nul
Attrib / s / d + s + r "% destination%\ *. *" > nul 2 > nul
:: add the ability to submit a report when a scheduled task goes wrong
::
When using scheduled tasks to have the system run some commands or programs automatically, if an error occurs at run time
In the default settings of the system, scheduled tasks do not submit error reports.
:: this setting allows the scheduled task to pop up a prompt when an error occurs.
:: to disable this feature, delete NotifyOnTaskMiss under SchedulingAgent in the registry
::
:: reg add HKLM\ SOFTWARE\ Microsoft\ SchedulingAgent / v NotifyOnTaskMiss / t REG_DWORD / d 00000001 / f > nul 2 > nul
Cls
Title backup log
Echo.
Echo.
Type "% destination%\% name_log%_log.log"
Echo.
Echo.
Echo.
Echo press any key to continue.
Pause > nul
Cls
Title backup task list
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo _
Echo.
For I in (copytime%) do (
Echo has added monthly ^ (week ^)% copydate% day% I backup tasks for "% source%"
)
Echo.
Echo _
Echo.
Echo if you want to continue adding backup tasks, please enter B and any other keys to exit.
Echo.
Echo.
Set again=
Set / p again= Please select the next operation code:
If / I "% again%" = = "b" goto input_source
Exit
Rem = Delete files or directories that are no longer in use
: del_nouse
The purpose of the following statement is: if a backup task is stopped, check the bat file generated by this program on the hard disk
Which are not in the at task list; if so, delete the bat and delete the corresponding string value in the registry
:: if not, no deletion is made
:: delete the directory created by this program under% ProgramFiles% if it is empty
Attrib-h-r-s "% ProgramFiles%\ backup task program\ * .bat" > nul 2 > nul
Setlocal enabledelayedexpansion
For% I in ("% ProgramFiles%\ backup task program\ * _ backup.bat") do (
Set full_name=%%i
Set partnered nameplate filled with fullware namelug 0mlle 11!
At | find / I "% I" > nul | | find / I "Code by JM"! partnernameroomroom.bat "> nul & & (
Del / f / Q "! partnamekeeper room.bat"
Reg delete HKLM\ SOFTWARE\ Microsoft\ Windows\ CurrentVersion\ Run / v% ~ fi / f > nul 2 > nul
)
)
For% I in ("% ProgramFiles%\ backup task program\ * .bat") do (
Find / I "Code by JM"% I" > nul & & attrib + r "% I"
)
If not exist "% ProgramFiles%\ backup Task Program" goto: eof
Dir / a / b "% ProgramFiles%\ backup task program" | findstr. > nul | | rd / Q "% ProgramFiles%\ backup task program"
Goto: eof
:: ━ the following code is the error prompt ━
: system_error
Cls
Color 0c
Title file backup-not supported by the operating system
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
├─╮ is not supported in echo ╭─┤ operating system
Echo │ ╰─╯ │
Echo │ │
Echo │ │
Echo │ is very sorry, this program can only run │ in XP environment.
Echo │ │
The echo │ program is about to exit. │
Echo │ │
Echo ╰──╯
Ping 127.1-n 4 > nul & & goto: eof
: popedom_error
Cls
Color 0c
Title File backup-insufficient permissions
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
Insufficient permissions for echo ╭─┤ ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ │
Echo │ │
Echo │ is very sorry, the current user privilege is too low to run this program │
Echo │ │
Echo │ Please switch to another user account with administrator group privileges to run │
Echo │ │
Echo │ press any key to exit... │
Echo │ │
Echo ╰──╯
Pause > nul
Goto: eof
: subarea_noexist
Cls
Color 0c
Title File backup-disk'% subarea% 'does not exist
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
├─╮ does not exist in echo ╭─┤ disk partition
Echo │ ╰─╯ │
Echo │ │
Echo │ │
│ does not exist on the partition with echo │ drive letter subarea%
Echo │ │
Echo │ press any key to return to the previous step to reselect the path │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_destination
: source_noexist
Cls
Color 0c
Title File backup-File does not exist
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
├─╮ does not exist in echo ╭─┤ file
Echo │ ╰─╯ │
Echo │ │
Echo │ │
│ does not exist in the file to be backed up by echo │
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_source
: forbid_to_backup
Cls
Color 0c
Title File backup device-disable backup
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
Echo ╭─┤ prohibits backup of ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ │
Echo │ this program does not support full backup of │
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_source
: forbid_to_build_1
Cls
Color 0c
Title File backup-disable creation
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
Echo ╭─┤ prohibits the creation of ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ │
Echo │ for the sake of data security, do not back up the │ directly to the root directory
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_destination
: forbid_to_build_2
Cls
Color 0c
Title File backup-disable creation
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
Echo ╭─┤ prohibits the creation of ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ warning: save location is the same as the path of the file to be backed up │
Echo │ │
Echo │ or │ in a directory where the files are to be backed up
Echo │ │
Echo │ for the security of the data, please re-select the save location │
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_destination
: destination_input_erro
Cls
Color 0c
Title File backup-path input error
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
Echo ╭─┤ path input error ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ │
Echo │ your path entry has an error │
Echo │ │
Echo │ Please enter colon and backslash │ in half-corner state
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_destination
: date_error
Cls
Color 0c
Title File backup-date input error
Echo.
Echo ╭─╮
Echo ╭─┤ date entry error ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ your date was entered incorrectly │
Echo │ │
Echo │ │
Echo │ 1. Dates cannot be mixed with letters and numbers; │
Echo │ │
Echo │ 2. A single numeric date cannot be greater than 31, and the number cannot exceed │
Echo │ │
31 echo │; │
Echo │ │
Echo │ 3. The alphabetical date can only be the │ in M ·T ·J ·W ·H ·F ·S ·Su
Echo │ │
Any number of echo │, case-insensitive; │
Echo │ │
Echo │ 4. Dates can only be separated by commas. │
Echo │ │
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Pause > nul
Goto input_date
: time_error
Cls
Color 0c
Title File backup-time input error
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
Echo ╭─┤ time input error ├─╮
Echo │ ╰─╯ │
Echo │ │
Echo │ │
Echo │ your time entry has an error │
Echo │ │
Echo │ hours cannot be greater than 24, minutes cannot be greater than 60, and │ is separated by spaces at each time point
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_time
: name_exist
Cls
Color 0c
Title file backup-program% name%_backup.bat with the same name already exists
Echo.
Echo.
Echo.
Echo.
Echo.
Echo ╭─╮
There is a program ├─╮ with the same name in echo ╭─┤.
Echo │ ╰─╯ │
Echo │ │
Echo │ │
A batch program │ with the same name already exists under echo │ "% ProgramFiles%\ backup Task Program"
Echo │ │
Echo │ press any key to return to the previous step to reselect │
Echo │ │
Echo ╰──╯
Echo.
Pause > nul
Goto input_name
:: ━ the following code is the called subprocedure ━
Rem = View the contents under the save location to determine actions such as append / overwrite / reselect, etc. =
: view_directory
Explorer "destination%"
Goto: eof
Rem = simplify operations when backups are needed every day =
: all_date
Set copydate=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
Goto input_time
Goto: eof
Rem = restore files from backup files =
: revert
Explorer "% ProgramFiles%\ backup Task Program"
Goto input_source
Goto: eof
Rem = Show backup list =
: list
Cls
Color 1f
Title File backup-backup list
Echo.
Echo _
Echo.
Echo backup task name: "% name%"
Echo.
File to be backed up by echo: "% source%"
Echo.
Echo save location: "% destination%"
Echo.
Echo backup date:% copydate%
Echo.
Echo backup time:% copytime%
Echo.
Echo _
Echo.
Goto: eof
Rem = update headers in the log =
: build_head
(
Echo: head
Echo set times=1
Echo ^ (
Echo echo _
Echo echo.
Echo echo * Update list ^ ^ (% date:~0,10%% time:~0, 8% ^ ^):
Echo echo.
Echo ^) ^ > ^ > "% destination%\% name_log%_log.log"
Echo goto: eof
) > > "% batch_directory%\% name%_backup.bat"
Goto: eof
This is the end of this article on "how to implement document backup V2.3 with batch processing". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.