c# - Shadow copy error using Alphavss -
ii trying utilize sample code provided on site alphavss. trying include class vssbackup.cs , utilize in program. missing dll reference not getting errors on using components. knows problem be?
i getting 3 errors:
the type or namespace name 'snapshot' not found (are missing using directive or assembly reference?)
snapshot _snap;
the type or namespace name 'ivssasync' not found (are missing using directive or assembly reference?
using (ivssasync async = _backup.gatherwritermetadata()) {.......
the type or namespace name 'snapshot' not found (are missing using directive or assembly reference?)
_snap = new snapshot(_backup);
class **vssbackup.cs c# sample code site provides**
/* copyright (c) 2008-2012 peter palotas * * permission hereby granted, free of charge, person obtaining re-create * of software , associated documentation files (the "software"), deal * in software without restriction, including without limitation rights * use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of software, , permit persons whom software * furnished so, subject next conditions: * * above copyright notice , permission notice shall included in * copies or substantial portions of software. * * software provided "as is", without warranty of kind, express or * implied, including not limited warranties of merchantability, * fitness particular purpose , noninfringement. in no event shall * authors or copyright holders liable claim, damages or other * liability, whether in action of contract, tort or otherwise, arising from, * out of or in connection software or utilize or other dealings in * software. */ #region copyright notice /* * alphavss sample code * written jay miller * * code hereby released public domain, applies * worldwide. */ #endregion using system; using system.diagnostics; using system.collections.generic; using alphaleonis.win32.vss; using alphaleonis.win32.filesystem; namespace vsssample { /// <summary> /// class encapsulates simple vss logic. goal allow /// user backup single file shadow re-create (presumably because /// file otherwise unavailable on home volume). /// </summary> /// <example> /// code creates shadow re-create , copies single file /// new snapshot location on d drive. here we're /// using alphafs library create full-file re-create of file. /// <code> /// string source_file = @"c:\windows\system32\config\sam"; /// string backup_root = @"d:\backups"; /// string backup_path = path.combine(backup_root, /// path.getfilename(source_file)); /// /// // initialize shadow re-create subsystem. /// using (vssbackup vss = new vssbackup()) /// { /// vss.setup(path.getpathroot(source_file)); /// string snap_path = vss.getsnapshotpath(source_file); /// /// // here utilize alphafs library create copy. /// alphaleonis.win32.filesystem.file.copy(snap_path, backup_path); /// } /// </code> /// code creates shadow re-create , opens stream on file /// on new snapshot volume. /// <code> /// string source_file = @"c:\windows\system32\config\sam"; /// /// // initialize shadow re-create subsystem. /// using (vssbackup vss = new vssbackup()) /// { /// vss.setup(path.getpathroot(filename)); /// /// // can access shadow re-create either retrieving stream: /// using (stream s = vss.getstream(filename)) /// { /// debug.assert(s.canread == true); /// debug.assert(s.canwrite == false); /// } /// } /// </code> /// </example> public class vssbackup : idisposable { /// <summary> /// setting flag true enable 'component mode', /// not, in example, much of substance. /// </summary> /// <remarks> /// vss has ability selectively disable vss-compatible /// components according specifics of current backup. 1 /// might, example, quiesce outlook if outlook pst /// file intended backed up. examinecomponents() method /// provides framework sort of mode if you're interested. /// otherwise, illustration code quiesces vss-compatible components /// before making shadow copy. /// </remarks> bool componentmode = false; /// <summary>a reference vss context.</summary> ivssbackupcomponents _backup; /// <summary>some persistent context current snapshot.</summary> snapshot _snap; /// <summary> /// constructs vssbackup object , initializes of necessary /// vss structures. /// </summary> public vssbackup() { initializebackup(); } /// <summary> /// sets shadow re-create against specified volume. /// </summary> /// <remarks> /// methods separated out constructor because if /// throws, still want dispose() method called. /// </remarks> /// <param name="volumename">name of volume copy.</param> public void setup(string volumename) { discovery(volumename); prebackup(); } /// <summary> /// disposal of object involves sending completion notices /// writers, removing shadow copies scheme , /// releasing backupcomponents object. method must /// called when class no longer used. /// </summary> public void dispose() { seek { complete(true); } grab { } if (_snap != null) { _snap.dispose(); _snap = null; } if (_backup != null) { _backup.dispose(); _backup = null; } } /// <summary> /// stage initializes both requester (this program) , /// writers on scheme in preparation backup , sets /// communcation channel between two. /// </summary> void initializebackup() { // here retrieving os-dependent object encapsulates // of vss functionality. os indepdence single // mill method provides 1 of alphavss's major strengths! ivssimplementation vss = vssutils.loadimplementation(); // create backupcomponents object manage backup. // object have one-to-one relationship backup // , must cleaned when backup finishes (ie. cannot // reused). // // note object fellow member of our class, needs // stick around total backup. _backup = vss.createvssbackupcomponents(); // must initialize components. can either start // fresh backup passing null here, or resume previous // backup operation through before utilize of savexml method. _backup.initializeforbackup(null); // @ point, we're supposed found communication // writers on system. possible before step // enable or disable specific writers via backupcomponents' // enable* , disable* methods. // // note 'using' build here dispose of asynchronous // comm link 1 time no longer need it. using (ivssasync async = _backup.gatherwritermetadata()) { // because allowing writers prepare metadata can take // while, given vssasync object gives // status on background operation. in case, // wait finish. async.wait(); } } /// <summary> /// stage involes requester (us, again) processing /// info received writers on scheme find out /// volumes - if - must shadow copied perform total /// backup. /// </summary> void discovery(string fullpath) { if (componentmode) // in component mode, need enumerate through each // component , decide whether should added our // backup document. examinecomponents(fullpath); else // 1 time finished author metadata, can dispose // of it. if in component mode, want maintain // around notify writers of our success or // failure when finish backup. _backup.freewritermetadata(); // utilize our helper class add together appropriate volume // shadow re-create set. _snap = new snapshot(_backup); _snap.addvolume(path.getpathroot(fullpath)); } /// <summary> /// method optional in implementation, , in fact /// nil of substance. demonstrate how 1 might parse /// through various writers on scheme , add together them /// backup document if necessary. /// </summary> /// <param name="fullpath">the total path of file up.</param> void examinecomponents(string fullpath) { // @ point requester's duty examine // writers have prepared us. writermetadata property // (in place of c api's 'getwritermetadata' function) collects // metadata each author behind list interface. ilist<ivssexaminewritermetadata> writer_mds = _backup.writermetadata; // if receive "bad state" error when enumerating, might // have registry inconsistency programme improperly // uninstalled itself. if event log showing error like, // "contentindexingservice called routine regqueryvalueexw // failed," you'll want read microsoft's kb article #907574. foreach (ivssexaminewritermetadata metadata in writer_mds) { // can see name of writer, if like. trace.writeline("examining metadata " + metadata.writername); // of import bit of writers' metadata list of // components each author broken into. these components // responsible number of files, going through // info allows build initial list of files our // shadow copies. foreach (ivsswmcomponent cmp in metadata.components) { // print out info each component. trace.writeline(" component: " + cmp.componentname); trace.writeline(" component info: " + cmp.caption); // if component available backup, it's // decide whether relevant current backup. // this, may examine files each component manages. foreach (vsswmfiledescription file in cmp.files) { // thought here find out whether these files // relevant whatever purpose application holds. if // are, should a) add together component backup // set vss involves in shadow re-create operation, , // b) record files' volume names know later // volumes need shadow copied. // i'm not worried stuff example, though, // instead i'm printing out stuff might need // examine if have requirements of sort. trace.writeline(" path: " + file.path); trace.writeline(" spec: " + file.filespecification); // here might insert logic to: // // 1. check whether alternatelocation property valid. // 2. expand environment vairables in either path.or // alternatelocation, appropriate. // 3. considering filespecification , isrecursive // properties, decide whether component manages // file(s) wish backup (in case, // fullpath argument). // // if component relevant, add together addcomponent(). // (the filetopathspecification method below might help // of these steps.) } } } } /// <summary> /// phase of backup focused around creating shadow copy. /// notify writers of impending snapshot, after /// have short period of time on-disk info in order , /// quiesce writing. /// </summary> void prebackup() { debug.assert(_snap != null); // next bit way tell writers sort of backup // should preparing for. of import parts // first , 3rd arguments: want full, // backup and, depending on whether in component mode, either // full-volume backup or backup requires specific // components. _backup.setbackupstate(componentmode, true, vssbackuptype.full, false); // here need send messages each author our // snapshot imminent, using (ivssasync async = _backup.prepareforbackup()) { // before, 'using' statement automatically disposes of // our comm link. before, block while // writers finish background preparations. async.wait(); } // it's time create snapshot. each author have // freeze i/o selected volumes 10 seconds // while process takes place. _snap.copy(); } /// <summary> /// simple method uses bit of string manipulation turn /// full, local path corresponding snapshot path. /// method may help users perform total file copies snapsnot. /// </summary> /// <remarks> /// note system.io methods not able access files on /// snapshot. instead, need utilize alphafs library /// shown in example. /// </remarks> /// <example> /// code creates shadow re-create , copies single file /// new snapshot location on d drive. here we're /// using alphafs library create full-file re-create of file. /// <code> /// string source_file = @"c:\windows\system32\config\sam"; /// string backup_root = @"d:\backups"; /// string backup_path = path.combine(backup_root, /// path.getfilename(source_file)); /// /// // initialize shadow re-create subsystem. /// using (vssbackup vss = new vssbackup()) /// { /// vss.setup(path.getpathroot(source_file)); /// string snap_path = vss.getsnapshotpath(source_file); /// /// // here utilize alphafs library create copy. /// alphaleonis.win32.filesystem.file.copy(snap_path, backup_path); /// } /// </code> /// </example> /// <seealso cref="getstream"/> /// <param name="localpath">the total path of original file.</param> /// <returns>a total path same file on snapshot.</returns> public string getsnapshotpath(string localpath) { trace.writeline("new volume: " + _snap.root); // bit replaces file's normal root info root // info our new shadow copy. if (path.ispathrooted(localpath)) { string root = path.getpathroot(localpath); localpath = localpath.replace(root, string.empty); } string slash = path.directoryseparatorchar.tostring(); if (!_snap.root.endswith(slash) && !localpath.startswith(slash)) localpath = localpath.insert(0, slash); localpath = localpath.insert(0, _snap.root); trace.writeline("converted path: " + localpath); homecoming localpath; } /// <summary> /// method opens stream on shadow re-create of specified /// file. /// </summary> /// <example> /// code creates shadow re-create , opens stream on file /// on new snapshot volume. /// <code> /// string source_file = @"c:\windows\system32\config\sam"; /// /// // initialize shadow re-create subsystem. /// using (vssbackup vss = new vssbackup()) /// { /// vss.setup(path.getpathroot(filename)); /// /// // can access shadow re-create either retrieving stream: /// using (stream s = vss.getstream(filename)) /// { /// debug.assert(s.canread == true); /// debug.assert(s.canwrite == false); /// } /// } /// </code> /// </example> public system.io.stream getstream(string localpath) { // getsnapshotpath() returns funky-looking path. // system.io methods can't handle these sorts of paths, instead // we're using alphafs, first-class library alpha leonis. // note have no 'using system.io' @ top of file. // (the stream returns, however, system.io stream.) homecoming file.openread(getsnapshotpath(localpath)); } /// <summary> /// final phase of backup involves cleanup steps. /// if we're in component mode, we're supposed notify each of /// writers of outcome of backup. 1 time that's done, or if /// we're not in component mode, send backupcomplete event /// of writers. /// </summary> /// <param name="succeeded">success value of writers.</param> void complete(bool succeeded) { if (componentmode) { // before, iterate through of writers on system. // more efficient method might iterate through writers // involved in backup. ilist<ivssexaminewritermetadata> writers = _backup.writermetadata; foreach (ivssexaminewritermetadata metadata in writers) { foreach (ivsswmcomponent component in metadata.components) { // backupsucceeded phone call should mirror addcomponent // phone call called during discovery phase. _backup.setbackupsucceeded( metadata.instanceid, metadata.writerid, component.type, component.logicalpath, component.componentname, succeeded); } } // finally, can dispose of author metadata. _backup.freewritermetadata(); } seek { // backupcomplete event must sent of writers. using (ivssasync async = _backup.backupcomplete()) async.wait(); } // not sure why, throws vss_bad_state on xp , w2k3. // per forum posts this, i'm ignoring it. grab (vssbadstateexception) { } } /// <summary> /// method takes info in file description , /// converts total path specification - wildcards. /// </summary> /// <remarks> /// using wildcard-to-regex library found @ /// http://www.codeproject.com/kb/string/wildcmp.aspx on /// output of method might helpful. /// </remarks> /// <param name="file">object describing component's file.</param> /// <returns> /// returns total path, potentially including dos wildcards. eg. /// 'c:\windows\config\*'. /// </returns> string filetopathspecification(vsswmfiledescription file) { // environment variables (eg. "%windir%") common. string path = environment.expandenvironmentvariables(file.path); // utilize alternate location if it's present. if (!string.isnullorempty(file.alternatelocation)) path = environment.expandenvironmentvariables( file.alternatelocation); // normalize wildcard usage. string spec = file.filespecification.replace("*.*", "*"); // combine file specification , directory name. homecoming path.combine(path, file.filespecification); } } }
i ran same issues when attempting utilize sample code. should note in add-on linking, , adding references references need alphavss, code uses alphafs. in particular, should link , reference alphafs.dll package.
the snapshot class not found...you should bring in snapshot.cs file sample project.
but wait...there's more...
this bit frustrating til found few clever notes in change log version 1.1.
"* breaking change: class vsswmfiledescription has been renamed vsswmfiledescriptor
breaking change: ivssasync interface has been removed. methods returning ivssasync synchronous , returns void. asynchronous versions of these methods have been added standard apm naming scheme of beginxxx, endxxx begin method returns ivssasyncresult instance implements standard iasyncresult interface. "replacing "vsswmfiledescription" "vsswmfiledescriptor" half way there.
to code compile , function, alter messages in next pattern of:
using (ivssasync async = _backup.gatherwritermetadata()) { // because allowing writers prepare metadata can take // while, given vssasync object gives // status on background operation. in case, // wait finish. async.wait(); }
to
_backup.gatherwritermetadata();
in short, methods synchronous, calling them differently trick.
i hope helps. have vsssample code working these changes.
c# volume-shadow-service
No comments:
Post a Comment