backup_script_7zip
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
backup_script_7zip [2011/06/14 02:11] – stephen | backup_script_7zip [2017/01/01 20:05] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Backup Script (7-Zip) ===== | ===== Backup Script (7-Zip) ===== | ||
+ | |||
+ | ==== With Fancy Logging ==== | ||
+ | |||
+ | See [[logger|Logger]]. | ||
+ | |||
+ | <code DOS> | ||
+ | @echo off | ||
+ | |||
+ | rem Version 1.1.0 | ||
+ | rem Last Update: 2011-06-24 | ||
+ | |||
+ | rem Usage: | ||
+ | rem | ||
+ | rem | ||
+ | rem | ||
+ | rem | ||
+ | rem | ||
+ | rem | ||
+ | rem | ||
+ | rem Example: | ||
+ | rem | ||
+ | rem | ||
+ | rem | ||
+ | rem NOTE: Do NOT put double quotes in the arguments - it won't work. If the directory has a space, use 8.3 formatted names: | ||
+ | rem | ||
+ | rem | ||
+ | rem | ||
+ | |||
+ | set LoggerExe=C: | ||
+ | set SummaryLogFile=C: | ||
+ | set FullLogFile=C: | ||
+ | |||
+ | echo Info: Backup: **** Starting **** | %LoggerExe% >> %SummaryLogFile% | ||
+ | |||
+ | set AllFlags= | ||
+ | set AllSearch=* | ||
+ | |||
+ | set CSFlags=-x!*.dll -x!*.zip -x!*.pdf -x!*.pdb -x!*.exe | ||
+ | set CSSearch=* | ||
+ | |||
+ | set BatchFlags= | ||
+ | set BatchSearch=*.bat | ||
+ | |||
+ | if [%1]==[] goto ErrorInCommandLineOptions | ||
+ | if [%2]==[] goto ErrorInCommandLineOptions | ||
+ | if [%3]==[] goto ErrorInCommandLineOptions | ||
+ | if [%4]==[] goto ErrorInCommandLineOptions | ||
+ | if [%5]==[] goto ErrorInCommandLineOptions | ||
+ | |||
+ | set TargetName=%1 | ||
+ | set TargetDir=%2 | ||
+ | set ContentType=%3 | ||
+ | set Frequency=%4 | ||
+ | set HaltOnTargetDirError=%5 | ||
+ | |||
+ | set BackupDir=C: | ||
+ | |||
+ | : | ||
+ | if " | ||
+ | if " | ||
+ | |||
+ | echo ERROR: The HaltOnTargetDirError must be ' | ||
+ | echo ERROR: Backup: The HaltOnTargetDirError must be ' | ||
+ | |||
+ | echo. | ||
+ | goto ErrorInCommandLineOptions | ||
+ | |||
+ | : | ||
+ | if exist " | ||
+ | |||
+ | echo ERROR: The target directory (%TargetDir%) does not exist or can not be accessed. | ||
+ | echo ERROR: Backup: The target directory (%TargetDir%) does not exist or can not be accessed. | %LoggerExe% >> %SummaryLogFile% | ||
+ | |||
+ | if " | ||
+ | |||
+ | pause | ||
+ | goto Done | ||
+ | |||
+ | : | ||
+ | if exist " | ||
+ | |||
+ | echo ERROR: The backup directory (%BackupDir%) does not exist or can not be accessed. | ||
+ | echo ERROR: Backup: The backup directory (%BackupDir%) does not exist or can not be accessed. | %LoggerExe% >> %SummaryLogFile% | ||
+ | |||
+ | pause | ||
+ | goto Done | ||
+ | |||
+ | : | ||
+ | if " | ||
+ | if " | ||
+ | if " | ||
+ | |||
+ | echo ERROR: The content type must be ' | ||
+ | echo ERROR: Backup: The content type must be ' | ||
+ | |||
+ | echo. | ||
+ | goto ErrorInCommandLineOptions | ||
+ | |||
+ | : | ||
+ | set Flags=%AllFlags% | ||
+ | set Search=%AllSearch% | ||
+ | goto CheckFrequency | ||
+ | |||
+ | : | ||
+ | set Flags=%CSFlags% | ||
+ | set Search=%CSSearch% | ||
+ | goto CheckFrequency | ||
+ | |||
+ | : | ||
+ | set Flags=%BatchFlags% | ||
+ | set Search=%BatchSearch% | ||
+ | goto CheckFrequency | ||
+ | |||
+ | : | ||
+ | if " | ||
+ | if " | ||
+ | if " | ||
+ | |||
+ | echo ERROR: The frequency must be ' | ||
+ | echo ERROR: Backup: The frequency must be ' | ||
+ | |||
+ | echo. | ||
+ | goto ErrorInCommandLineOptions | ||
+ | |||
+ | : | ||
+ | set CreateBackupCommand=" | ||
+ | goto CheckDailyBackup | ||
+ | |||
+ | : | ||
+ | set CreateBackupCommand=" | ||
+ | goto CleanUpTemps | ||
+ | |||
+ | : | ||
+ | set CreateBackupCommand=copy " | ||
+ | goto CheckDailyBackup | ||
+ | |||
+ | : | ||
+ | if exist " | ||
+ | |||
+ | echo ERROR: The daily backup (" | ||
+ | echo ERROR: Backup: The daily backup (" | ||
+ | |||
+ | pause | ||
+ | goto Done | ||
+ | |||
+ | : | ||
+ | rem Clean up now, just in case the last run died halfway through. | ||
+ | del " | ||
+ | del " | ||
+ | del " | ||
+ | del " | ||
+ | |||
+ | : | ||
+ | |||
+ | echo Pre-check and set up is done. Beginning backup. | ||
+ | echo Info: Backup: [%TargetName% %Frequency%] Pre-check and set up is done. Beginning backup. | %LoggerExe% >> %SummaryLogFile% | ||
+ | |||
+ | %CreateBackupCommand% 2>&1 | %LoggerExe% >> %FullLogFile% | ||
+ | |||
+ | if not exist " | ||
+ | |||
+ | rem Determine if there is any differences between the current backup and the previous backup. | ||
+ | rem 7Zip includes the name of the file in the content list, so we need to make sure the filename is the same for each backup. We only want to know if the *contents* are different. | ||
+ | rem If DOS had a more functional ' | ||
+ | |||
+ | rename " | ||
+ | " | ||
+ | rename " | ||
+ | |||
+ | rename " | ||
+ | " | ||
+ | rename " | ||
+ | |||
+ | fc " | ||
+ | |||
+ | IF ERRORLEVEL 1 GOTO : | ||
+ | |||
+ | ECHO No differences found - throwing the backup away. | ||
+ | echo Info: Backup: [%TargetName% %Frequency%] No differences found - throwing the backup away. | %LoggerExe% >> %SummaryLogFile% | ||
+ | |||
+ | REM No differences found, so just clean up. | ||
+ | del " | ||
+ | del " | ||
+ | del " | ||
+ | GOTO :done | ||
+ | |||
+ | : | ||
+ | |||
+ | ECHO Differences found - storing the backup. | ||
+ | echo Info: Backup: [%TargetName% %Frequency%] Differences found - storing the backup. | %LoggerExe% >> %SummaryLogFile% | ||
+ | |||
+ | del " | ||
+ | del " | ||
+ | |||
+ | : | ||
+ | |||
+ | del " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | rename " | ||
+ | |||
+ | :RollDone | ||
+ | |||
+ | rename " | ||
+ | |||
+ | goto :Done | ||
+ | |||
+ | : | ||
+ | echo Error in command line arguments. | ||
+ | echo. | ||
+ | echo Usage: | ||
+ | echo. | ||
+ | echo | ||
+ | echo. | ||
+ | echo | ||
+ | echo | ||
+ | echo | ||
+ | echo. | ||
+ | echo Example: | ||
+ | echo. | ||
+ | echo | ||
+ | echo. | ||
+ | echo NOTE: Do NOT put double quotes in the arguments - it won't work. If the directory has a space, use 8.3 formatted names: | ||
+ | echo. | ||
+ | echo | ||
+ | echo. | ||
+ | |||
+ | goto :Done | ||
+ | |||
+ | :Done | ||
+ | echo Info: Backup: **** Done **** | %LoggerExe% >> %SummaryLogFile% | ||
+ | </ | ||
+ | |||
+ | ==== Without Fancy Logging ==== | ||
<code DOS> | <code DOS> | ||
Line 167: | Line 417: | ||
ECHO No differences found - throwing the backup away. | ECHO No differences found - throwing the backup away. | ||
- | eventcreate /ID 1 /t INFORMATION /l APPLICATION /so " | + | eventcreate /ID 1 /t INFORMATION /l APPLICATION /so " |
REM No differences found, so just clean up. | REM No differences found, so just clean up. | ||
Line 178: | Line 428: | ||
ECHO Differences found - storing the backup. | ECHO Differences found - storing the backup. | ||
- | eventcreate /ID 1 /t INFORMATION /l APPLICATION /so " | + | eventcreate /ID 1 /t INFORMATION /l APPLICATION /so " |
del " | del " |
backup_script_7zip.1308017505.txt.gz · Last modified: 2017/01/01 19:48 (external edit)