Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple 7-Zip based backup script
@echo off
REM # Send To Backup Script
REM # Author - Matt Little (http://matthewjlittle.com)
REM # Adam Caudill (http://adamcaudill.com)
REM #
REM # To install:
REM #
REM # (windows 7):
REM # Goto Start->Run. Type in shell:sendto
REM # Save as Backup.bat
REM #
REM # To use:
REM # right click on the folder you want to backup and click on the batch file
REM # in the sendto menu.
REM #
REM # Example:
REM #
REM # If you are in this folder and run the script on Production folder a
REM # backup of the folder is placed in
REM # X:\App\Prod\Backups\Prod.YYYY.MM.DD.HHMI.zip
REM #
set year=%date:~-4,4%
set month=%date:~-10,2%
set day=%date:~-7,2%
set hour=%time:~-11,2%
set hour=%hour: =0%
set min=%time:~-8,2%
set zipfilename=%~n1.%year%.%month%.%day%.%hour%%min%.zip
set destination=%~dp1
set source="%~1\*"
set dest="%destination%Backups\%zipfilename%"
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
echo Backing up %source% to %dest%
%AppExePath% a -rtzip %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
PAUSE
@ARNik

This comment has been minimized.

Copy link

@ARNik ARNik commented Jun 7, 2017

it says :
Command Line Error:
Too long switch:
-rtzip

@fatihkaratay

This comment has been minimized.

Copy link

@fatihkaratay fatihkaratay commented Oct 3, 2017

Same!
Command Line Error:
Too long switch:
-rtzip

@philipshannon

This comment has been minimized.

Copy link

@philipshannon philipshannon commented Dec 27, 2017

I was able to get past this "too long switch:" error by changing -rtzip

change to:

-r -tzip

@smling

This comment has been minimized.

Copy link

@smling smling commented Apr 13, 2018

For resolve region issue, you can get datetime via WMI query

for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined currentDate set currentDate=%%x
set year=%currentDate:~0,4%
set month=%currentDate:~4,2%
set date=%currentDate:~6,2%
set hour=%currentDate:~8,2%
set minute=%currentDate:~10,2%
set second=%currentDate:~12,2%

@rejazz

This comment has been minimized.

Copy link

@rejazz rejazz commented Apr 16, 2018

Thank you! I just change -rtzip to -r -tzip

@uaiz

This comment has been minimized.

Copy link

@uaiz uaiz commented Apr 3, 2020

set date=%currentDate:~6,2%

set day=%currentDate:~6,2%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.