예제 #1
0
 //DebugBackUp Object...
 public static void DebugBackUp(Backup bck)
 {
     Console.WriteLine(" ");
         Console.WriteLine("Backup ID :" + bck.iD);
         Console.WriteLine("Backup Name :"+ bck.Name);
         Console.WriteLine("Backup Password :"******"Backup Status :"+ bck.status);
         Console.WriteLine("Backup Vss :"+bck.isVss);
         Console.WriteLine("Backup Sub Folder :"+bck.isSubDir);
         Console.WriteLine("Backup Report :" +bck.isReport);
         Console.WriteLine("Backup Type :"+bck.backupLevel);
         Console.WriteLine("Sets to Keep :"+bck.setsToKeep);
         Console.WriteLine("Sources :");
         String[] values = bck.Sources;
         if (values != null)
         {
             foreach (String val in values)
             {
                 if(val!=String.Empty)
                     Console.WriteLine(val);
             }
         }
         Console.WriteLine("Destination :" + bck.dest);
         Console.WriteLine("Compression Level :" + bck.compressLevel);
         Console.WriteLine("Monitor Free Space :"+bck.spaceFree);
         Console.WriteLine("Backup Type :" + bck.backupType);
 }
예제 #2
0
 public DriveImageXML(Backup bck)
 {
     this.proc.StartInfo.FileName = "dixml.exe";
     //this.proc.StartInfo.Arguments=;
     this.proc.Start();
     Thread.Sleep(1000);
     this.proc.Kill();
 }
예제 #3
0
 public Report(Backup bck)
 {
     ownerName =  ConfigTextManager.Owner;
     companyName = ConfigTextManager.Company;
     backupSources = bck.Sources;
     backupDestination = bck.dest;
     numOfFileAlready = bck.numOfFileAlready;
     numOfFileBackedup = bck.numOfFileBackedup;
     numOfFileBackup = bck.numOfFileBackup;
     backupTime = bck.backupTime;
     backupStartTime = bck.backupStartTime;
     backupEndTime = bck.backupEndTime;
     isSuccess = bck.isSuccess;
 }
예제 #4
0
        //Gets THe BackUpList()
        public static List<Backup> GetBackUpList()
        {
            List<Backup> backuplist = new List<Backup>();

            for (int x = 0; x < ExtractTagCount(backupTag); x++)
            {
                Backup backup = new Backup();
                backup.Name = ExtractTagData(backupNameTag)[x];
                backup.isVss = ExtractTagBool(useVssTag)[x];
                backup.status = ExtractTagBool(backupStatusTag)[x];
                backup.isReport = ExtractTagBool(reportTag)[x];
                backup.isSubDir = ExtractTagBool(subFolderTag)[x];
                try
                {
                    backup.iD = Convert.ToInt32(ExtractTagData(backupTag)[x]);
                }
                catch (Exception e)
                {
                    backup.iD = 0;
                }
                String backupLvl = ExtractTagData(backupTypeTag)[x];
                backup.backupLevel = GetBackupLevel(backupLvl);
                backup.setsToKeep = Convert.ToInt32(ExtractTagData(setsToKeepTag)[x]);
                backup.dest =  ExtractTagData(destinationTag)[x].Replace("\\","\\\\");
                String Comp = ExtractTagData(compressionTag)[x];
                switch (Comp)
                {
                    case "High": backup.compressLevel = Compression.High; break;
                    case "Fast": backup.compressLevel = Compression.Fast; break;
                    case "Normal": backup.compressLevel = Compression.Normal; break;
                    default: backup.compressLevel = Compression.Normal; break;
                }
                String space = ExtractTagData(freeSpaceTag)[x];
                backup.spaceFree = Convert.ToInt32(space.Substring(0,space.Length-1));
                backup.Sources = ExtractSources(x);
                backup.password = ExtractTagData(backupPassTag)[x];
                backup.backupType = GetBackupType(x);

                backuplist.Add(backup);
            }

                return backuplist;
        }
예제 #5
0
        private static void CreateBackUpFile(Backup backup)
        {
            switch(backup.backupLevel)
            {
                case BackupLevel.Zip:

                         ZipManager zM = new ZipManager();

                         zM.ZipFiles(backup);

                         break;
                case BackupLevel.DriverXml:break;
                case BackupLevel.Reflect:break;
                case BackupLevel.NtBackup: break;
                case BackupLevel.Wbadmin: break;
                default: break;
            }
        }
예제 #6
0
        internal void ZipFiles(Backup bck)
        {
            string strzipdir = bck.dest;  // where the zip file is to be created
            string strfilename = "";     // the final filename we want to create

            strfilename = string.Format("{0}-{1}-{2}-Backup-{3}-{4}.zip", DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,bck.backupType, bck.iD);
            SearchOption srchOption = SearchOption.TopDirectoryOnly;

            if(bck.isSubDir)
                srchOption = SearchOption.AllDirectories;

            strfilename = strzipdir + "\\" + strfilename;
            List<FileInfo> filess = new List<FileInfo>();
            if(bck.Sources.Length>0)
            {
                foreach(String srce in bck.Sources)
                 {
                     if (srce != String.Empty)
                     {
                         DirectoryInfo di = new DirectoryInfo(srce);
                         filess.AddRange(di.GetFiles("*.*",srchOption));

                     }
                 }
            }
            bck.numOfFileBackup = filess.Count;
            bck.numOfFileAlready = 0;
            bck.numOfFileBackedup = 0;
            FileAttributes fileAttributes;

            // Open the zip file if it exists, else create a new one
            Package zip = ZipPackage.Open(strfilename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            Package oldZip;
            DateTime date = DateTime.Today;
            date = date.AddDays(-1);
            String oldZipFile = strzipdir + "\\" + string.Format("{0}-{1}-{2}-Backup-{3}-{4}.zip", date.Year, date.Month, date.Day, BackupType.Differential, bck.iD);

            if (File.Exists(oldZipFile)&&bck.backupType==BackupType.Differential)
            {
                oldZip = ZipPackage.Open(oldZipFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                PackagePartCollection ppc = oldZip.GetParts();
                foreach (PackagePart pp in ppc)
                {
                    PackagePart zipP =  zip.CreatePart(pp.Uri,MediaTypeNames.Application.Zip);
                    Byte[] byt = ReadFully(pp.GetStream());
                    zipP.GetStream().Write(byt, 0, byt.Length);

                }
                oldZip.Close();
            }

            if (bck.isVss)
                InitVssShadow();

            //Add as many files as you like
            for (int ii = 0; ii < filess.Count; ii++)
            {

                if ((bck.backupType == BackupType.Incremental||bck.backupType==BackupType.Differential))
                {
                    // get the attibutes
                    fileAttributes = File.GetAttributes(filess[ii].FullName);

                    // check whether a file has archive attribute
                    bool isArchive = ((File.GetAttributes(filess[ii].FullName) &
                         FileAttributes.Archive) == FileAttributes.Archive);

                    bck.numOfFileAlready++;
                    // if the archive bit is set then clear it
                    if (isArchive)
                    {
                        // add to the archive file
                        if(AddToArchive(zip, filess[ii].FullName, bck))
                             bck.numOfFileBackedup++;

                    }
                }
                else
                {
                    // add to the archive file
                    if(AddToArchive(zip, filess[ii].FullName, bck))
                        bck.numOfFileBackedup++;

                }

                // clear the bit we archived it
                try
                {
                    File.SetAttributes(filess[ii].FullName, FileAttributes.Normal);
                }
                catch (Exception e)
                {
                    MessageBox.Show("ERROR OCCURED");
                }
            }
            wApi.Close();
            oShadow.Dispose();
               zip.Close();
        }
예제 #7
0
        private bool AddToArchive(Package zip, string fileToAdd,Backup bck)
        {
            // Replace spaces with an underscore (_)
            string uriFileName = fileToAdd.Replace(" ", "_");

            // A Uri always starts with a forward slash "/"
            string zipUri = string.Concat("/", Path.GetFileName(uriFileName));

            Uri partUri = new Uri(zipUri, UriKind.Relative);
            string contentType = MediaTypeNames.Application.Zip;

            if (!zip.PartExists(partUri))
            {
                zip.DeletePart(partUri);
            }
            if (!zip.PartExists(partUri))
            {
                PackagePart pkgPart = zip.CreatePart(partUri, contentType, ConvertCompIntoCompressOption(bck.compressLevel));

                // Read all of the bytes from the file to add to the zip file
                Byte[] bites = null;

                if (bck.isVss)
                {
                    MessageBox.Show(sShadowPath + fileToAdd);
                    //bites = wApi.GetFileData(sShadowPath + Path.GetFileName(fileToAdd));
                }
                else
                {
                    try
                    {
                        bites = File.ReadAllBytes(fileToAdd);
                    }
                    catch (Exception e)
                    {
                        bites = null;
                    }
                }

                //Compress and write the bytes to the zip file

                if (bites != null)
                {

                    pkgPart.GetStream().Write(bites, 0, bites.Length);
                    return true;
                }
                else
                    return false;

            }
            else
                return false;
        }