示例#1
0
        private static bool BackupByPublishmentSystemID(TaskInfo taskInfo, int publishmentSystemID, EBackupType backupType)
        {
            var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemID);

            if (publishmentSystemInfo == null)
            {
                ExecutionUtils.LogError(taskInfo, new Exception("无法找到对应站点"));
                return(false);
            }

            var filePath = PathUtility.GetBackupFilePath(publishmentSystemInfo, backupType);

            DirectoryUtils.CreateDirectoryIfNotExists(filePath);
            FileUtils.DeleteFileIfExists(filePath);

            if (backupType == EBackupType.Templates)
            {
                BackupUtility.BackupTemplates(publishmentSystemInfo.PublishmentSystemId, filePath);
            }
            else if (backupType == EBackupType.ChannelsAndContents)
            {
                BackupUtility.BackupChannelsAndContents(publishmentSystemInfo.PublishmentSystemId, filePath);
            }
            else if (backupType == EBackupType.Files)
            {
                BackupUtility.BackupFiles(publishmentSystemInfo.PublishmentSystemId, filePath);
            }
            else if (backupType == EBackupType.Site)
            {
                BackupUtility.BackupSite(publishmentSystemInfo.PublishmentSystemId, filePath);
            }

            return(true);
        }
示例#2
0
        public NameValueCollection Backup(int siteId, string backupType, string userKeyPrefix)
        {
            //返回“运行结果”和“错误信息”的字符串数组
            NameValueCollection retval;
            var request = new RequestImpl(Request);

            try
            {
                var eBackupType = EBackupTypeUtils.GetEnumType(backupType);

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                var filePath = PathUtility.GetBackupFilePath(siteInfo, eBackupType);
                DirectoryUtils.CreateDirectoryIfNotExists(filePath);
                FileUtils.DeleteFileIfExists(filePath);

                if (eBackupType == EBackupType.Templates)
                {
                    BackupUtility.BackupTemplates(siteId, filePath, request.AdminName);
                }
                else if (eBackupType == EBackupType.ChannelsAndContents)
                {
                    BackupUtility.BackupChannelsAndContents(siteId, filePath, request.AdminName);
                }
                else if (eBackupType == EBackupType.Files)
                {
                    BackupUtility.BackupFiles(siteId, filePath, request.AdminName);
                }
                else if (eBackupType == EBackupType.Site)
                {
                    BackupUtility.BackupSite(siteId, filePath, request.AdminName);
                }

                string resultString =
                    $"任务完成,备份地址:<br /><strong> {filePath} </strong>&nbsp;<a href='{ApiRouteActionsDownload.GetUrl(ApiManager.InnerApiUrl, filePath)}'><img src='{SiteServerAssets.GetIconUrl("download.gif")}' />下载</a>。";

                retval = AjaxManager.GetWaitingTaskNameValueCollection(resultString, string.Empty, string.Empty);
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty);
                LogUtils.AddErrorLog(ex);
            }

            return(retval);
        }