Skip to main content

Posts

Showing posts with the label scripting

AWS EC2 AMI Back up Script

Goal: If you looking for an ready made working script to complete back your ec2 servers then these article is there to help you out with working shell script code. Steps: Install aws cli. (I am adding commands for Linux/macOS system, for other env please follow through link share in each steps) $ python -m pip install awscli Detailed steps for various env can be found here . To check version after installation run  $ aws --version Setup Credentials on your machine using below command and try to follow steps. $ aws configure More details can be found here .  Once Everything has been setup. you can copy code from below gist. It takes few input.  Elastic ip of server How long you want to keep your old ami Server name, that's nothing but what initial name you want to keep for your backup ami. Hope this article helped you, Lemme know if you find any difficulty using it will try to help it out ASAP.

Useful MongoDB commands

To export JSON from MongoDB Collection   mongoexport -h replicaSet/primaryHost,secondaryHost -u username -p pwd --db dbName -c collectionName --quiet > collectionExport.json To export BSON from MongoDB Collection mongodump -h replicaSet/primaryHost,secondaryHost -u username -p pwd --db dbName -c collectionName -o - > collectionDump.bson To export some fields in csv from MongoDB Collection mongoexport --host primaryHost --db dbName --collection collectionName --fields 'field1,field2,field3' --out collection.csv --csv -u userName -p To run javascript on MongoDB mongo replicaSet/primaryHost,secondaryHost/dbName -u userName mongoScript.js -p To restore bson in MongoDB mongorestore --host primaryHost --db dbName --collection collectionName -u userName -p --drop  collectionName .bson