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);
        }
예제 #2
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);
        }