예제 #1
0
        static Backup()
        {
            FBDC.FbConnectionStringBuilder connectionInfo =
                new FBDC.FbConnectionStringBuilder();

            SCLP.LogProxy.Log(SCLP.LogLevel.Info,
                              "Backup Manager is now initializing...");

            SCLP.LogProxy.Log(SCLP.LogLevel.Info,
                              "Creating cache directories if necessary...");

            cacheDirectory = new DirectoryInfo(
                SC.Configuration.SafemateRootPath +
                @"\Cache");
            creationCacheDirectory = new DirectoryInfo(
                cacheDirectory.FullName + @"\Build");

            backupOperations =
                new List <QueuedBackupOperation>();

            backupService = new FBDS.FbBackup();

            restorationService = new FBDS.FbRestore();
            restorationPath    = String.Format(
                "{0}\\{1}", creationCacheDirectory.FullName,
                "RestorationTesting.fdb");
            restorationService.Options =
                FBDS.FbRestoreFlags.Replace;

            connectionInfo.Charset    = "NONE";
            connectionInfo.Database   = restorationPath;
            connectionInfo.DataSource = "localhost";
            connectionInfo.Password   = "******";
            connectionInfo.UserID     = "sysdba";

            restorationService.ConnectionString =
                connectionInfo.ToString();

            backupService.Verbose = restorationService.Verbose = true;

            backupService.ServiceOutput      += ServiceOutputHandler;
            restorationService.ServiceOutput += ServiceOutputHandler;

#if __Safemate_Core_Backup_Debug
            fragmentThreshold = 1 << 30;
#endif
            CreateCreationCache();
        }
		public void RestoreTest()
		{
			FbRestore restoreSvc = new FbRestore();

			restoreSvc.ConnectionString = this.BuildServicesConnectionString();
			restoreSvc.BackupFiles.Add(new FbBackupFile(ConfigurationManager.AppSettings["BackupRestoreFile"], 2048));
			restoreSvc.Verbose = true;
			restoreSvc.PageSize = 4096;
			restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace;

			restoreSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);

			restoreSvc.Execute();

            if (File.Exists(ConfigurationManager.AppSettings["BackupRestoreFile"]))
            {
                File.Delete(ConfigurationManager.AppSettings["BackupRestoreFile"]);
            }
		}
		public void BackupRestore_B_Restore01Test()
		{
			FbRestore restoreSvc = new FbRestore();

			restoreSvc.ConnectionString = BuildServicesConnectionString();
			restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace;
			restoreSvc.PageSize = 4096;
			restoreSvc.Verbose = true;
			restoreSvc.BackupFiles.Add(new FbBackupFile(ConfigurationManager.AppSettings["BackupRestoreFile"], 2048));

			restoreSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);

			restoreSvc.Execute();

			// some validation
		}
		void BackupRestoreTest_RestorePart()
		{
			FbRestore restoreSvc = new FbRestore();

			restoreSvc.ConnectionString = BuildServicesConnectionString(FbServerType);
			restoreSvc.Options = FbRestoreFlags.Create | FbRestoreFlags.Replace;
			restoreSvc.PageSize = 4096;
			restoreSvc.Verbose = true;
			restoreSvc.BackupFiles.Add(new FbBackupFile(TestsSetup.BackupRestoreFile, 2048));

			restoreSvc.ServiceOutput += new EventHandler<ServiceOutputEventArgs>(ServiceOutput);

			restoreSvc.Execute();
		}
예제 #5
0
        public void Copy(string source, string dest)
        {
            if (!File.Exists(source))
                throw new FileNotFoundException("Source file not found", source);

            if (File.Exists(dest))
                throw new IOException("Destination file already exists");

            Debug.WriteLine("Copying database");
            Debug.WriteLine("Source: {0} ({1})", source, GetFileSize(source));
            Debug.WriteLine("Destination: {0}", dest, null);

            string backupTemp = GetTempName(source);

            Debug.WriteLine("Backing up to temp file - {0}", backupTemp, null);

            FbBackup backup = new FbBackup
            {
                ConnectionString = CreateConnectionString(source),
                Verbose = true,
                Options = FbBackupFlags.NoGarbageCollect,
            };

            backup.BackupFiles.Add(new FbBackupFile(backupTemp, null));

            backup.ServiceOutput += ServiceOutput;

            backup.Execute();

            Debug.WriteLine("Backup complete - {0} ({1})", backupTemp, GetFileSize(backupTemp));

            string restoreTemp = GetTempName(source);

            Debug.WriteLine("Restoring to temp file - {0}", restoreTemp, null);

            FbRestore restore = new FbRestore()
            {
                ConnectionString = CreateConnectionString(restoreTemp),
                Verbose = true,
                Options = FbRestoreFlags.Create,
            };

            restore.BackupFiles.Add(new FbBackupFile(backupTemp, null));

            restore.ServiceOutput += ServiceOutput;

            restore.Execute();

            Debug.WriteLine("Restore complete - {0} ({1})", restoreTemp, GetFileSize(restoreTemp));

            Debug.WriteLine("Renaming temp restore file to - {0}", dest, null);

            File.Move(restoreTemp, dest);

            Debug.WriteLine("Deleting temp backup file - {0}", backupTemp, null);

            File.Delete(backupTemp);

            Debug.WriteLine("Copy complete");
        }