Is it just み?

Tag: Batch

Simple backups with windows 2

by on Dec.03, 2009, under Programmierung, Technik

Ich werde mal versuchen einige meiner Einträge auf Englisch zu verfassen – um in der Übung zu bleiben.

Update: I made additional changes to the script which are a real improvement for my daily use. The current version is “0.3d [2010-01-08]”

Last week I wrote about a simple way to zip all subfolders of a specific folder which I use for my simple archiving strategy at work. Today I would like to show you a simple script I wrote which backups files listed in a configuration file using rar and puts them into a single archive named after the current date and time. I wrote it to be used as a scheduled task that runs every few hours on some windows machine that is always on.1

I will not show the complete code here, since it’s about 150 lines. You can download the whole script package as .zip-archive.

The archive contains four files:

INFO-README.TXT Some Information about the script
KPSBackupList.ini The file containing the list of files to backup. Can be changed in the KPSFileBackup.bat
startHidden.vbs Just a simple Script file to start the batch file without showing a console-window
FileBackupConfig.bat The batch config file. It contains the config-section where you can change the settings as explained below
KPSFileBackup.bat The actual batch file, you may run.

The following settings are available:

backupFilelist The file containing the list of all files that should be backed up
destinationDir Destination directory where all backup files are stored
prefix The prefix is put before the date in the name of the backup file
retryTime Number of seconds to wait before retrying if one of the files was open and could therefore not be put into the archive. This is an approximate value since I hadd to use a workaround to put the script to sleep.
maxRetries Number of times the script will retry if one of the files was open
backupsToKeep The number of old backups to keep
rarPath Path to the RAR2 executable file

1 The reason for using a batch script and a Windows machine is simple: They do not use linux here. Though I might get my own litte Debian VM in the future, for now Windows has to suffice.

2 The reason for using RAR is simple: It comes preinstalled on all machines here.

Comments Off on Simple backups with windows 2 :, , , , , more...

Simple backups with windows 1

by on Nov.26, 2009, under Computer, Programmierung

Ich werde mal versuchen einige meiner Einträge auf Englisch zu verfassen – um in der Übung zu bleiben.

At my current workplace, working with Linux (or anything other than windows) seems to be something no one would even bother to think about.  So I had to dig into the world of Windows Batch Scripting in order to create those little tools that make my life  just a bit easier when using linux.

The first thing I had to do was creating a script that simply backups folders. I have a folder which contains other folders that should be archived – I usually zip (or 7zip) them and move them to the backup space later, which is a fairly easy task using a bash-script and nautilus actions.

Under windows it’s not that much harder to accomplish. (In the following example I used WinRAR to compress the files because that’s what we use at work.)

The first thing I needed was of course the batch-file that does the actual work. Here it is:

@echo off

rem ===================== Begin Configuration =====================
rem !!! Do not use quotes for the values of the following variables !!!

rem Path to the WinRAR executable file
set winrarPath=%PROGRAMFILES%\WinRAR\WinRAR.exe

rem ====================== End Configuration ======================

rem Please only edit after this line if you know exactly what you are doing.

set curVer=0.1 [2009-11-26]

rem ======================== Begin Script ========================

rem Tell the user which version of the tool they use
echo                     Mi ArchiveSubfolders version %curVer%

if not exist "%winrarPath%" (
    echo Cannot find WinRAR exe file: %winrarPath%
    goto eof

set dir=%*
if not exist "%dir%" (
    echo The directory "%dir%" cannot be found
    goto eof

set dateString=%DATE:~-4,4%-%DATE:~-7,2%-%DATE:~0,2%_%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%

cd "%dir%"
for /D %%a in (*) do (
    rem Creating the archive
    echo Archiving "%%~na"...
    "%winrarPath%" M -afzip -ibck -inul -m5 "" "%%a"

echo Archiving done


Now that is a nice, simple script, but what should I do with it? I wanted it to be useable directly in the explorer context-menu, so I made a small registry-entry. This is the exported .reg-file:

Windows Registry Editor Version 5.00

@="Mi: Archive Subfolders (ZIP)"

@="cmd /c \"\"%%ProgramFiles%%\\MiTools\\archiveSubfolders\\archiveSubfolders.bat\"\" %1"

Now I wanted a simple installation-script, for really lazy people like me:

@echo off

set installDir=%PROGRAMFILES%\MiTools\archiveSubfolders

if not exist "%installDir%" (
    mkdir "%installDir%"

copy archiveSubfolders.bat "%installDir%"
copy "ArchiveSubfolders Context Menu Entry.reg" "%installDir%"

regedit /S "ArchiveSubfolders Context Menu Entry.reg"

echo Installation complete.

Comments Off on Simple backups with windows 1 :, , , , , more...