Backup di file aperti con VSHADOW e ROBOCOPY

Argomenti vari di carattere sistemistico
Post Reply
daniele
Posts: 342
Joined: 04 Mar 2009, 13:59

Backup di file aperti con VSHADOW e ROBOCOPY

Post by daniele »

Original article: http://www.eggheadcafe.com/tutorials/as ... e-bac.aspx
ALL RIGHTS RESERVED TO THE AUTHOR OF THE ORIGINAL ARTICLE

Requirement.


The user wanted the ability to see and restore files and folders themselves with previous versions.
A full backup of a system that will run in the background while the user is unaware.

A full backup of a system that includes open files and system files.

A full backup that will not take too much time, CPU or bandwidth on the workstation.

The backup store will be as small as possible.

The backup to run at a regular time intervals.



History.



Previously users copied files using a simple Robocopy script to backup their documents and settings to a server share. This is great once you have done the initial copy as it only copies changed / newer files and removes files from the destination when no longer on the source. However this was rarely done as the user would forget to run the script until it was too late.
The problem was that after a while people wanted to recover files in other directories not just in their documents and settings folders. This would have led to a massive increase of storage for the backups. Also files in use were not backed up like pst files as Robocopy cant copy a file in use.


Solution.



There are lots of free and paid for applications that do full or incremental shadow backups but we needed a simple solution without installing programs everywhere that created massive image files of each machine.



1. User access to backed up files and previous versions.

It had to be files on a share. Easy, create a shared folder on a server for all the machines files to be copied to. Robocopy can copy security info stopping unwanted assess from other users.

Enable Shadow copies for the volume holding the share on the server. (Windows 2003+) this gives the user the option to see a previous version of a file/folder.



2. Shadow copies for open files

I found some useful steps on eggheads for using vshadow so worked from that to set up a simple backup script and finally came up with this.



3. Backup storage space.

In our case 30 machines with an average of 27Gb on their C: drives would be about 800Gb+ of storage. As most of our workstations data is identical windows system files, and the program files etc I used a very handy utility to save space once copied to the server. Microsoft’s Single Instance Storage (SIS) is a utility that finds multiple identical files within its directories and stores a single copy that is cross linked in the file system. Usually SIS comes with Windows storage server only, however it can be used within at least windows standard by installing Windows deployment services (for OS instillation of workstations over the Lan) and only using it for its SIS capabilities. This creates a shared folder on the server that can be used for the destination backup store. Another shared folder within this could easily work too just for the backup. Using this method with windows file compression brings down our storage to about 300Gb. However I’m not so sure the windows compression makes much difference.



The scripting.



The complicated bit is the scripting which would be simple if we wanted to just pull the data from a workstation to a server somewhere, but this wouldn’t fix the open file issues. So I used my limited DOS skills to alter another eggheads script which used vshadow.exe to copy open files.

The new script runs Vshadow.exe which created a snapshot of the c: drive, then calls another script where Dosdev.exe maps the snapshot of the c: drive to be semi visible as the b: drive on the workstation. Robocopy.exe then copies changed files from the b: drive to the server. Viola! The b: drive is that unfortunately Robocopy.exe cannot copy straight from the shadow volume so Dosdev.exe helps here.

Once this script exits and returns to the Vhsadow.exe process the snapshot is deleted on the workstation and the job is done.



You will need the following in the same directory as the scripts or installed on the workstation. Vshadow.exe from Microsoft msdn site. Robocopy.exe from Microsoft’s windows support tools download section. Dosdev.exe I cant remember where I got this but if you Google dosdev.exe you’ll find it.



The command that starts the backup. (local admin rights needed);



vshadow.exe -script=vss-setvar.cmd -exec=vss-exec.cmd c:



The vss-exec.cmd script that is called from Vshadow.exe. Create vss-exec.cmd file containing:



call vss-setvar.cmd

@ECHO OFF

dosdev B: %SHADOW_DEVICE_1%

robocopy B:\ \\server\share\ /mir

dosdev -r -d B:



The above is all you need to start copying everything to a share on a server but the destination could be anything like a USB hard drive.

!! The first time you run this all the files will be copied to the destination so I suggest running when quiet.

It also doesn’t exclude some big files that are not needed. Try adding “/xd *"System Volume Information" *"temporary internet files" *temp *RECYCLER $* /xf pagefile.sys hiberfil.sys *.bak *.cmf /w:0 /r:0” to the robocopy line.




The final solution.



In my situation I wanted to control when the backups fired off especially for the first big run so I used psexec (see Microsoft remote execution tools) to start it remotely as a low priority on all our workstations, and monitor it. Also I put the vss-exec.cmd file on a share elsewhere where it couldn’t be tampered with. Dosdev.exe, robocopy.exe and vshadow.exe are in the c:\windows directories on each workstation.



@names.exe is a file with all the computer names on each line.

\\Store is the server where the workstation backup files are kept and in our case uses SIS too, but also the vss-exec.cmd is kept away from tampering with in the shadowback$ share.



Execute:



psexec @names.txt -low -e -a 0 -u crick\domainadminusername -w c:\ "vshadow.exe" -script="vss-setvar.cmd" -exec="\\store\shadowback$\vss-exec.cmd" c:



Vss-exec.cmd located on the server contains;



call vss-setvar.cmd



@ECHO OFF

dosdev B: %SHADOW_DEVICE_1%



robocopy B:\ \\store\reminst\computers\%computername%\c$\ /mir /sec /log:c:\backup.log /np /xd *"System Volume Information" *"temporary internet files" *temp *RECYCLER $* /xf pagefile.sys hiberfil.sys *.bak *.cmf /w:0 /r:0



dosdev -r -d B:



Conclusion



The above works very well for us using robocopy however using rsync or xcopy should work well too.

I hope this helps some IT manager or developer in their solutions.


Biography - Robert Jeffery
IT manager for a small software house having been in the IT trade for 15 years, and before that in Electronics. Not specializing in anything but being a "Jack of all trades" especially in the Microsoft range.
Post Reply