# DB Backup Document > KT to : Viya, Polly Date: -09-2022 1) Detail instrunction for BTC and Factory databse backup has included in below hackmd filesn [BTC DB Backup](https://hackmd.io/TmdfDh2vSjC18vsvVus7iQ) [Factory DB Backup](https://hackmd.io/rMXjE8TwSJmf6JRPnwc8Qw?view) 2) Once backup has completed need to update BTC/Factory DB file with updated DB size in GB and screenshots ## Follow below mentioned steps to take database backup #### dtaDB database statistics (Before delete) 1. Database and collection statistics before deleting old records **dtaDB** Storage size: **5.3GB** ![](https://i.imgur.com/GJz9mnO.png) #### Realtimestatus statistics (Before delete) **realtimestatus** No. of documents: **13416315** Storage size: **3.2GB** ![](https://i.imgur.com/n08w8fq.png) 2. Create folder : Check existing folders ``` Path: /home/test/ Command: ls -lrt factory-backup-2022-09-04-2022-09-19 ssh to BTC database ssh test@10.100.1.8 mkdir <folder name> Folder name format:<factory-backup-(START Date yyyy-mm-dd)-(End Date yyyy-mm-dd)> factory-backup-2022-09-04-2022-09-19 Modify folder permission: chmod -R 777 <folder name> ``` 3. Compress and backup the existing dtaDB on the production server ``` mongodump --uri="mongodb://10.100.1.8:27017/dtaDB?" --gzip --out=/home/test/factory-backup-2022-09-04-2022-09-19 ls factory-backup-2022-09-04-2022-09-19/dtaDB/ * Copy backup to RD_backup machine 1. ssh test@10.10.80.76 2. Execute below command on 10.10.80.76 scp -r test@10.100.1.8:/home/test/factory-backup-2022-09-04-2022-09-19 /home/test/BTC/ ``` 4. Delete Realtimestatus data from dtaDB database #### Delete Realtimestatus records * ssh to Factory database ssh test@10.100.1.8 * sudo su * execute command in mongo shell * mongo * use dtaDB * Delete the old records in realtimestatus collection ``` db.realtimestatus.deleteMany({"date":{$lt: new ISODate("2022-09-18 00:00:00.000Z")}}) { "acknowledged" : true, "deletedCount" : 12498319 } # Compact the collection db.runCommand({compact:'realtimestatus'}) ``` #### dtaDB database statistics (after delete) 5. Database and collection statistics after deleting old records **dtaDB** Storage size: **2.2GB** ![](https://i.imgur.com/8XnUI4O.png) #### Realtimestatus statistics (after delete) **realtimestatus** No. of documents: **925021** Storage size: **0.21GB** ![](https://i.imgur.com/oEp9o2l.png)