Esempio n. 1
0
        public void PerformBackup()
        {
            if (Program.YamlData.Deploy.Type == "zip")
            {
            }
            else if (Program.YamlData.Deploy.Type == "folder")
            {
            }
            else
            {
                throw new Error($"Invalid deploy type {Program.YamlData.Deploy.Type} - only zip or folder are supported");
            }

            BackupSiteLocation = Path.Combine(Program.YamlData.Deploy.BaseFolder, "Website");
            if (!Directory.Exists(BackupSiteLocation))
            {
                throw new Error($"Website folder {BackupSiteLocation} not found");
            }

            Console.WriteLine(".NET Site");

            // clean temp folder
            string folder = Path.Combine(Program.YamlData.Deploy.BaseFolder, TEMPFOLDER);

            IOHelper.DeleteFolder(folder);

            BackupTempFolder = folder;

            if (Program.YamlData.Deploy.Type == "zip")
            {
                string to   = Path.Combine(Program.YamlData.Deploy.BaseFolder, Program.YamlData.Deploy.To);
                string path = Path.GetDirectoryName(to);
                Directory.CreateDirectory(path);
                File.Delete(to);

                BackupTargetZip = new BackupZipFile(to);
            }
            else
            {
                // clean target folder
                BackupTargetFolder = Path.Combine(Program.YamlData.Deploy.BaseFolder, Program.YamlData.Deploy.To);

                IOHelper.DeleteFolder(BackupTargetFolder);
                Directory.CreateDirectory(BackupTargetFolder);
            }

            // backup all dbs
            BackupDBs();

            // Add all files to zip file
            CopyAllFilesToTarget();

            // Upload everything
            UploadAll();

            // Local copies
            LocalCopy();

            IOHelper.DeleteFolder(BackupTempFolder);
        }
Esempio n. 2
0
        private void AddFilesToTargetAndRecurse(string absPath, string relPath, List <string> ExcludeFiles = null, List <string> ExcludeFolders = null, bool Optional = false)
        {
            if (ExcludeFiles == null)
            {
                ExcludeFiles = new List <string>();
            }
            ExcludeFiles.Add(@".*\.lastcodeanalysissucceeded");
            if (!Program.YamlData.Deploy.Debug)
            {
                ExcludeFiles.Add(@".*\.pdb");
            }
            ExcludeFiles.Add(@".*\.d\.ts");
            if (ExcludeFolders == null)
            {
                ExcludeFolders = new List <string>();
            }
            ExcludeFolders.Add(@"\.git");

            if (File.Exists(Path.Combine(absPath, DONTDEPLOY)))
            {
                return;
            }

            if (!Directory.Exists(absPath))
            {
                if (Optional)
                {
                    return;
                }
                throw new Error($"Folder {absPath} does not exist");
            }

            string[] files = Directory.GetFiles(absPath);
            foreach (string file in files)
            {
                bool   exclude  = false;
                string filename = Path.GetFileName(file);
                foreach (string excludeFile in ExcludeFiles)
                {
                    if (LikeString(filename, excludeFile))
                    {
                        exclude = true;
                        break;
                    }
                }
                if (!exclude)
                {
                    Console.WriteLine("Copying {0}", file);

                    // Check for minimal length (most files should be > 0 (or > 3 Unicode)
                    long length = new System.IO.FileInfo(file).Length;
                    if (length <= 3 && !file.Contains("node_modules\\") && !file.Contains("node_modules/"))
                    {
                        if ((file.EndsWith(".ts") && !file.EndsWith(".d.ts")) || file.EndsWith(".css") || file.EndsWith(".js"))
                        {
                            throw new Error($"File {file} is empty");
                        }
                    }
                    // Check for stray .js and .css files without filelistJS/CSS.txt in Addons folder
                    if (file.EndsWith(".css") && ((!file.Contains(@"/node_modules/") && file.Contains(@"/Addons/")) || (!file.Contains(@"\\node_modules\\") && file.Contains(@"\\Addons\\"))))
                    {
                        string dir       = file;
                        int    maxLevels = 3;
                        for (; ;)
                        {
                            dir = Path.GetDirectoryName(dir);
                            if (File.Exists(Path.Combine(dir, "filelistCSS.txt")))
                            {
                                break;
                            }
                            --maxLevels;
                            if (maxLevels == 0)
                            {
                                throw new Error($"File {file} found without filelistCSS.txt");
                            }
                        }
                    }
                    if (file.EndsWith(".js") && ((!file.Contains(@"/node_modules/") && file.Contains(@"/Addons/")) || (!file.Contains(@"\node_modules\") && file.Contains(@"\Addons\"))))
                    {
                        string dir       = file;
                        int    maxLevels = 3;
                        for (; ;)
                        {
                            dir = Path.GetDirectoryName(dir);
                            if (File.Exists(Path.Combine(dir, "filelistJS.txt")))
                            {
                                break;
                            }
                            --maxLevels;
                            if (maxLevels == 0)
                            {
                                throw new Error($"File {file} found without FilelistJS.txt");
                            }
                        }
                    }

                    string relFile    = Path.Combine(relPath, filename);
                    string searchFile = BackupZipFile.CleanFileName(relFile);//$$$$verify
                    if (BackupTargetZip != null)
                    {
                        bool found = (from e in BackupTargetZip.Entries where e.RelativeName == searchFile select e).Any();
                        if (!found)
                        {
                            BackupTargetZip.AddFile(file, relFile);
                        }
                    }
                    if (BackupTargetFolder != null)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(BackupTargetFolder, relFile)));
                        File.Copy(file, Path.Combine(BackupTargetFolder, relFile));
                    }
                }
            }
            string[] dirs = Directory.GetDirectories(absPath);
            foreach (string dir in dirs)
            {
                bool   exclude = false;
                string folder  = Path.GetFileName(dir);
                if (ExcludeFolders != null)
                {
                    foreach (string excludeFolder in ExcludeFolders)
                    {
                        if (LikeString(folder, excludeFolder))
                        {
                            exclude = true;
                            break;
                        }
                    }
                }
                if (!exclude)
                {
                    Console.WriteLine("Copying folder {0}", folder);
                    AddFilesToTargetAndRecurse(dir, Path.Combine(relPath, folder), ExcludeFiles, ExcludeFolders);
                }
            }
            if (files.Length == 0 && dirs.Length == 0)
            {
                // no files or folders, just add the folder in the ZIP file
                // some modules/data providers check folder existence to determine whether the module is installed
                if (BackupTargetZip != null)
                {
                    //$$$$BackupTargetZip.AddDirectoryByName(relPath);
                }
                if (BackupTargetFolder != null)
                {
                    string absFolder = Path.Combine(BackupTargetFolder, relPath);
                    Directory.CreateDirectory(absFolder);
                }
            }
        }