Esempio n. 1
0
        public int Restore()
        {
            VdiEngine BackupDevice = new VdiEngine();

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

            using (var RestoreStream = UriStreamUtil.GetUriStream(Options))
            {
                using (DeflateStream CompressedRestoreStream = new DeflateStream(RestoreStream, CompressionMode.Decompress))
                {
                    DateTime Start = DateTime.Now;

                    BackupDevice.ExecuteCommand(string.Join(Environment.NewLine,
                                                            "ALTER DATABASE [" + Options.Database + "] SET SINGLE_USER WITH ROLLBACK IMMEDIATE",
                                                            "RESTORE DATABASE [" + Options.Database + "] FROM VIRTUAL_DEVICE = '{0}' WITH REPLACE, STATS = 1",
                                                            "ALTER DATABASE[" + Options.Database + "] SET MULTI_USER"
                                                            ), CompressedRestoreStream);

                    Console.WriteLine(DateTime.Now.Subtract(Start));
                }
            }

            return(0);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public int Verify()
        {
            VdiEngine BackupDevice = new VdiEngine();

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

            using (var VerifyStream = UriStreamUtil.GetUriStream(Options))
            {
                using (DeflateStream CompressedRestoreStream = new DeflateStream(VerifyStream, CompressionMode.Decompress))
                {
                    DateTime Start = DateTime.Now;
                    BackupDevice.ExecuteCommand("RESTORE VERIFYONLY FROM VIRTUAL_DEVICE = '{0}' WITH STATS = 1", CompressedRestoreStream);
                    Console.WriteLine(DateTime.Now.Subtract(Start));
                }
            }

            return(0);
        }