📜 ⬆️ ⬇️

Windows: remote backup using snapshots (VShadow)

When backing up by simply copying files, the question arises: "How to ensure data integrity." After all, if, for example, to copy a 50-gig base database of a lotus server, then in the process of copying one part, the other may change and integrity will be broken. And in some cases (for example, with databases) it may be necessary to stop the service, but it is not possible to stop it for a couple of hours.

For such tasks, Windows has a useful tool. I first learned about this technology while working with FreeBSD, then I learned about LVM on Linux, and after searching for the same solution for Windows, I found that it also exists here and is called Volume Shadow Copy.

This technology allows you to make an instant copy of the file system, which is static in time, while the original file system continues to work in normal mode. To back up databases in this way, you can stop the database (when possible), create an impression, start the database again, and then quietly copy the files using the created impression.
')
I will give an example of an automatic creation of an impression for backing up the Lotus Domino database (it does not require stopping) and explain how it works. The script can be easily adapted to your needs.


snapshot.cmd


rem Go to the script's directory
%~d0
cd %~dp0

rem Get options or exit
call snapshot_env.cmd || exit 1

date /t > %snapshot_date%
date /t >> %snapshot_status%

rem Delete the oldest shadow of the specified volume
vshadow - do = %snapshot_drive% > %snapshot_create_volume% && echo Removing old OK >> %snapshot_status% || echo Removing old ERR >> %snapshot_status%
rem Force removing the share if it haven't done itself (it happens sometimes)
net share %snapshot_share% /delete

rem Create a persistent shadow copy
vshadow -p -script = %snapshot_var_script% %snapshot_drive% >> %snapshot_create_volume% && echo Snapshot OK >> %snapshot_status% || echo Snapshot ERR >> %snapshot_status%
call %snapshot_var_script%

rem Expose a child directory from the shadow copy as a share
vshadow -er = %SHADOW_ID_1% , %snapshot_share% , %snapshot_path% && echo Sharing OK >> %snapshot_status% || echo Sharing ERR >> %snapshot_status%

echo --- >> %snapshot_status%


snapshot_env.cmd


set snapshot_drive = e:
set snapshot_path = lotus
set snapshot_share = lotus$
set snapshot_var_script = snapshot_vars.cmd
set snapshot_status = logs\snapshot_status.log
set snapshot_create_volume = logs\snapshot_create_volume.log
set snapshot_date = %snapshot_drive% \ %snapshot_path% \snapshot_date.log


How it works


- The script snapshot.cmd reads parameters from the file snapshot_env.cmd after launch
- The file% snapshot_date% is created in the directory to be archived (I will explain later)
- Removes old snapshots, if any, and shared directories
- Creates a new snapshot for% snapshot_drive%
- Share the% snapshot_path% directory with the network name% snapshot_share% (i.e. via the network, you can refer to this directory as \\ server \ lotus $). The important point is that the group backup operators will have rights to the directory, which means you will need to create a special user lotus-backup, add it to the Backup operators group and use it in the scripts to connect to the \\ server \ lotus $ folder over the network.
- From this point on, data from the \\ server \ lotus $ directory can be easily and at any pace copied to a safe place :)

And now I’ll say separately about why the% snapshot_date% file was needed. This file is needed in order to be able to distinguish the newly created snapshot from the old one, which for one reason or another has not been deleted. This can be done by checking the date of creation of the file% snapshot_date% (nagios does this with us).

Requirements


- vshadow.exe, necessary for running scripts, you can find in the Volume Shadow Copy Service SDK which can be downloaded at: www.microsoft.com/downloads/en/details.aspx?FamilyID=0b4f56e4-0ccc-4626-826a-ed2c4c95c871
- Work of all this was checked only on Windows Server 2003

PS: by the way, the Windows client of Bacula, as far as I know, also uses the technology "Volume Shadow Copy" in its work.

Source: https://habr.com/ru/post/115758/


All Articles