Skip to content

Instantly share code, notes, and snippets.

@redtrillix
Last active August 4, 2022 05:45
Show Gist options
  • Save redtrillix/0accadd9175fd5ea21705dfa0d146b84 to your computer and use it in GitHub Desktop.
Save redtrillix/0accadd9175fd5ea21705dfa0d146b84 to your computer and use it in GitHub Desktop.
A batch backup script that uses 7-zip command-line.
:: Revision 2.2.5 | 2022-07-20 | 12:01
echo off
set year=%date:~-4,4%
set month=%date:~-7,2%
set day=%date:~-10,2%
set hour=%time:~-11,2%
set hour=%hour: =0%
set min=%time:~-8,2%
set zipfilename=%~n1%year%-%month%-%day%_%hour%-%min%
set destination=%~dp1
::update these for your situation
set source="(Put the path you want backed up here.)"
set dest="%destination%(Put where you want to save your backup here.)"
set AppExePath="%ProgramFiles(x86)%\7-Zip\7z.exe"
if not exist %AppExePath% set AppExePath="%ProgramFiles%\7-Zip\7z.exe"
if not exist %AppExePath% goto notInstalled
::These 5 lines are a preference for if you would like the script to close certain apps.
::update these for your situation.
echo Close all programs that are open in %source%.
echo Press any key when you have saved them.
pause
echo Backing up %source% to %dest%
%AppExePath% a -r -mx9 -t7z -x!~$*.* %dest% %source%
echo %source% backed up to %dest% is complete!
goto end
:notInstalled
echo Can not find 7-Zip, please install it from:
echo http://7-zip.org/
:end
::update these for your situation
START (If you would like the backup directory to open when it finishes, put the path here)
pause
@redtrillix
Copy link
Author

redtrillix commented Jul 20, 2022

Changelogs are viewable here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment