Exemplo n.º 1
0
        /// <summary>
        /// Performs actual backup.
        /// </summary>
        public override void DoWork()
        {
            string backupFileName;
            int    storePackageId;
            string storePackageFolder;
            string storeServerFolder;
            bool   deleteTempBackup;

            try
            {
                backupFileName     = (string)TaskManager.TaskParameters["BACKUP_FILE_NAME"];
                storePackageId     = Convert.ToInt32(TaskManager.TaskParameters["STORE_PACKAGE_ID"]);
                storePackageFolder = (string)TaskManager.TaskParameters["STORE_PACKAGE_FOLDER"];
                storeServerFolder  = (string)TaskManager.TaskParameters["STORE_SERVER_FOLDER"];
                deleteTempBackup   = Convert.ToBoolean(TaskManager.TaskParameters["DELETE_TEMP_BACKUP"]);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex, "Some parameters are absent or have incorrect value.");
                return;
            }

            try
            {
                PackageInfo package = PackageController.GetPackage(TaskManager.PackageId);
                // We do not take into account service id as long as scheduled tasks run against packages.
                BackupController.Backup(false, "BackupTask", package.UserId, package.PackageId, 0, 0,
                                        backupFileName, storePackageId, storePackageFolder, storeServerFolder, deleteTempBackup);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex, "Failed to do backup.");
            }
        }
Exemplo n.º 2
0
 public int Backup(bool async, string taskId, int userId, int packageId, int serviceId, int serverId,
                   string backupFileName, int storePackageId, string storePackageFolder, string storeServerFolder,
                   bool deleteTempBackup)
 {
     return(BackupController.Backup(async, taskId, userId, packageId, serviceId, serverId,
                                    backupFileName, storePackageId, storePackageFolder, storeServerFolder, deleteTempBackup));
 }
        public int BackupItem(string tempFolder, XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group)
        {
            if (item is SqlDatabase)
            {
                // backup database
                DatabaseServer sql = GetDatabaseServer(item.ServiceId);

                string backupName       = String.Format("DatabaseBackup_{0}.zip", item.Id);
                string remoteBackupFile = sql.BackupDatabase(item.Name, backupName, true);

                // download remote backup
                string localBackupPath = Path.Combine(tempFolder, backupName);

                byte[]     buffer = null;
                FileStream stream = new FileStream(localBackupPath, FileMode.Create, FileAccess.Write);

                int  offset = 0;
                long length = 0;
                do
                {
                    // read remote content
                    buffer = sql.GetTempFileBinaryChunk(remoteBackupFile, offset, FILE_BUFFER_LENGTH);

                    // write remote content
                    stream.Write(buffer, 0, buffer.Length);

                    length += buffer.Length;
                    offset += FILE_BUFFER_LENGTH;
                }while (buffer.Length == FILE_BUFFER_LENGTH);
                stream.Close();

                // add file pointer

                BackupController.WriteFileElement(writer, "DatabaseBackup", backupName, length);

                // store meta item
                SqlDatabase   database   = sql.GetDatabase(item.Name);
                XmlSerializer serializer = new XmlSerializer(typeof(SqlDatabase));
                serializer.Serialize(writer, database);
            }
            else if (item is SqlUser)
            {
                // backup user
                DatabaseServer sql = GetDatabaseServer(item.ServiceId);

                SqlUser userItem = item as SqlUser;

                // store user info
                SqlUser user = sql.GetUser(item.Name, GetSqlDatabasesArray(item.PackageId, item.GroupName));
                user.Password = userItem.Password;

                XmlSerializer serializer = new XmlSerializer(typeof(SqlUser));
                serializer.Serialize(writer, user);
            }

            return(0);
        }
Exemplo n.º 4
0
        public void Restore()
        {
            // impersonate thread
            if (threadUserId != -1)
            {
                SecurityContext.SetThreadPrincipal(threadUserId);
            }

            // perform restore
            BackupController.RestoreInternal(taskId, userId, packageId, serviceId, serverId,
                                             storePackageId, storePackageBackupPath, storeServerBackupPath);
        }
Exemplo n.º 5
0
        public void Backup()
        {
            // impersonate thread
            if (threadUserId != -1)
            {
                SecurityContext.SetThreadPrincipal(threadUserId);
            }

            // perform backup
            BackupController.BackupInternal(taskId, userId, packageId, serviceId, serverId, backupFileName, storePackageId,
                                            storePackageFolder, storeServerFolder, deleteTempBackup);
        }
Exemplo n.º 6
0
        public int BackupItem(string tempFolder, System.Xml.XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group)
        {
            if (item is HomeFolder)
            {
                // backup home folder files
                string backupName = String.Format("SpaceFiles_{0}_{1}.zip",
                                                  item.Id, DateTime.Now.Ticks);

                // get the list of remote files
                List <SystemFile> files = FilesController.GetFiles(item.PackageId, "\\", true);

                string[] zipFiles = new string[files.Count];
                for (int i = 0; i < zipFiles.Length; i++)
                {
                    zipFiles[i] = files[i].Name;
                }

                // zip remote files
                FilesController.ZipFiles(item.PackageId, zipFiles, backupName);

                // download zipped file
                string localBackupPath = Path.Combine(tempFolder, backupName);

                byte[]     buffer = null;
                FileStream stream = new FileStream(localBackupPath, FileMode.Create, FileAccess.Write);

                int  offset = 0;
                long length = 0;
                do
                {
                    // read remote content
                    buffer = FilesController.GetFileBinaryChunk(item.PackageId, backupName, offset, FILE_BUFFER_LENGTH);

                    // write remote content
                    stream.Write(buffer, 0, buffer.Length);

                    length += buffer.Length;
                    offset += FILE_BUFFER_LENGTH;
                }while (buffer.Length == FILE_BUFFER_LENGTH);
                stream.Close();

                // delete zipped file
                if (FilesController.FileExists(item.PackageId, backupName))
                {
                    FilesController.DeleteFiles(item.PackageId, new string[] { backupName });
                }

                // add file pointer
                BackupController.WriteFileElement(writer, "SpaceFiles", backupName, length);

                // store meta item
                XmlSerializer serializer = new XmlSerializer(typeof(HomeFolder));
                serializer.Serialize(writer, item);
            }
            else if (item is SystemDSN)
            {
                // backup ODBC DSN
                OS.OperatingSystem os = GetOS(item.ServiceId);

                // read DSN info
                SystemDSN itemDsn = item as SystemDSN;
                SystemDSN dsn     = os.GetDSN(item.Name);
                dsn.DatabasePassword = itemDsn.DatabasePassword;

                XmlSerializer serializer = new XmlSerializer(typeof(SystemDSN));
                serializer.Serialize(writer, dsn);
            }

            return(0);
        }
Exemplo n.º 7
0
 public int Restore(bool async, string taskId, int userId, int packageId, int serviceId, int serverId,
                    int storePackageId, string storePackageBackupPath, string storeServerBackupPath)
 {
     return(BackupController.Restore(async, taskId, userId, packageId, serviceId, serverId,
                                     storePackageId, storePackageBackupPath, storeServerBackupPath));
 }
Exemplo n.º 8
0
 public KeyValueBunch GetBackupContentSummary(int userId, int packageId,
                                              int serviceId, int serverId)
 {
     return(BackupController.GetBackupContentSummary(userId, packageId, serviceId, serverId));
 }