Esempio n. 1
0
        public static int Backup(bool async, string taskId, int userId, int packageId, int serviceId, int serverId,
                                 string backupFileName, int storePackageId, string storePackageFolder, string storeServerFolder,
                                 bool deleteTempBackup)
        {
            // check demo account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check admin account
            accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin);
            if ((serviceId > 0 || serverId > 0) && accountCheck < 0)
            {
                return(accountCheck);
            }

            if (accountCheck < 0)
            {
                deleteTempBackup = true;
            }

            // check if backup temp folder is available
            string tempFolder = GetTempBackupFolder();

            if (!FolderWriteAccessible(tempFolder))
            {
                return(BusinessErrorCodes.ERROR_BACKUP_TEMP_FOLDER_UNAVAILABLE);
            }

            // check destination folder if required
            if (!String.IsNullOrEmpty(storePackageFolder) &&
                !RemoteServerFolderWriteAccessible(storePackageId, storePackageFolder))
            {
                return(BusinessErrorCodes.ERROR_BACKUP_DEST_FOLDER_UNAVAILABLE);
            }

            // check server folder if required
            if (!String.IsNullOrEmpty(storeServerFolder) &&
                !FolderWriteAccessible(storeServerFolder))
            {
                return(BusinessErrorCodes.ERROR_BACKUP_SERVER_FOLDER_UNAVAILABLE);
            }

            // check/reset delete flag
            accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin);
            if (accountCheck < 0 && !deleteTempBackup)
            {
                deleteTempBackup = true;
            }

            if (async)
            {
                BackupAsyncWorker worker = new BackupAsyncWorker();
                worker.threadUserId       = SecurityContext.User.UserId;
                worker.taskId             = taskId;
                worker.userId             = userId;
                worker.packageId          = packageId;
                worker.serviceId          = serviceId;
                worker.serverId           = serverId;
                worker.backupFileName     = backupFileName;
                worker.storePackageId     = storePackageId;
                worker.storePackageFolder = storePackageFolder;
                worker.storeServerFolder  = storeServerFolder;
                worker.deleteTempBackup   = deleteTempBackup;

                // run
                worker.BackupAsync();

                return(0);
            }
            else
            {
                return(BackupInternal(taskId, userId, packageId, serviceId, serverId,
                                      backupFileName, storePackageId, storePackageFolder, storeServerFolder,
                                      deleteTempBackup));
            }
        }
Esempio n. 2
0
        public static int Backup(bool async, string taskId, int userId, int packageId, int serviceId, int serverId,
            string backupFileName, int storePackageId, string storePackageFolder, string storeServerFolder,
            bool deleteTempBackup)
        {
            // check demo account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // check admin account
            accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin);
            if ((serviceId > 0 || serverId > 0) && accountCheck < 0) return accountCheck;

			if (accountCheck < 0)
				deleteTempBackup = true;

            // check if backup temp folder is available
			string tempFolder = GetTempBackupFolder();
			if (!FolderWriteAccessible(tempFolder))
				return BusinessErrorCodes.ERROR_BACKUP_TEMP_FOLDER_UNAVAILABLE;

            // check destination folder if required
            if (!String.IsNullOrEmpty(storePackageFolder) &&
                !RemoteServerFolderWriteAccessible(storePackageId, storePackageFolder))
                return BusinessErrorCodes.ERROR_BACKUP_DEST_FOLDER_UNAVAILABLE;

            // check server folder if required
            if (!String.IsNullOrEmpty(storeServerFolder) &&
                !FolderWriteAccessible(storeServerFolder))
                return BusinessErrorCodes.ERROR_BACKUP_SERVER_FOLDER_UNAVAILABLE;

			// check/reset delete flag
			accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin);
			if (accountCheck < 0 && !deleteTempBackup)
				deleteTempBackup = true;

			if (async)
			{
				BackupAsyncWorker worker = new BackupAsyncWorker();
				worker.threadUserId = SecurityContext.User.UserId;
				worker.taskId = taskId;
				worker.userId = userId;
				worker.packageId = packageId;
				worker.serviceId = serviceId;
				worker.serverId = serverId;
				worker.backupFileName = backupFileName;
				worker.storePackageId = storePackageId;
				worker.storePackageFolder = storePackageFolder;
				worker.storeServerFolder = storeServerFolder;
				worker.deleteTempBackup = deleteTempBackup;

				// run
				worker.BackupAsync();

				return 0;
			}
			else
			{
				return BackupInternal(taskId, userId, packageId, serviceId, serverId,
					backupFileName, storePackageId, storePackageFolder, storeServerFolder,
					deleteTempBackup);
			}
        }
Esempio n. 3
0
        public static int Restore(bool async, string taskId, int userId, int packageId, int serviceId, int serverId,
                                  int storePackageId, string storePackageBackupPath, string storeServerBackupPath)
        {
            // check demo account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check admin account
            accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin);
            if ((serviceId > 0 || serverId > 0) && accountCheck < 0)
            {
                return(accountCheck);
            }

            // check if backup temp folder is available
            string tempFolder = GetTempBackupFolder();

            if (!FolderWriteAccessible(tempFolder))
            {
                return(BusinessErrorCodes.ERROR_BACKUP_TEMP_FOLDER_UNAVAILABLE);
            }

            // check server source path if required
            if (!String.IsNullOrEmpty(storeServerBackupPath))
            {
                try
                {
                    if (!File.Exists(storeServerBackupPath))
                    {
                        return(BusinessErrorCodes.ERROR_RESTORE_BACKUP_SOURCE_NOT_FOUND);
                    }
                }
                catch
                {
                    return(BusinessErrorCodes.ERROR_RESTORE_BACKUP_SOURCE_UNAVAILABLE);
                }
            }

            if (async)
            {
                BackupAsyncWorker worker = new BackupAsyncWorker();
                worker.threadUserId           = SecurityContext.User.UserId;
                worker.taskId                 = taskId;
                worker.userId                 = userId;
                worker.packageId              = packageId;
                worker.serviceId              = serviceId;
                worker.serverId               = serverId;
                worker.storePackageId         = storePackageId;
                worker.storePackageBackupPath = storePackageBackupPath;
                worker.storeServerBackupPath  = storeServerBackupPath;

                // run
                worker.RestoreAsync();

                return(0);
            }
            else
            {
                return(RestoreInternal(taskId, userId, packageId, serviceId, serverId,
                                       storePackageId, storePackageBackupPath, storeServerBackupPath));
            }
        }
Esempio n. 4
0
        public static int Restore(bool async, string taskId, int userId, int packageId, int serviceId, int serverId,
            int storePackageId, string storePackageBackupPath, string storeServerBackupPath)
        {
            // check demo account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);
            if (accountCheck < 0) return accountCheck;

            // check admin account
            accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin);
            if ((serviceId > 0 || serverId > 0) && accountCheck < 0) return accountCheck;

            // check if backup temp folder is available
			string tempFolder = GetTempBackupFolder();
			if (!FolderWriteAccessible(tempFolder))
				return BusinessErrorCodes.ERROR_BACKUP_TEMP_FOLDER_UNAVAILABLE;

			// check server source path if required
			if (!String.IsNullOrEmpty(storeServerBackupPath))
			{
				try
				{
					if (!File.Exists(storeServerBackupPath))
						return BusinessErrorCodes.ERROR_RESTORE_BACKUP_SOURCE_NOT_FOUND;
				}
				catch
				{
					return BusinessErrorCodes.ERROR_RESTORE_BACKUP_SOURCE_UNAVAILABLE;
				}
			}

			if (async)
			{
				BackupAsyncWorker worker = new BackupAsyncWorker();
				worker.threadUserId = SecurityContext.User.UserId;
				worker.taskId = taskId;
				worker.userId = userId;
				worker.packageId = packageId;
				worker.serviceId = serviceId;
				worker.serverId = serverId;
				worker.storePackageId = storePackageId;
				worker.storePackageBackupPath = storePackageBackupPath;
				worker.storeServerBackupPath = storeServerBackupPath;

				// run
				worker.RestoreAsync();

				return 0;
			}
			else
			{
				return RestoreInternal(taskId, userId, packageId, serviceId, serverId,
					storePackageId, storePackageBackupPath, storeServerBackupPath);
			}
        }