Exemplo n.º 1
0
        public void Wildcard2Filter()
        {
            FileSelectionList list = new FileSelectionList();

            list.Add(testPath);
            FileFilter filter = new FileFilter();

            filter.Add(@".*\.b");
            filter.Add(@".*\.c");
            BackupParameters param = new BackupParameters()
            {
                type = EBackupType.Full
            };

            FileList files = new Backup().GetFiles(list, filter, param);

            List <String> expected = new List <string>()
            {
                testPath + @"\file1.a",
                testPath + @"\dir1\file4.a",
                testPath + @"\dir2\file6.a",
            };

            CompareFileLists(files, expected);
        }
Exemplo n.º 2
0
        public void DuplicateFiles()
        {
            FileSelectionList list = new FileSelectionList();

            list.Add(testPath + @"\file3.c");
            list.Add(testPath + @"\file3.c");
            FileFilter       filter = new FileFilter();
            BackupParameters param  = new BackupParameters()
            {
                type = EBackupType.Full
            };

            FileList files = new Backup().GetFiles(list, filter, param);

            List <String> expected = new List <string>()
            {
                testPath + @"\file3.c",
            };

            CompareFileLists(files, expected);
        }
Exemplo n.º 3
0
        public void GetAllFilesZip()
        {
            FileSelectionList list = new FileSelectionList();

            list.Add(testPath);
            FileFilter       filter = new FileFilter();
            BackupParameters param  = new BackupParameters()
            {
                type = EBackupType.Full, outputDirectory = outputPath, backupName = "GetAllFilesZip", backupTime = new DateTime(2020, 1, 1, 13, 0, 0)
            };

            FileList files = new Backup().GetFiles(list, filter, param);

            new Backup().DoBackup(files, param);
        }
Exemplo n.º 4
0
        public void GetAllFiles2()
        {
            FileSelectionList list = new FileSelectionList();

            list.Add(testPath + @"\dir2");
            list.Add(testPath + @"\dir1\dir3");
            FileFilter       filter = new FileFilter();
            BackupParameters param  = new BackupParameters()
            {
                type = EBackupType.Full
            };

            FileList files = new Backup().GetFiles(list, filter, param);

            List <String> expected = new List <string>()
            {
                testPath + @"\dir2\file6.a",
                testPath + @"\dir2\file7.b",
                testPath + @"\dir1\dir3\dir4\file8.b",
                testPath + @"\dir1\dir3\dir4\file9.c",
            };

            CompareFileLists(files, expected);
        }
Exemplo n.º 5
0
        public void GetAllFiles()
        {
            FileSelectionList list = new FileSelectionList();

            list.Add(testPath);
            FileFilter       filter = new FileFilter();
            BackupParameters param  = new BackupParameters()
            {
                type = EBackupType.Full
            };

            FileList files = new Backup().GetFiles(list, filter, param);

            List <String> expected = new List <string>();

            foreach (var f in testFiles)
            {
                expected.Add(f.filename);
            }

            CompareFileLists(files, expected);
        }
Exemplo n.º 6
0
        public void IncrementalFilter()
        {
            FileSelectionList list = new FileSelectionList();

            list.Add(testPath);
            FileFilter filter = new FileFilter();

            filter.Add(@".*\.b");
            filter.Add(@".*\.c");
            BackupParameters param = new BackupParameters()
            {
                type = EBackupType.Incremental, lastBackup = new DateTime(2020, 1, 1, 12, 15, 0)
            };

            FileList files = new Backup().GetFiles(list, filter, param);

            List <String> expected = new List <string>()
            {
                testPath + @"\dir1\file4.a",
            };

            CompareFileLists(files, expected);
        }
Exemplo n.º 7
0
        static BackupParameters ProcessCommandLine(string[] args)
        {
            BackupParameters param = new BackupParameters();

            int index = 0;

            while (index < args.Length)
            {
                string arg     = args[index];
                string nextArg = index + 1 < args.Length ? args[index + 1] : "";
                switch (arg)
                {
                case "--type":
                    if (nextArg == "Full")
                    {
                        param.type = EBackupType.Full;
                    }
                    else if (nextArg == "Incremental")
                    {
                        param.type = EBackupType.Incremental;
                    }
                    else
                    {
                        throw new ApplicationException($"Unknown backup type '{nextArg}'");
                    }
                    index++;
                    break;

                case "--fileList":
                    if (!File.Exists(nextArg))
                    {
                        throw new ApplicationException($"Can't find include file '{nextArg}'");
                    }
                    else
                    {
                        string[] files = File.ReadAllLines(nextArg);
                        foreach (var f in files)
                        {
                            selectionList.Add(f);
                        }
                    }
                    index++;
                    break;

                case "--excludeList":
                    if (!File.Exists(nextArg))
                    {
                        throw new ApplicationException($"Can't find exclusion file '{nextArg}'");
                    }
                    else
                    {
                        string[] files = File.ReadAllLines(nextArg);
                        foreach (var f in files)
                        {
                            filter.Add(f);
                        }
                    }
                    index++;
                    break;

                case "--lastBackup":
                {
                    DateTime dt;
                    if (DateTime.TryParse(nextArg, out dt))
                    {
                        param.lastBackup = dt;
                    }
                    else
                    {
                        throw new ApplicationException($"Can't understand --lastBackup datetime '{nextArg}'");
                    }
                }
                    index++;
                    break;

                case "--outputPath":
                    param.outputDirectory = nextArg;
                    index++;
                    break;

                case "--backupName":
                    param.backupName = nextArg;
                    index++;
                    break;

                case "--help":
                    System.Console.WriteLine(helpText);
                    System.Environment.Exit(0);
                    break;
                }
                index++;
            }
            System.Console.WriteLine("Backup Starting...");
            System.Console.WriteLine($"Backup Name      {param.backupName}");
            System.Console.WriteLine($"Backup Time      {param.backupTime}");
            System.Console.WriteLine($"Last Backup Time {param.lastBackup}");
            System.Console.WriteLine($"Output Directory {param.outputDirectory}");
            System.Console.WriteLine($"Backup Type      {param.type}");

            return(param);
        }