AngularJS, MEAN, MongoDB

MongoDB Backup/Dump and Restore

MongoDB Backup/Dump and Restore , one of the most important things we must need to know !

ssh example.host
mongodump --db productionDb
tar czf ./dump.tgz ./dump
scp dump.tgz user@development.host

tar xzf ./dump.tgz
cd ./dump
mongorestore --db example_test ./productionDb

Advertisements
Standard
C#, SQL Server

Compress SQL Server DB .bak file in C#

Many a time , We need to take Backup of our Production Database . Most of the Time , This process is done Automatically .

And After Taking the Database , we can also compress that and keep for later use . This is how , we can compress Our .bak file in C# .

public void CompressDbBackup(string sFileName)
        {
            try
            {
                string sZipFileName = sFileName.Replace(".bak", ".zip");

                using (FileStream fStream = File.Open(sZipFileName, FileMode.Create))
                {
                    GZipStream obj = new GZipStream(fStream, CompressionMode.Compress);

                    byte[] bt = File.ReadAllBytes(sFileName);
                    obj.Write(bt, 0, bt.Length);

                    obj.Close();
                    obj.Dispose();
                }

                File.Delete(sFileName);
            }
            catch (Exception ex)
            {
                // Log Recorded
            }
        }

There will be another Post on How we can take Database backup Programmatically .

Keep an eye on this Blog . Thanks
Cheers 🙂

Standard