public ArchiveWriteRequestExecution(
     List<ISceneEntity> sceneObjects,
     ITerrainModule terrainModule,
     IRegionSerialiserModule serialiser,
     IScene scene,
     TarArchiveWriter archiveWriter,
     Guid requestId)
 {
     m_sceneObjects = sceneObjects;
     m_terrainModule = terrainModule;
     m_serialiser = serialiser;
     m_scene = scene;
     m_archiveWriter = archiveWriter;
     m_requestId = requestId;
 }
        public void SaveRegionBackup (TarArchiveWriter writer, IScene scene)
        {
            writer.WriteDir ("assets"); //Used by many, create it by default

            IWhiteCoreBackupModule[] modules = scene.RequestModuleInterfaces<IWhiteCoreBackupModule> ();
            foreach (IWhiteCoreBackupModule module in modules)
                module.SaveModuleToArchive (writer, scene);

            foreach (IWhiteCoreBackupModule module in modules)
            {
                while (module.IsArchiving) //Wait until all are done
                    Thread.Sleep (100);
            }

            writer.Close ();
            GC.Collect ();
            MainConsole.Instance.Info ("[Archive]: Finished saving of archive.");
        }
Esempio n. 3
0
 private void WriteAsset(string id, AssetBase asset, TarArchiveWriter writer)
 {
     if (asset != null)
         writer.WriteFile("assets/" + asset.ID, OSDParser.SerializeJsonString(asset.ToOSD()));
     else
         MainConsole.Instance.WarnFormat("Could not find asset {0}", id);
 }
Esempio n. 4
0
            public void SaveModuleToArchive(TarArchiveWriter writer, IScene scene)
            {
                m_isArchiving = true;

                MainConsole.Instance.Info("[Archive]: Writing parcels to archive");

                writer.WriteDir("parcels");

                IParcelManagementModule module = scene.RequestModuleInterface<IParcelManagementModule>();
                if (module != null)
                {
                    List<ILandObject> landObject = module.AllParcels();
                    foreach (ILandObject parcel in landObject)
                    {
                        OSDMap parcelMap = parcel.LandData.ToOSD();
                        writer.WriteFile("parcels/" + parcel.LandData.GlobalID.ToString(),
                                         OSDParser.SerializeLLSDBinary(parcelMap));
                        parcelMap = null;
                    }
                }

                MainConsole.Instance.Info("[Archive]: Finished writing parcels to archive");
                MainConsole.Instance.Info("[Archive]: Writing terrain to archive");

                writer.WriteDir("newstyleterrain");
                writer.WriteDir("newstylerevertterrain");

                writer.WriteDir("newstylewater");
                writer.WriteDir("newstylerevertwater");

                ITerrainModule tModule = scene.RequestModuleInterface<ITerrainModule>();
                if (tModule != null)
                {
                    try
                    {
                        byte[] sdata = WriteTerrainToStream(tModule.TerrainMap);
                        writer.WriteFile("newstyleterrain/" + scene.RegionInfo.RegionID.ToString() + ".terrain", sdata);
                        sdata = null;

                        sdata = WriteTerrainToStream(tModule.TerrainRevertMap);
                        writer.WriteFile("newstylerevertterrain/" + scene.RegionInfo.RegionID.ToString() + ".terrain",
                                         sdata);
                        sdata = null;

                        if (tModule.TerrainWaterMap != null)
                        {
                            sdata = WriteTerrainToStream(tModule.TerrainWaterMap);
                            writer.WriteFile("newstylewater/" + scene.RegionInfo.RegionID.ToString() + ".terrain", sdata);
                            sdata = null;

                            sdata = WriteTerrainToStream(tModule.TerrainWaterRevertMap);
                            writer.WriteFile(
                                "newstylerevertwater/" + scene.RegionInfo.RegionID.ToString() + ".terrain", sdata);
                            sdata = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        MainConsole.Instance.WarnFormat("[Backup]: Exception caught: {0}", ex.ToString());
                    }
                }

                MainConsole.Instance.Info("[Archive]: Finished writing terrain to archive");
                MainConsole.Instance.Info("[Archive]: Writing entities to archive");
                ISceneEntity[] entities = scene.Entities.GetEntities();
                //Get all entities, then start writing them to the database
                writer.WriteDir("entities");

                IDictionary<UUID, AssetType> assets = new Dictionary<UUID, AssetType>();
                UuidGatherer assetGatherer = new UuidGatherer(m_scene.AssetService);
                IWhiteCoreBackupArchiver archiver = m_scene.RequestModuleInterface<IWhiteCoreBackupArchiver>();
                bool saveAssets = false;
                if (archiver.AllowPrompting)
                    saveAssets =
                        MainConsole.Instance.Prompt("Save assets? (Will not be able to load on other grids)", "false")
                                   .Equals("true", StringComparison.CurrentCultureIgnoreCase);

                int count = 0;
                foreach (ISceneEntity entity in entities)
                {
                    try
                    {
                        if (entity.IsAttachment ||
                            ((entity.RootChild.Flags & PrimFlags.Temporary) == PrimFlags.Temporary)
                            || ((entity.RootChild.Flags & PrimFlags.TemporaryOnRez) == PrimFlags.TemporaryOnRez))
                            continue;
                        //Write all entities
                        byte[] xml = entity.ToBinaryXml2();
                        writer.WriteFile("entities/" + entity.UUID.ToString(), xml);
                        xml = null;
                        count++;
                        if (count%3 == 0)
                            Thread.Sleep(5);
                        //Get all the assets too
                        if (saveAssets)
                            assetGatherer.GatherAssetUuids(entity, assets);
                    }
                    catch (Exception ex)
                    {
                        MainConsole.Instance.WarnFormat("[Backup]: Exception caught: {0}", ex);
                    }
                }
                entities = null;

                MainConsole.Instance.Info("[Archive]: Finished writing entities to archive");
                MainConsole.Instance.Info("[Archive]: Writing assets for entities to archive");

                bool foundAllAssets = true;
                foreach (UUID assetID in new List<UUID>(assets.Keys))
                {
                    try
                    {
                        foundAllAssets = false; //Not all are cached
                        m_scene.AssetService.Get(assetID.ToString(), writer, RetrievedAsset);
                        m_missingAssets.Add(assetID);
                    }
                    catch (Exception ex)
                    {
                        MainConsole.Instance.WarnFormat("[Backup]: Exception caught: {0}", ex);
                    }
                }
                if (foundAllAssets)
                    m_isArchiving = false; //We're done if all the assets were found

                MainConsole.Instance.Info("[Archive]: Finished writing assets for entities to archive");
            }
        private void SaveWhiteCoreArchive(IScene scene, string[] cmd)
        {
            string fileName = MainConsole.Instance.Prompt("What file name will this be saved as?",
                                                          scene.RegionInfo.RegionName + ".abackup");

            //some file sanity checks
            string extension = Path.GetExtension (fileName);

            if (extension == string.Empty)
            {
                fileName = fileName + ".abackup";
            }

            string fileDir = Path.GetDirectoryName(fileName);
            if (fileDir == "") { fileDir = "./"; }
            if (!Directory.Exists(fileDir))
            {
                MainConsole.Instance.Info ( "[Archiver]: The file path specified, '" + fileDir + "' does not exist!" );
                return;
            }

            if (File.Exists(fileName)) {
                if (MainConsole.Instance.Prompt ("[Archiver]: The Region archive file '" + fileName + "' already exists. Overwrite?", "yes" ) != "yes")
                    return;

                File.Delete (fileName);
            }

            GZipStream m_saveStream = new GZipStream(new FileStream(fileName, FileMode.Create), CompressionMode.Compress);
            TarArchiveWriter writer = new TarArchiveWriter(m_saveStream);

            SaveRegionBackup(writer, scene);
        }
        /// <summary>
        /// Saves the estate settings to an archive.
        /// </summary>
        /// <param name="writer">Writer.</param>
        /// <param name="scene">Scene.</param>
        public void SaveModuleToArchive(TarArchiveWriter writer, IScene scene)
        {
            MainConsole.Instance.Debug("[Archive]: Writing estates to archive");

            EstateSettings settings = scene.RegionInfo.EstateSettings;
            if (settings == null)
                return;
            writer.WriteDir("estatesettings");
            writer.WriteFile("estatesettings/" + scene.RegionInfo.RegionName,
                             OSDParser.SerializeLLSDBinary(settings.ToOSD()));

            MainConsole.Instance.Debug("[Archive]: Finished writing estates to archive");
            MainConsole.Instance.Debug("[Archive]: Writing region info to archive");

            writer.WriteDir("regioninfo");
            RegionInfo regionInfo = scene.RegionInfo;

            writer.WriteFile("regioninfo/" + scene.RegionInfo.RegionName,
                             OSDParser.SerializeLLSDBinary(regionInfo.PackRegionInfoData()));

            MainConsole.Instance.Debug("[Archive]: Finished writing region info to archive");
        }
        /// <summary>
        /// Execute the inventory write request
        /// </summary>
        public void Execute(string fileName)
        {
            Stream m_saveStream = new GZipStream (new FileStream (fileName, FileMode.Create), CompressionMode.Compress);
            try
            {
                InventoryFolderBase inventoryFolder = new InventoryFolderBase (UUID.Zero, UUID.Zero);
                if (m_rootFolders.Count == 1)
                    inventoryFolder = m_rootFolders[0];

                bool saveFolderContentsOnly = false;

                m_archiveWriter = new TarArchiveWriter (m_saveStream);

                if (inventoryFolder != null)
                {
                    //recurse through all dirs getting dirs and files
                    SaveInvFolder (inventoryFolder, ArchiveConstants.INVENTORY_PATH, !saveFolderContentsOnly);
                }
            }
            catch (Exception)
            {
                m_saveStream.Close ();
                throw;
            }
            foreach (AssetBase asset in m_loadedAssets.Values)
            {
                WriteData (asset);
            }
            m_saveStream.Close ();
            MessageBox.Show ("Save complete!");
        }
        /// <summary>
        ///     Archive the region requested.
        /// </summary>
        /// <exception cref="System.IO.IOException">if there was an io problem with creating the file</exception>
        public void ArchiveRegion()
        {
            Dictionary<UUID, AssetType> assetUuids = new Dictionary<UUID, AssetType>();

            ISceneEntity[] entities = m_scene.Entities.GetEntities();
            List<ISceneEntity> sceneObjects = new List<ISceneEntity>();
            int numObjectsSkippedPermissions = 0;

            // Filter entities so that we only have scene objects.
            // FIXME: Would be nicer to have this as a proper list in SceneGraph, since lots of methods
            // end up having to do this
            foreach (ISceneEntity entity in entities.Where(entity => !entity.IsDeleted && !entity.IsAttachment))
            {
                if (!CanUserArchiveObject(m_scene.RegionInfo.EstateSettings.EstateOwner, entity, m_checkPermissions))
                    // The user isn't allowed to copy/transfer this object, so it will not be included in the OAR.
                    ++numObjectsSkippedPermissions;
                else
                    sceneObjects.Add(entity);
            }

            UuidGatherer assetGatherer = new UuidGatherer(m_scene.AssetService);

            foreach (ISceneEntity sceneObject in sceneObjects)
            {
                assetGatherer.GatherAssetUuids(sceneObject, assetUuids);
            }

            MainConsole.Instance.InfoFormat(
                "[Archiver]: {0} scene objects to serialize requiring save of {1} assets",
                sceneObjects.Count, assetUuids.Count);

            if (numObjectsSkippedPermissions > 0)
            {
                MainConsole.Instance.DebugFormat(
                    "[Archiver]: {0} scene objects skipped due to lack of permissions",
                    numObjectsSkippedPermissions);
            }

            // Make sure that we also request terrain texture assets
            RegionSettings regionSettings = m_scene.RegionInfo.RegionSettings;

            if (regionSettings.TerrainTexture1 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_1)
                assetUuids[regionSettings.TerrainTexture1] = AssetType.Texture;

            if (regionSettings.TerrainTexture2 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_2)
                assetUuids[regionSettings.TerrainTexture2] = AssetType.Texture;

            if (regionSettings.TerrainTexture3 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_3)
                assetUuids[regionSettings.TerrainTexture3] = AssetType.Texture;

            if (regionSettings.TerrainTexture4 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_4)
                assetUuids[regionSettings.TerrainTexture4] = AssetType.Texture;

            TarArchiveWriter archiveWriter = new TarArchiveWriter(m_saveStream);

            // Asynchronously request all the assets required to perform this archive operation
            ArchiveWriteRequestExecution awre
                = new ArchiveWriteRequestExecution(
                    sceneObjects,
                    m_scene.RequestModuleInterface<ITerrainModule>(),
                    m_scene.RequestModuleInterface<IRegionSerialiserModule>(),
                    m_scene,
                    archiveWriter,
                    m_requestId);

            new AssetsRequest(
                new AssetsArchiver(archiveWriter), assetUuids,
                m_scene.AssetService, awre.ReceivedAllAssets).Execute();
        }
 public AssetsArchiver(TarArchiveWriter archiveWriter)
 {
     m_archiveWriter = archiveWriter;
 }
        /// <summary>
        ///     Execute the inventory write request
        /// </summary>
        public void Execute()
        {
            try
            {
                InventoryFolderBase inventoryFolder = null;
                InventoryItemBase inventoryItem = null;
                InventoryFolderBase rootFolder =
                    m_registry.RequestModuleInterface<IInventoryService>().GetRootFolder(m_userInfo.PrincipalID);

                if (m_defaultFolderToSave != null)
                    rootFolder = m_defaultFolderToSave;

                bool saveFolderContentsOnly = false;

                // Eliminate double slashes and any leading / on the path.
                string[] components
                    = m_invPath.Split(
                        new[] {InventoryFolderImpl.PATH_DELIMITER}, StringSplitOptions.RemoveEmptyEntries);

                int maxComponentIndex = components.Length - 1;

                // If the path terminates with a STAR then later on we want to archive all nodes in the folder but not the
                // folder itself.  This may get more sophisicated later on
                if (maxComponentIndex >= 0 && components[maxComponentIndex] == STAR_WILDCARD)
                {
                    saveFolderContentsOnly = true;
                    maxComponentIndex--;
                }

                m_invPath = String.Empty;
                for (int i = 0; i <= maxComponentIndex; i++)
                {
                    m_invPath += components[i] + InventoryFolderImpl.PATH_DELIMITER;
                }

                // Annoyingly Split actually returns the original string if the input string consists only of delimiters
                // Therefore if we still start with a / after the split, then we need the root folder
                if (m_invPath.Length == 0)
                {
                    inventoryFolder = rootFolder;
                }
                else
                {
                    m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
                    List<InventoryFolderBase> candidateFolders
                        = InventoryArchiveUtils.FindFolderByPath(
                            m_registry.RequestModuleInterface<IInventoryService>(), rootFolder, m_invPath);
                    if (candidateFolders.Count > 0)
                        inventoryFolder = candidateFolders[0];
                }

                // The path may point to an item instead
                if (inventoryFolder == null)
                {
                    inventoryItem =
                        InventoryArchiveUtils.FindItemByPath(m_registry.RequestModuleInterface<IInventoryService>(),
                                                             rootFolder, m_invPath);
                    //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
                }

                if (null == inventoryFolder && null == inventoryItem)
                {
                    // We couldn't find the path indicated
                    string errorMessage = string.Format("Aborted save.  Could not find inventory path {0}", m_invPath);
                    Exception e = new InventoryArchiverException(errorMessage);
                    if (m_module != null)
                        m_module.TriggerInventoryArchiveSaved(m_id, false, m_userInfo, m_invPath, m_saveStream, e);
                    throw e;
                }

                m_archiveWriter = new TarArchiveWriter(m_saveStream);

                if (inventoryFolder != null)
                {
                    MainConsole.Instance.DebugFormat(
                        "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
                        inventoryFolder.Name,
                        inventoryFolder.ID,
                        m_invPath == String.Empty ? InventoryFolderImpl.PATH_DELIMITER : m_invPath);

                    //recurse through all dirs getting dirs and files
                    SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !saveFolderContentsOnly);
                }
                else if (inventoryItem != null)
                {
                    MainConsole.Instance.DebugFormat(
                        "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
                        inventoryItem.Name, inventoryItem.ID, m_invPath);

                    SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH);
                }

                // Don't put all this profile information into the archive right now.
                //SaveUsers();
            }
            catch (Exception)
            {
                m_saveStream.Close();
                throw;
            }
            if (m_saveAssets)
            {
                foreach (AssetBase asset in m_assetsToAdd)
                {
                    m_assetUuids[asset.ID] = (AssetType) asset.Type;
                }
                new AssetsRequest(
                    new AssetsArchiver(m_archiveWriter), m_assetUuids,
                    m_registry.RequestModuleInterface<IAssetService>(), ReceivedAllAssets).Execute();
            }
            else
            {
                MainConsole.Instance.Debug("[INVENTORY ARCHIVER]: Save Complete");
                m_archiveWriter.Close();
            }
        }
Esempio n. 11
0
        public bool SaveBackup(string fileName, RegionData regiondata)
        {
            try
            {
                bool oldFileExists = File.Exists(fileName);
                //Do new style saving here!
                GZipStream m_saveStream = new GZipStream(new FileStream(fileName + ".tmp", FileMode.Create),
                                                         CompressionMode.Compress);
                TarArchiveWriter writer = new TarArchiveWriter(m_saveStream);
                GZipStream m_loadStream = new GZipStream(new FileStream(fileName, FileMode.Open),
                                                         CompressionMode.Decompress);
                TarArchiveReader reader = new TarArchiveReader(m_loadStream);

                writer.WriteDir("parcels");

                foreach (LandData parcel in regiondata.Parcels)
                {
                    OSDMap parcelMap = parcel.ToOSD();
                    var binary = OSDParser.SerializeLLSDBinary(parcelMap);
                    writer.WriteFile("parcels/" + parcel.GlobalID.ToString(),
                                     binary);
                    binary = null;
                    parcelMap = null;
                }

                writer.WriteDir("newstyleterrain");
                writer.WriteDir("newstylerevertterrain");

                writer.WriteDir("newstylewater");
                writer.WriteDir("newstylerevertwater");

                writer.WriteDir("regioninfo");
                byte[] regionData = OSDParser.SerializeLLSDBinary(regiondata.RegionInfo.PackRegionInfoData());
                writer.WriteFile("regioninfo/regioninfo", regionData);

                try
                {
                    writer.WriteFile("newstyleterrain/" + regiondata.RegionInfo.RegionID.ToString() + ".terrain",
                                     regiondata.Terrain);

                    writer.WriteFile(
                        "newstylerevertterrain/" + regiondata.RegionInfo.RegionID.ToString() + ".terrain",
                        regiondata.RevertTerrain);

                    if (regiondata.Water != null)
                    {
                        writer.WriteFile("newstylewater/" + regiondata.RegionInfo.RegionID.ToString() + ".terrain",
                                         regiondata.Water);

                        writer.WriteFile(
                            "newstylerevertwater/" + regiondata.RegionInfo.RegionID.ToString() + ".terrain",
                            regiondata.RevertWater);
                    }
                }
                catch (Exception ex)
                {
                    MainConsole.Instance.WarnFormat("[Backup]: Exception caught: {0}", ex);
                }

                List<UUID> entitiesToSave = new List<UUID>();
                foreach (ISceneEntity entity in regiondata.Groups)
                {
                    try
                    {
                        if (entity.IsAttachment ||
                            ((entity.RootChild.Flags & PrimFlags.Temporary) == PrimFlags.Temporary)
                            || ((entity.RootChild.Flags & PrimFlags.TemporaryOnRez) == PrimFlags.TemporaryOnRez))
                            continue;
                        if (entity.HasGroupChanged || !oldFileExists)
                        {
                            entity.HasGroupChanged = false;
                            //Write all entities
                            writer.WriteFile("entities/" + entity.UUID.ToString(), entity.ToBinaryXml2());
                        }
                        else
                            entitiesToSave.Add(entity.UUID);
                    }
                    catch (Exception ex)
                    {
                        MainConsole.Instance.WarnFormat("[Backup]: Exception caught: {0}", ex);
                        entitiesToSave.Add(entity.UUID);
                    }
                }

                if (oldFileExists)
                {
                    byte[] data;
                    string filePath;
                    TarArchiveReader.TarEntryType entryType;
                    //Load the archive data that we need
                    try
                    {
                        while ((data = reader.ReadEntry(out filePath, out entryType)) != null)
                        {
                            if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                                continue;
                            if (filePath.StartsWith("entities/"))
                            {
                                UUID entityID = UUID.Parse(filePath.Remove(0, 9));
                                if (entitiesToSave.Contains(entityID))
                                {
                                    writer.WriteFile(filePath, data);
                                    entitiesToSave.Remove(entityID);
                                }
                            }
                            data = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        MainConsole.Instance.WarnFormat("[Backup]: Exception caught: {0}", ex);
                    }

                    if (entitiesToSave.Count > 0)
                    {
                        MainConsole.Instance.Fatal(entitiesToSave.Count +
                                                   " PRIMS WERE NOT GOING TO BE SAVED! FORCE SAVING NOW! ");
                        foreach (ISceneEntity entity in regiondata.Groups)
                        {
                            if (entitiesToSave.Contains(entity.UUID))
                            {
                                if (entity.IsAttachment ||
                                    ((entity.RootChild.Flags & PrimFlags.Temporary) == PrimFlags.Temporary)
                                    || ((entity.RootChild.Flags & PrimFlags.TemporaryOnRez) == PrimFlags.TemporaryOnRez))
                                    continue;
                                //Write all entities
                                byte[] xml = entity.ToBinaryXml2();
                                writer.WriteFile("entities/" + entity.UUID.ToString(), xml);
                                xml = null;
                            }
                        }
                    }
                }

                reader.Close();
                writer.Close();
                m_loadStream.Close();
                m_saveStream.Close();
                GC.Collect();
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[TarRegionDataLoader]: Failed to save backup: " + ex.ToString());
                return false;
            }
            return true;
        }
Esempio n. 12
0
        private void SaveWhiteCoreArchive(IScene scene, string[] cmd)
        {
            string fileName = MainConsole.Instance.Prompt("What file name will this be saved as?",
                                                          scene.RegionInfo.RegionName + ".abackup");

            GZipStream m_saveStream = new GZipStream(new FileStream(fileName, FileMode.Create), CompressionMode.Compress);
            TarArchiveWriter writer = new TarArchiveWriter(m_saveStream);

            SaveRegionBackup(writer, scene);
        }