Skip to content

Instantly share code, notes, and snippets.

@jnwarp
Last active May 4, 2016 00:09
Show Gist options
  • Save jnwarp/4b62822c0f3f1249678357ce74a42776 to your computer and use it in GitHub Desktop.
Save jnwarp/4b62822c0f3f1249678357ce74a42776 to your computer and use it in GitHub Desktop.
Create an encrypted backup file for files that have changed in the past week
echo off
cls
:: Change variables below
set encPass=CHANGEME-zRFNnk88GpfFXijBcW7Hjfcp9284CRNoQi6ZPogxTJ5W9fZqD4hGfTlZjlOsY7j-CHANGEME
set username=USERNAME
set backupDir=C:\Users\%username%\backup
set backupZip=C:\Users\%username%\backup.7z
set maxAge=8
:: Other variables
set buildDate=%DATE:~4,10%
set encUnique=%buildDate:~6,4%%buildDate:~3,2%
::set encUnique=NONE
set fileDate=%buildDate:~6,4%-%buildDate:~3,2%-%buildDate:~0,2%
::
:: CREATE BACKUP
::
:: Copy files into the backup directory
robocopy "C:\Users\%username%\Desktop" "%backupDir%\desktop" /e /XJD /XJF /maxage:%maxAge%
robocopy "C:\Users\%username%\Documents" "%backupDir%\documents" /e /XJD /XJF /maxage:%maxAge%
robocopy "C:\Users\%username%\Music" "%backupDir%\music" /e /XJD /XJF /maxage:%maxAge%
robocopy "C:\Users\%username%\Pictures" "%backupDir%\pictures" /e /XJD /XJF /maxage:%maxAge%
robocopy "C:\Users\%username%\Videos" "%backupDir%\videos" /e /XJD /XJF /maxage:%maxAge%
:: Encrypt and zip all files
"C:\Program Files\7-Zip\7z.exe" a -sdel -r -p%encPass%%encUnique% %backupZip% %backupDir%/*
:: Empty the backup directory
rmdir "%backupDir%" /q /s
mkdir "%backupDir%"
pause
exit
::
:: EXTRACT BACKUP
::
:: Move backup out of transmit location
move %backupZip% "%backupDir%\incremental-%fileDate%.7z"
:: Decrypt backup into folder
"C:\Program Files\7-Zip\7z.exe" x -p%encPass%%encUnique% -o%backupDir%\%fileDate%\ "%backupDir%\incremental-%fileDAte%.7z"
:: Delete the incremental backup
del "%backupDir%\incremental-%fileDAte%.7z"
pause
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment