This commit is contained in:
16
Startup.cs
16
Startup.cs
@@ -108,14 +108,14 @@ namespace rockfishCore
|
|||||||
RfSchema.CheckAndUpdate(dbContext);
|
RfSchema.CheckAndUpdate(dbContext);
|
||||||
|
|
||||||
//bool bMM=RfMail.MailIsMirroringProperly();
|
//bool bMM=RfMail.MailIsMirroringProperly();
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
var test = OpsDiagnostics.CheckSpacesBackupStorage();
|
// var test = OpsDiagnostics.VerifyBackups();
|
||||||
}
|
// }
|
||||||
catch (Exception ex)
|
// catch (Exception ex)
|
||||||
{
|
// {
|
||||||
string res = ex.Message;
|
// string res = ex.Message;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}//eof
|
}//eof
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,14 @@ namespace rockfishCore.Util
|
|||||||
{
|
{
|
||||||
public static class OpsDiagnostics
|
public static class OpsDiagnostics
|
||||||
{
|
{
|
||||||
|
private const int S3_EXPECTED_FILE_COUNT=24;
|
||||||
|
public static readonly string[] S3_EXPECTED_BACKUP_FILE_PREFIXES =
|
||||||
|
{ "biz-docker-website-backup-", "biz-letsencryptbackup-", "biz-pecklist-db-backup-", "biz-rockfish-db-backup-",
|
||||||
|
"devops-docker-le-config-backup-","forum-backup-", "mail-svn-repo-backup-" };
|
||||||
|
private const string S3_SECRET_KEY = "iNwbHr+sK+9is2wmRjIax+rdyEjLNvWKJBYr7w4txkY";
|
||||||
|
private const string S3_ACCESS_KEY = "CMPAFDNX53OWPC55HBJ4";
|
||||||
|
private const string S3_HOST_ENDPOINT = "https://nyc3.digitaloceanspaces.com";
|
||||||
|
|
||||||
private static HttpClient Client = new HttpClient();
|
private static HttpClient Client = new HttpClient();
|
||||||
|
|
||||||
|
|
||||||
@@ -31,31 +39,41 @@ namespace rockfishCore.Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static bool CheckSpacesBackupStorage()
|
public static List<string> GetFileListFromSpacesBackupStorage()
|
||||||
{
|
{
|
||||||
|
|
||||||
var SECRET_KEY = "iNwbHr+sK+9is2wmRjIax+rdyEjLNvWKJBYr7w4txkY";
|
AmazonS3Config clientConfig = new AmazonS3Config();
|
||||||
var ACCESS_KEY = "CMPAFDNX53OWPC55HBJ4";
|
clientConfig.ServiceURL = S3_HOST_ENDPOINT;
|
||||||
var HOST_ENDPOINT = "https://nyc3.digitaloceanspaces.com";
|
IAmazonS3 s3Client = new AmazonS3Client(S3_ACCESS_KEY, S3_SECRET_KEY, clientConfig);
|
||||||
var BUCKET = "%(bucket)s.nyc3.digitaloceanspaces.com";
|
var objectList = s3Client.ListObjectsAsync("gztw1").Result;
|
||||||
AmazonS3Config clientConfig=new AmazonS3Config();
|
var fileList = objectList.S3Objects.Select(c => c.Key).ToList();
|
||||||
clientConfig.ServiceURL=HOST_ENDPOINT;
|
return fileList;
|
||||||
IAmazonS3 s3Client = new AmazonS3Client(ACCESS_KEY, SECRET_KEY, clientConfig);
|
|
||||||
var bucketlist=s3Client.ListBucketsAsync().Result;
|
|
||||||
|
|
||||||
// IAmazonS3 amazonS3Client = new
|
|
||||||
// AWSClientFactory.CreateAmazonS3Client("your-spaces-key", "your-spaces-key-secrete",
|
|
||||||
// new AmazonS3Config
|
|
||||||
// {
|
|
||||||
// ServiceURL = "https://nyc3.digitaloceanspaces.com"
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// var myBuckets = amazonS3Client.ListBuckets();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool VerifyBackups()
|
||||||
|
{
|
||||||
|
bool ret=false;
|
||||||
|
var SpacesFileNames = GetFileListFromSpacesBackupStorage();
|
||||||
|
if (SpacesFileNames.Count != S3_EXPECTED_FILE_COUNT) return ret;
|
||||||
|
//get yesterday's date in the same format as the backup creates
|
||||||
|
var ExpectedBackupDateString=DateTime.Today.AddDays(-1).ToString("yyMMdd");
|
||||||
|
int foundMatches=0;
|
||||||
|
foreach(string ExpectedFileName in S3_EXPECTED_BACKUP_FILE_PREFIXES){
|
||||||
|
foreach(string FileName in SpacesFileNames){
|
||||||
|
if(FileName.StartsWith(ExpectedFileName+ExpectedBackupDateString)){
|
||||||
|
foundMatches++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(foundMatches==S3_EXPECTED_BACKUP_FILE_PREFIXES.Length){
|
||||||
|
ret=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user