Ejemplo n.º 1
0
        public int Backup()
        {
            AmazonS3Client s3client = null;

            if (!string.IsNullOrEmpty(Options.AWSProfileName))
            {
                AWSConfigs.AWSProfileName = Options.AWSProfileName;
            }

            if (!string.IsNullOrEmpty(Options.Region))
            {
                AWSConfigs.AWSRegion = Options.Region;
            }

            if (Options.RegionEndpoint != null)
            {
                AWSConfigs.RegionEndpoint = Options.RegionEndpoint;
            }

            if (s3client == null)
            {
                s3client = new AmazonS3Client
                           (
                    new AmazonS3Config
                {
                    RetryMode     = RequestRetryMode.Standard,
                    MaxErrorRetry = 3,
                }
                           );
            }

            //Backup the database
            VdiEngine BackupDevice = new VdiEngine();

            BackupDevice.CommandIssued       += new EventHandler <CommandIssuedEventArgs>(BackupDevice_CommandIssued);
            BackupDevice.InfoMessageReceived += new EventHandler <InfoMessageEventArgs>(BackupDevice_InfoMessageReceived);

            int partSize = Options.PartSize * 1024 * 1024;

            using (S3StreamWriter BackupStream = new S3StreamWriter(Options.Bucket, Options.Key, s3client, partSize))
            {
                using (DeflateStream CompressedBackupStream = new DeflateStream(BackupStream, CompressionMode.Compress))
                {
                    DateTime Start = DateTime.Now;
                    BackupDevice.ExecuteCommand("BACKUP DATABASE [" + Options.Database + "] TO VIRTUAL_DEVICE='{0}' WITH STATS = 1", CompressedBackupStream);
                    Console.WriteLine(DateTime.Now.Subtract(Start));
                }

                BackupStream.Close();
            }

            s3client.Dispose();

            return(0);
        }
Ejemplo n.º 2
0
        public int Backup()
        {
            AmazonS3Client s3client = null;

            if (!string.IsNullOrEmpty(Options.AWSProfileName))
            {
                var sharedFile = new SharedCredentialsFile();
                if (sharedFile.TryGetProfile(Options.AWSProfileName, out CredentialProfile profile))
                {
                    if (AWSCredentialsFactory.TryGetAWSCredentials(profile, sharedFile, out AWSCredentials credentials))
                    {
                        s3client = new AmazonS3Client(credentials, Options.RegionEndpoint);
                    }
                }
            }

            if (s3client == null)
            {
                s3client = new AmazonS3Client(Options.RegionEndpoint);
            }

            //Backup the database
            VdiEngine BackupDevice = new VdiEngine();

            BackupDevice.CommandIssued       += new EventHandler <CommandIssuedEventArgs>(BackupDevice_CommandIssued);
            BackupDevice.InfoMessageReceived += new EventHandler <InfoMessageEventArgs>(BackupDevice_InfoMessageReceived);

            int partSize = Options.PartSize * 1024 * 1024;

            using (S3StreamWriter BackupStream = new S3StreamWriter(Options.Bucket, Options.Key, s3client, partSize))
            {
                using (DeflateStream CompressedBackupStream = new DeflateStream(BackupStream, CompressionMode.Compress))
                {
                    DateTime Start = DateTime.Now;
                    BackupDevice.ExecuteCommand("BACKUP DATABASE [" + Options.Database + "] TO VIRTUAL_DEVICE='{0}' WITH STATS = 1", CompressedBackupStream);
                    Console.WriteLine(DateTime.Now.Subtract(Start));
                }

                BackupStream.Close();
            }

            s3client.Dispose();

            return(0);
        }