示例#1
0
        public void Execute(IJobExecutionContext context)
        {
            string fileName = DateTimeOffset.UtcNow.Ticks.ToString();
            var domains = TenantConvention.GetDomains();

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


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

                try
                {
                    agent.BackupAsync
                        (
                            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}"); })
                        .Wait();
                }
                catch (Exception ex)
                {
                    Log.Error("Exception occurred executing the backup job. {Exception}.", ex);
                }
            }
        }
示例#2
0
        public void Execute(IJobExecutionContext context)
        {
            string fileName = DateTimeOffset.UtcNow.Ticks.ToString();
            var    domains  = TenantConvention.GetDomains();

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


                var server = new DbServer(tenant);

                foreach (string directory in directories)
                {
                    var agent = this.GetAgent(server, fileName, tenant, directory);

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

                            backup.AddTenantDataToBackup();
                            backup.Compress();
                            backup.Clean();
                        },
                            error => { Log.Error($"Could not backup because an error occurred. \n\n{error}"); })
                        .GetAwaiter()
                        .GetResult();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Exception occurred executing the backup job. {Exception}.", ex);
                    }
                }
            }
        }
示例#3
0
        public IDbAgent GetAgent(DbServer server, string backupFileName, string tenant, string backupPath)
        {
            if (server.ProviderName.ToUpperInvariant().Equals("SQL SERVER"))
            {
                return new Agent
                {
                    Server = server,
                    FileName = backupFileName,
                    Tenant = tenant,
                    BackupFileLocation = backupPath
                };
            }


            return new Postgres.Agent
            {
                Server = server,
                FileName = backupFileName,
                Tenant = tenant,
                BackupFileLocation = backupPath
            };
        }
示例#4
0
        public IDbAgent GetAgent(DbServer server, string backupFileName, string tenant, string backupPath)
        {
            if (server.ProviderName.ToUpperInvariant().Equals("SQL SERVER"))
            {
                return(new Agent
                {
                    Server = server,
                    FileName = backupFileName,
                    Tenant = tenant,
                    BackupFileLocation = backupPath
                });
            }


            return(new Postgres.Agent
            {
                Server = server,
                FileName = backupFileName,
                Tenant = tenant,
                BackupFileLocation = backupPath
            });
        }