Ejemplo n.º 1
0
        public static void DiffBackup(JobsClientModel job)
        {
            SnapShotModel snap = SnapShotManage.FindFull(job.Destination[0], job.Id);
            //snap.IsSec = true;
            string finaltime = DateTime.UtcNow.ToString().Replace(':', ';').Replace(' ', '_');

            for (int i = 0; i < job.Source.Count; i++)
            {
                for (int e = 0; e < job.Destination.Count; e++)
                {
                    if (job.ToZip)
                    {
                        Helper.CopyCompared(job.Source[i], Path.Combine("C:\\TEMPBACKUP", finaltime), snap);
                        ZipFile.CreateFromDirectory("C:\\TEMPBACKUP", Path.Combine(job.Destination[e], finaltime) + ".zip");
                    }
                    else
                    {
                        Helper.CopyCompared(job.Source[i], Path.Combine(job.Destination[e], finaltime), snap);
                    }
                }
            }
            foreach (var item in job.Destination)
            {
                SnapShotManage.Process(snap, Path.Combine(item, finaltime));
            }
            ReportService.RunAsync(ClientProcess.ClientIdGlobal, "diff", false, new Exception("OK")).GetAwaiter();
        }
Ejemplo n.º 2
0
        public static void CopyCompared(string source, string destination, SnapShotModel snap)
        {
            //string finaldir = Path.Combine(destination, DateTime.UtcNow.ToString().Replace(':', ';').Replace(' ', '_'));
            string temp = "";

            //destination.Replace('/',Path.DirectorySeparatorChar);
            //if (ToZip)
            //    temp = "C:\\TEMPBACKUP";
            temp = Path.Combine(destination, DateTime.UtcNow.ToString().Replace(':', ';').Replace(' ', '_'));
            Directory.CreateDirectory(destination);
            //Console.WriteLine(temp);
            foreach (string item in Directory.GetDirectories(source))
            {
                if (snap.Dirs.Contains(item) == false)
                {
                    DirectoryInfo dirinf = new DirectoryInfo(item);
                    var           temp2  = Path.Combine(destination, dirinf.Name);
                    Directory.CreateDirectory(temp2);
                    snap.Dirs.Add(item);
                    CopyCompared(item, temp2, snap);
                }
            }
            foreach (string item in Directory.GetFiles(source))
            {
                if (snap.Files.Contains(item) == false)
                {
                    File.Copy(item, Path.Combine(destination, Path.GetFileName(item)));
                    snap.Files.Add(item);
                }
            }
            //if(ToZip)
            //{
            //    ZipFile.CreateFromDirectory(temp, finaldir);
            //}
        }
Ejemplo n.º 3
0
        public static SnapShotModel FindFull(string destination, int idjob)
        {
            string nazevSlozky          = "snaps";
            List <SnapShotModel> models = new List <SnapShotModel>();

            string[] dirs      = Directory.GetDirectories(destination);
            var      filePaths = new List <string>();// Directory.GetFiles(Path.Combine(destination, nazevSlozky), "*.json");

            foreach (var item in dirs)
            {
                filePaths.Add(Path.Combine(destination, item, nazevSlozky, "SnapShotek.json"));
            }
            foreach (var item in filePaths)
            {
                using (StreamReader r = new StreamReader(item))
                {
                    string json = r.ReadToEnd();
                    models.Add(JsonConvert.DeserializeObject <SnapShotModel>(json));
                    r.Close();
                }
            }

            SnapShotModel tmp = new SnapShotModel();

            //for (int i = 0; i < models.Count; i++)
            //{
            //    for (int j = 1; j < models.Count; j++)
            //    {
            //        tmp = models[i];
            //        int compare = tmp.Time.CompareTo(models[j].Time);
            //        if (compare > 0 || compare == 0)
            //            tmp = models[j];
            //    }
            //}
            foreach (var item in models)
            {
                if (item.IsSec == false && item.JobId == idjob)
                {
                    tmp = item;
                }
            }
            //Console.WriteLine(tmp.Time);
            if (tmp.Dirs == null || models.Count == 0)
            {
                tmp = CreateSnapShot(idjob, new List <string>(), new List <string>(), 5, false);
            }

            return(tmp);
        }
Ejemplo n.º 4
0
        //private static string PathToSnap = @"C:\Users\Polo\Documents\SnapShotData.json";
        //public static List<SnapShotModel> LoadSnapShots()
        //{
        //    Exists();
        //    using (StreamReader r = new StreamReader(PathToSnap))
        //    {
        //        string json = r.ReadToEnd();
        //        List<SnapShotModel> items = JsonConvert.DeserializeObject<List<SnapShotModel>>(json);
        //        return items;
        //    }
        //}
        //public static void SaveSnapShots(SnapShotModel model)
        //{
        //    Exists();
        //    var temp = new List<SnapShotModel>(LoadSnapShots());
        //    temp.Add(model);
        //    var json = JsonConvert.SerializeObject(temp);
        //    File.WriteAllText(PathToSnap, json);
        //}

        public static SnapShotModel CreateSnapShot(int jobid, List <string> dirs, List <string> files, int tillfullbackup, bool sec)
        {
            var snap = new SnapShotModel()
            {
                JobId    = jobid,
                Dirs     = dirs,
                Files    = files,
                TillFull = tillfullbackup,
                IsSec    = sec,
                Time     = DateTime.UtcNow
            };

            //SaveSnapShots(snap);
            return(snap);
        }
Ejemplo n.º 5
0
        public static async void Process(SnapShotModel model, string destination)
        {
            string        nazevSlozky = "snaps";
            string        temp        = Path.Combine(destination, nazevSlozky);
            DirectoryInfo di          = Directory.CreateDirectory(temp);

            di.Attributes = FileAttributes.Hidden;
            temp          = Path.Combine(temp + "\\SnapShotek.json");
            //Existing(temp);
            //string strResultJson = JsonConvert.SerializeObject(model);
            using (StreamWriter file = File.CreateText(temp))
            {
                JsonSerializer serializer = new JsonSerializer();
                //serialize object directly into file stream
                serializer.Serialize(file, model);
            }
        }