7-Zip Backup Script
Friday, October 31st, 2008Overview
The Computer Assisted Translation MSC runs using Microsoft Virtual PC 2007 software.
The host computers are all PC Caledonia student microlab machines, and the VPC machines are configured to share drive C: of the host as drive F: of the guest.
- Folder C:temp of the host - or F:temp of the VPC guest - is writeable.
- Students also have a networked home drive, H:, on the host PC.
We seek a mechanism to backup files in three key folders of the VPC guest to the shared folder,
from where the backup may be copied to the student’s home folder or USB stick, etc.
7-Zip
The 7-Zip freeware package is installed inside each VPC and has a command line option available.
The three folders of interest to backup are
- c:/documents and settings/SML Student/My Documents
- c:/documents and settings/SML Student/Desktop
- c:/program files/Trados/MTiX/Termbase
The following backup script was written for this purpose. Backup files are first written to
C:temp of the VPC and then copied to shared folder F:temp, then renamed with the
date and time of the backup e.g. 31-10-08-15-32.7z
The Backup Script
@echo off
rem: Purpose: 7-zip backup script
rem: Uses 7-zip to backup ‘My Documents’ of Transcend USB drive to the shared folder F:\temp of the
rem: host PC (PC Caledonia) which, on that host, is actually C:\temp.
rem: Assumes user has logged in as ‘msc’ and profile is ‘c:/documents and settings/SML Student/’
rem:
rem: Author: Dr Duncan J Potter
rem: Date: Oct 31st 2008
cls
echo —— My Documents Backup Script ——-
echo.
echo.
:CHECK
echo 1a. Checking if you have the 7Zip software installed …
if not exist “%programfiles%\7-zip\7z.exe” echo Problem - Zip software 7z.exe was not found
if not exist “%programfiles%\7-zip\7z.exe” pause
if not exist “%programfiles%\7-zip\7z.exe” exit
echo Passed.
echo.
:MKDIR
echo 2. Creating backup folder on shared host folder C:\temp
rem: SRC http://talk.bmc.com/blogs/blog-gentle/anne-gentle/dos-timestamp-tips
set hh=%time:~0,2%
if “%time:~0,1%”==” ” set hh=0%hh:~1,1%
set yymmdd_hhmm=%date:~4,2%-%date:~7,2%-%date:~12,2%-%hh%-%time:~3,2%
echo Done.
echo.
:GENEXCLUDE
echo 3. Generating list of file types to exclude from backup …
rem: Generate a file listing types to exclude from the backup
echo *.avi > %temp%\exclude.txt
echo *.mpg >> %temp%\exclude.txt
echo *.mp3 >> %temp%\exclude.txt
echo *.avi >> %temp%\exclude.txt
echo *.exe >> %temp%\exclude.txt
echo *.dll >> %temp%\exclude.txt
echo *.tmp >> %temp%\exclude.txt
echo *.lnk >> %temp%\exclude.txt
echo Done.
echo.
echo 4a. Starting 7-zip backup …
cd /d “%programfiles%\7-zip”
7z a -r -x@%temp%\exclude.txt c:/temp/mydocs.7z “c:/documents and settings/SML Student/My Documents” “c:/documents and settings/SML Student/Desktop” “c:/program files/Trados/MTiX/Termbase”
echo 7-zip backup of My Documents complete.
echo.
:MKBACKUP
rem: Make Backup folder
if not exist f:\temp echo Problem - folder f:\temp does not exist
if not exist f:\temp pause
if not exist f:\temp exit
if not exist f:\temp\backup mkdir f:\temp\backup
echo 5. Copying your Zip archive to F:\temp\backup folder …
copy /y c:\temp\mydocs.7z F:\temp\backup\%yymmdd_hhmm%.7z
echo Done.
echo.
:TIDY
echo 6. Removing temporary files …
if exist c:\temp\mydocs.7z del /f c:\temp\mydocs.7z > nul
if exist c:\temp\mydocs.7z.tmp del /f c:\temp\mydocs.7z.tmp > nul
echo Done.
echo.
cd /d F:\temp
echo.
echo.
echo.
echo.
echo ——————— Backup Complete ——————
echo a) A compressed copy of your ‘My Documents’ folder has been created.
echo.
echo b) Backups file names are based on the date and time of the backup.
echo Your backup is named F:\temp\backup\%yymmdd_hhmm%.7z
echo.
echo c) On your host PC Caledonia machine, this file is located inside
echo folder C:\temp\backup.
echo Please copy this to your PC Caledonia H:\ drive or a USB stick.
echo.
echo *Remember any audio and video files that you may have are
echo excluded from this backup.
echo.
echo ————————————————————–
echo.
echo.
pause