示例#1
0
        public void Execute(IJobExecutionContext context)
        {
            ThreadPool.QueueUserWorkItem(callback =>
            {
                var server      = new DbServer();
                string fileName = DateTimeOffset.UtcNow.Ticks.ToString();
                var domains     = DbConvention.GetDomains();

                foreach (var domain in domains)
                {
                    string tenant    = DbConvention.GetDbNameByConvention(domain.DomainName);
                    string directory = this.GetBackupDirectory(domain, tenant);


                    var agent = this.GetAgent(server, fileName, tenant, directory);

                    try
                    {
                        agent.Backup(
                            done =>
                        {
                            var backup = new Resources(tenant, directory, fileName);

                            backup.AddTenantDataToBackup();
                            backup.Compress();
                            backup.Clean();
                        },
                            error =>
                        {
                            Log.Error($"Could not backup because and error occurred. \n\n{error}");
                        });
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Exception occurred executing the backup job. {Exception}.", ex);
                    }
                }
            });
        }