Skip to content

Instantly share code, notes, and snippets.

@MRuy
Created May 11, 2015 23:27
Show Gist options
  • Save MRuy/21c0e19c4da22c11520c to your computer and use it in GitHub Desktop.
Save MRuy/21c0e19c4da22c11520c to your computer and use it in GitHub Desktop.
Send To Backup Script (Excluding: .sass_cache, node_modules, bower_components)
@echo off
REM # Send To Backup Script
REM # Author: Matthias Ruchay (http://mruy.de/)
REM # Original script: https://gist.github.com/adamcaudill/2322221
REM #
REM # Excluding folders: (Never touch this folders!)
REM # .sass_cache
REM # node_modules
REM # bower_components
REM #
REM # To install:
REM #
REM # (windows 7):
REM # Goto: %APPDATA%\Microsoft\Windows\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 #
set AppExePath="%ProgramFiles(x86)%\7-Zip\7z.exe"
REM # Helper function for international date usage
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set II=%dt:~10,2%
set SS=%dt:~12,2%
set YYYYMMDD_HHIISS=%YYYY%-%MM%-%DD%_%HH%-%II%-%SS%
REM # Check for 7-Zip
if not exist %AppExePath% set AppExePath="%ProgramFiles%\7-Zip\7z.exe"
if not exist %AppExePath% goto notInstalled
REM # Set variables
set source="%~1\*"
set zipfilename=%~n1_%YYYYMMDD_HHIISS%.zip
set destination=%~dp1
set dest="%destination%Backups\%zipfilename%"
REM # Run 7-Zip
%AppExePath% a -rtzip %dest% %source% -x!bower_components -x!node_modules -x!.sass_cache >nul
if NOT %errorlevel% == 0 goto :error
echo %source% backed up to %dest% is complete!
goto end
:error
echo Error!
echo.
pause
goto end
:notInstalled
echo Can not find 7-Zip, please install it from:
echo ---> http://7-zip.org/
echo.
pause
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment