public override bool CreateFolder() { if (string.IsNullOrEmpty(FolderKey)) { throw new ArgumentNullException("name", "Folder name can not be null."); } S3Service.AddObject(bucketName, FolderKey, 0, null, stream => { }); return(true); }
public void Save(string filename, Stream filestream, string contentType) { try { _S3Service.AddObject(filestream, _bucketName, filename, contentType, CannedAcl.PublicRead); } catch (Exception e) { System.Diagnostics.Debug.Write(e.Message); } }
public void AddObject(string bucketName, string key, long bytes, string contentType, Action <Stream> action) { client.AddObject(bucketName, key, bytes, contentType, default(CannedAcl), action); }
public void ArchiveBackup(BackupDetails details, string inputFile) { _service.AddObject(inputFile, _settings.Bucket, GenerateFileName(details)); }
public Task Upload(string bucket, string key, Stream stream, long length, IDictionary <string, string> metadata) { CheckBucket(bucket); return(Task.Factory.StartNew(() => Service.AddObject(stream, length, bucket, key))); }
public Program() { var usingTrustedConnection = string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(Password); var sourceConnection = usingTrustedConnection ? new ServerConnection(ServerName) { LoginSecure = true } : new ServerConnection(ServerName, Username, Password); var sqlServer = new Server(sourceConnection); if (sqlServer != null) { var backup = new Backup(); var dbc = sqlServer.Databases; if (dbc.Contains(DatabaseName)) { backup.Action = BackupActionType.Database; backup.Database = DatabaseName; var dateFilename = DateTime.UtcNow.ToString("dd-MMM-yyyy"); var tempFilename = String.Format("{0}-{1}.bak", DatabaseName, dateFilename); var tempBackupPath = String.Format("{0}{1}", TempFilePath, tempFilename); //remove old backups from this local temp location foreach (var file in Directory.GetFiles(TempFilePath)) { if (file != tempBackupPath) { Console.WriteLine("Removing previous temp backup " + file); File.Delete(file); } } try { var backupDevice = new BackupDeviceItem(tempBackupPath, DeviceType.File); backup.Devices.Add(backupDevice); backup.Checksum = true; backup.ContinueAfterError = false; backup.LogTruncation = BackupTruncateLogType.Truncate; //if file exists then do an incremental, otherwise do a full if (File.Exists(tempBackupPath)) { backup.Incremental = true; } else { backup.Incremental = false; } // Perform backup. backup.SqlBackup(sqlServer); //now move the backup to S3 - overwriting anything that is there with the same name var s3 = new S3Service { AccessKeyID = AccessKeyID, SecretAccessKey = SecretAccessKey }; var bucket = Bucket; s3.AddObject(tempBackupPath, bucket, tempFilename); var metadataOnly = true; foreach (var listEntry in s3.ListObjects(Bucket, "")) { var request = new GetObjectRequest(s3, Bucket, listEntry.Name, metadataOnly); using (var response = request.GetResponse()) { if (response.LastModified < DateTime.UtcNow.AddDays(DaysToKeepS3BackupFor * -1)) { Console.WriteLine("Going to delete old archive " + listEntry.Name); s3.DeleteObject(Bucket, listEntry.Name); } } } Console.Out.WriteLine("Backup to S3 is complete"); System.Threading.Thread.Sleep(10000); } catch (Exception ee) { Console.Out.WriteLine("Exception occurred - do not continue. Wait until next run to try again " + ee.ToString()); System.Threading.Thread.Sleep(10000); } } } }