Ejemplo n.º 1
0
        public async Task <IActionResult> BackupDatabaseAsync([FromBody] BackupDatabaseRequest request)
        {
            if (request.BackupFile == null)
            {
                throw new BadRequestException("Backup file isn't specified!");
            }
            await databaseBackupService.BackupDatabaseAsync(request.BackupFile);

            return(Ok());
        }
Ejemplo n.º 2
0
        private BackupDatabaseResponse HandleDatabaseBackupRequest(BackupDatabaseRequest request)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                Log.Info("Creating database backup");

                CreateBackup();
                stopWatch.Stop();

                Log.Info($"Succesfully created a database backup in: {stopWatch.ElapsedMilliseconds}ms.");
                return(new BackupDatabaseResponse {
                    Success = true, DatabaseBackupTime = stopWatch.Elapsed
                });
            }
            catch (Exception e)
            {
                Log.Error("Creating database backup failed.", e);
                return(new BackupDatabaseResponse {
                    DatabaseBackupTime = stopWatch.Elapsed
                });
            }
        }
Ejemplo n.º 3
0
        public async Task <StorageResponse <BackupDatabaseResponse> > BackupDatabaseAsync(BackupDatabaseRequest request, string fileNameWithoutExtension)
        {
            var filePath = request.BackupPath.SetValidDirectoryPathEnd();

            try
            {
                fileNameWithoutExtension += ConstantsMsSql.FILE_EXTENSION_BAK;

                var sqlCommand = new StringBuilder();
                sqlCommand.AppendLine($"{ConstantsMsSql.BACKUP} {ConstantsMsSql.DATABASE} [{ request.Server.DatabaseName}]");
                sqlCommand.AppendLine(JoinStatement(ConstantsMsSql.TODISK, filePath + fileNameWithoutExtension));
                sqlCommand.AppendLine($"{ConstantsMsSql.WITHFORMAT},");
                sqlCommand.Append(JoinStatement(ConstantsMsSql.MEDIANAME, request.Server.DatabaseName));
                sqlCommand.AppendLine(",");
                sqlCommand.AppendLine(JoinStatement(ConstantsMsSql.NAME, request.Server.DatabaseName));

                await ExecuteNonQueryAsync(request.Server, sqlCommand.ToString(), ConstantsMsSql.MASTER);

                return(new StorageResponse <BackupDatabaseResponse>
                {
                    Data = new BackupDatabaseResponse
                    {
                        IsSuccessful = true,
                        BackupFullFileName = filePath + fileNameWithoutExtension
                    }
                });
            }
            catch (Exception ex)
            {
                return(new StorageResponse <BackupDatabaseResponse>
                {
                    IsFaulty = true,
                    Exception = ex
                });
            }
        }