示例#1
0
        private void Restore(RestoreInformation restore)
        {
            try
            {
                restore.Status = ProcessStatuses.Started;
                restore.Log("Beginning restore process.");

                Compression.UnZip(restore);

                restore.Log("Unzip complete");

                //var mongoRestore = new MongoRestore(restore);
                //mongoRestore.RestoreDatabase();

                restore.MongoServer.RestoreDatabase(restore);

                restore.Status = ProcessStatuses.Completed;
                restore.Log("Database restore complete.");

                Directory.Delete(restore.Directory, true);
            }
            catch (Exception ex)
            {
                restore.Log(ex.Message, LogLevel.Error);
            }
        }
示例#2
0
        public void RestoreDatabase(RestoreInformation restore)
        {
            restore.Status = ProcessStatuses.InProgress;
            restore.Log($"Restore of {restore.DatabaseRestoreName} started.");

            try
            {
                Client.DropDatabase(restore.DatabaseName);

                var db = Client.GetDatabase(restore.DatabaseName);

                var files = Directory.GetFiles(restore.DatabaseDirectory).Where(f => f.EndsWith(".bson")).ToList();

                files.ForEach(f =>
                {
                    FileInfo fileInfo = new FileInfo(f);
                    try
                    {
                        RestoreCollectionData(fileInfo, db);
                        restore.Log($"{fileInfo.Name} restored.");
                    }
                    catch (Exception ex)
                    {
                        restore.Log($"Error restoring {fileInfo.Name}. Error: {ex.Message}.");
                    }
                });

                restore.Log($"Restore complete.");
            }
            catch (Exception ex)
            {
                restore.Log($"Error restoring {ex.Message}.");
            }
        }
示例#3
0
        public static void UnZip(RestoreInformation restore)
        {
            var zipFile   = restore.File;
            var outFolder = restore.Directory;

            ZipFile zf = null;

            try
            {
                FileStream fs = File.OpenRead(zipFile);
                zf = new ZipFile(fs);
                //if (!String.IsNullOrEmpty(password))
                //{
                //    zf.Password = password;     // AES encrypted entries are handled automatically
                //}
                foreach (ZipEntry zipEntry in zf)
                {
                    if (!zipEntry.IsFile)
                    {
                        continue; // Ignore directories
                    }
                    String entryFileName = zipEntry.Name;
                    // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
                    // Optionally match entrynames against a selection list here to skip as desired.
                    // The unpacked length is available in the zipEntry.Size property.

                    byte[] buffer    = new byte[4096]; // 4K is optimum
                    Stream zipStream = zf.GetInputStream(zipEntry);

                    // Manipulate the output filename here as desired.
                    String fullZipToPath = Path.Combine(outFolder, entryFileName);
                    string directoryName = Path.GetDirectoryName(fullZipToPath);
                    if (directoryName.Length > 0)
                    {
                        Directory.CreateDirectory(directoryName);
                    }

                    // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
                    // of the file, but does not waste memory.
                    // The "using" will close the stream even if an exception occurs.
                    using (FileStream streamWriter = File.Create(fullZipToPath))
                    {
                        StreamUtils.Copy(zipStream, streamWriter, buffer);
                    }
                }
            }
            catch (Exception ex)
            {
                restore.Log(ex.Message, LogLevel.Error);
            }
            finally
            {
                if (zf != null)
                {
                    zf.IsStreamOwner = true; // Makes close also shut the underlying stream
                    zf.Close();              // Ensure we release resources
                }
            }
        }
示例#4
0
        private void importDatabaseButton_Click(object sender, EventArgs e)
        {
            var restoreInfo = new RestoreInformation(RestoreDatabaseName, RestoreFileName, EventAggregator, MongoServer);

            EventAggregator.Publish(new Message <RestoreInformation>(restoreInfo)
            {
                MessageType = MessageTypes.Restore
            });
        }
示例#5
0
 public MongoRestore(RestoreInformation restore)
 {
     this.restore = restore;
 }