Automated backup of Windows workstations using rsync and vshadow - Part 1

If you have a desire to maintain work stations in the most “protected” state, as well as as much as possible to “automate” this process, then this post is for you.

It will be used:

A little batch file
A little Linux server
A little Windows Server 2008 R2 and Group Policies

The idea is as follows: from the user himself, so as not to interrupt his work, make a weekly copy of his profile in order to eliminate data loss, and save it on the server as much as possible protected form.

To do this, start with the client side.We use shadow volume create - expand in order to eliminate the problem of unreadable files opened by the user, such as Outlook pst, or documents. We need a Microsoft kit that contains vshadow - this is the Volume Shadow Copy Service SDK 7.2, which can be downloaded for free from Microsoft servers, http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23490 . We will need vshadow.exe and vshadow.pdb files from this SDK. Attention - they are different for 64-bit and 32-bit systems.

After installation, they can be found here:

64-bit -% PROGRAMFILES% \ Microsoft \ VSSSDK72 \ TestApps \ vshadow \ bin \ obj-chk \ amd64
32-bit -% PROGRAMFILES% \ Microsoft \ VSSSDK72 \ TestApps \ vshadow \ bin \ release -xp

Also we need a set of files from cwrsync for Windows -http://sourceforge.net/projects/sereds/files/cwRsync/4.2.0/cwRsync_4.2.0_Installer.zip/download

After installation, they can be found here:

% PROGRAMFILES% \ cwRsync \ bin We

put all the files in one folder, let's call it “Backup” for convenience, and start creating a file that will run this “death machine” - in fact, this is a simple batch file that will work out all the actions. Let's call it “backup.cmd” for convenience.

We write to the file:

(unknown magic) This part of the “pasta code” makes a shadow volume copy from C: and connects it to O:, which we will use for copying, and then with the same script remove it. Now the part that is responsible for the actions of rsync: (unknown magic)

setlocal
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK
set SOURCE_VOLUME=C:
set DESTINATION_VOLUME=O:
set CALLBACK_SCRIPT=%~dpnx0
set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
%~dp0\vshadow.exe -nw -p -script=%TEMP_GENERATED_SCRIPT% -exec=%CALLBACK_SCRIPT% %SOURCE_VOLUME%
del /f %TEMP_GENERATED_SCRIPT%
goto :EOF
:IS_CALLBACK
setlocal
call %TEMP_GENERATED_SCRIPT%
%~dp0\vshadow.exe -el=%SHADOW_ID_1%,%DESTINATION_VOLUME%






setlocal
SET CWRSYNCHOME=C:\Backup\ (где папка с файлами rsync и vshadow)
SET CWOLDPATH=%PATH%
SET CYGWIN=nontsec
SET PATH=%CWRSYNCHOME%;%PATH%
SET HOME=С:\Backup\LOG\ (сюда будем сохранять логи)
SET RSYNC_PASSWORD=(тут пароль, который установлен на принимающем сервере rsync)
SET MY_NAME=%computername%

(теперь указываем, что копировать)

SET FS_SRC_HOME="/cygdrive/O/Users/" (используем именно в таком формате, указываем папку до "Users")
SET FS_SRC_BCK="/cygdrive/C/Backup/" (где файлы rsync, чтобы положить их вместе с логами на бекап сервер)

del /q С:\backup\log\*.log (стираем старые логи перед запуском)

(запускаем)

rsync -av --chmod=ug=rwx %FS_SRC_B2% backupusr@hostname::sbackupusr/%MY_NAME%
rsync -avhP --inplace --stats --del --modify-window=1 --log-file=%FS_SRC_BCK%DATA/backupwork.log --exclude-from=%FS_SRC_BCK%DATA/exclude %FS_SRC_HOME% backupusr@hostname::sbackupusr/%MY_NAME%/snapshot/
rsync -av %FS_SRC_BCK% backupusr@hostname::sbackupusr/%MY_NAME%/snapshot/Backup/


The first command we create a directory for the computer name% computername% The
second command, we copy data from a temporarily connected drive O: \ Users, with the log file saved.
With the third command, we copy the entire folder C: \ Backup, for the safety of the log and the program itself.

This line “backupusr @ hostname :: sbackupusr” indicates the user on the receiving side as well as the host of the receiving side. (To be considered in the second psto).

After that, we need to disconnect the O: drive, because if we do not, the next time vshadow will not be able to connect a copy there, and the copy will be made from the old O: \ drive all the time, despite the fact that the files in the user folder have long been changed.

(unknown magic)

SET HOME=%HOMEDRIVE%%HOMEPATH%

VSHADOW.EXE -ds=%SHADOW_ID_1%


You need to put all this into a regular .cmd file, as I already mentioned above, save it to the Backup folder, where rsync and vshadow files are stored, and run it as needed. It works on Windows Vista, Windows 7, Windows XP, 32 and 64-bit

PS: Of course, it will be necessary to raise the host machine, in our case based on * nix, and create partitions that will be protected by true-crypt in case of server theft. Also in the future, this folder can be packed into the msi installer for installation on all workstations via Group Policies and used to create Scheduled Tasks and close access to the Backup folder for the user. But that's another story.

Also popular now: