protected async Task BackupDatabaseAsync(string databaseFilePath, DatabaseBackupFrequency backupFrequency = DatabaseBackupFrequency.Default) { if (File.Exists(databaseFilePath)) { string databaseDirectoryPath = Path.GetDirectoryName(databaseFilePath); string backupDirectoryPath = Path.Combine(databaseDirectoryPath, "backups"); if (!Directory.Exists(backupDirectoryPath)) { Directory.CreateDirectory(backupDirectoryPath); } bool doBackup = true; DateTimeOffset lastWriteTime = GetFileLastWriteTime(databaseFilePath); DateTimeOffset lastBackupWriteTime = GetLastDatabaseBackupTime(backupDirectoryPath); if (backupFrequency == DatabaseBackupFrequency.Daily && (DateTimeOffset.UtcNow.Date == lastBackupWriteTime.Date)) { doBackup = false; } doBackup = doBackup && lastWriteTime != lastBackupWriteTime; if (doBackup) { string backupFilename = string.Format("{0}-{1}", DateUtilities.GetCurrentTimestamp(), Path.GetFileName(databaseFilePath)); string backupFilePath = Path.Combine(backupDirectoryPath, backupFilename); await OnLogAsync(Debug.LogSeverity.Info, "Creating database backup " + backupFilePath); Directory.CreateDirectory("backups"); File.Copy(databaseFilePath, backupFilePath); } } await Task.CompletedTask; }