Secure file download in PHP, Security question PHP, PHP MYSQL Interview Question -Books download - PHP solutions guidelines queries update, phpmysqlquestion
Sunday, May 3, 2020
Git & Github Cheatsheet
Hello Everyone !
Today I am sharing my collection of all everyday use git commands , with usage explanations. This Sheet also contains, the methods to use online git platform like Github.
- The markdown is also available on my Github for instant reference.
Basic Commands
-
Git Config :
-
git config -- global user.name NAME= set user name globally -
git config --global user.email EMAIL= set user email globally -
git config user.name||git config user.email= check saved info
-
Creating repo
-
git init= creates a git repository in the directory currently in
Staging
-
git status= to check status , if staged or unstaged -
git add FILE_NAME= to add a file to staging area -
git rm --cached FILE_NAME= to remove a file from staging area -
git add .= to add all files in project to staging area
Commiting
git commit -m "Specific Changes Made"= commits the staging area giving them a specific idgit log= shows all the commits with detailsgit log --oneline= shows all the commits in one line each-
SPECIAL log : this will log the info in a nice format (Try it once 😉)
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit- this can be used as an alias
Git Stash
-
git stash= clears the changes to the initial state (last commit) & creates a unique id for the current state -
git stash apply= brings back the current state - using git stash multiple times creates a list of stashes of all states with multiple ids
-
git stash list= shows all the stash (States) with their ID -
git stash apply ID= ID will be the number , which state you want to go back to -
git stash push -m "Your message"= used to give description to stash -
git stash drop ID= used to remove a stash saved -
git stash pop ID= applies the specific stash and removes it from history -
git stash clear= removes all the stash history
Gitignore
- a
.gitignorefile can be created , in which you can specify all the folders/files that should not be staged and commited - For example :
node_modules/.css.mapetc. - It's Good to create a gitignore at the start of Project
- a good gitignore generator for reference :
Reverting & Reset
- use
git log --onelineto see the commit_ID to change to - Checkout commit :
-
git checkout commit_ID= to just check the commit id entered , see it in read only ... changes will not be saved -
git checkout master= to come back to original commit (As checkout removes us from master branch)
-
-
Revert commit :
-
git revert commit_ID= to remove the changes of the provided commit (will add a new revert commit and remove the changes of the specific commit)
-
-
Reset Commit :
-
git reset commit_ID= will remove all the commits after the provided id , but the files in local directory will not be touched (therefore you can still commit to original state after doiHello Everyone !
Today I am sharing my collection of all everyday use git commands , with usage explanations. This Sheet also contains, the methods to use online git platform like Github.
- The markdown is also available on my Github for instant reference.
Basic Commands
-
-
Git Config :
-
git config -- global user.name NAME= set user name globally -
git config --global user.email EMAIL= set user email globally -
git config user.name||git config user.email= check saved info
-
Creating repo
-
git init= creates a git repository in the directory currently in
Staging
-
git status= to check status , if staged or unstaged -
git add FILE_NAME= to add a file to staging area -
git rm --cached FILE_NAME= to remove a file from staging area -
git add .= to add all files in project to staging area
Commiting
git commit -m "Specific Changes Made"= commits the staging area giving them a specific idgit log= shows all the commits with detailsgit log --oneline= shows all the commits in one line each-
SPECIAL log : this will log the info in a nice format (Try it once 😉)
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit- this can be used as an alias
Git Stash
-
git stash= clears the changes to the initial state (last commit) & creates a unique id for the current state -
git stash apply= brings back the current state - using git stash multiple times creates a list of stashes of all states with multiple ids
-
git stash list= shows all the stash (States) with their ID -
git stash apply ID= ID will be the number , which state you want to go back to -
git stash push -m "Your message"= used to give description to stash -
git stash drop ID= used to remove a stash saved -
git stash pop ID= applies the specific stash and removes it from history -
git stash clear= removes all the stash history
Gitignore
- a
.gitignorefile can be created , in which you can specify all the folders/files that should not be staged and commited - For example :
node_modules/.css.mapetc. - It's Good to create a gitignore at the start of Project
- a good gitignore generator for reference :
Reverting & Reset
- use
git log --onelineto see the commit_ID to change to - Checkout commit :
-
git checkout commit_ID= to just check the commit id entered , see it in read only ... changes will not be saved -
git checkout master= to come back to original commit (As checkout removes us from master branch)
-
-
Revert commit :
-
git revert commit_ID= to remove the changes of the provided commit (will add a new revert commit and remove the changes of the specific commit)
-
-
Reset Commit :
-
git reset commit_ID= will remove all the commits after the provided id , but the files in local directory will not be touched (therefore you can still commit to original state after doing changes as needed) ... might take you to vim editor (type ":wq" then "Enter" to exit) -
git reset commit_ID --hard= will remove all the commits after the provided id and even delete all the files and lines from local directory too
-
Branches
- Used to test a new feature or code , by creating a branch .. then merging it to master only if needed
- can be used for multiple developers working on same project .. create different branch for each developer adding their own feature then merging at the end
-
git branch branch_name= to create a new branch -
git branch -a= to list all the branches -
git checkout branch_name= to shift to the other branch -
git branch -d branch_name= to delete the branch only when it has been merged -
git branch -D branch_name= to delete the branch (even if not merged to master) -
git checkout -b branch_name= to create and shift to a new branch at once
Merging branches
- after completing changes in a branch and commiting them
- come back to master and run
git merge branch_name= this will merge the branch to master (all commits show in master) = automaticgit merge --squash branch_name= this will merge the branch to master (only the commit after merge is shown in master) = manual
Conflicts
- If Branch's Base (First Commit) is Master's Head (Last Commit) = No Conflict
- If Master had commits after creating Branch = Conflicts Might Come
- to solve this , edit the files manually , Solve The Conflicts then ..
- run
git add .and thengit commit -m "Message"and the changes will be made
Git Rebase & Git Merge
- Using Git Merge Shows that the Branches Were Added to master , i.e the tree is not inline for all commits
- whereas Git Rebase keeps changing the base, and makes the commit inline , feels like the branch was never there
-
RUN
git rebase masteron your branch
- Takes the base of master , matches it with every commit of your branch
- If The Master is already your base , no need of step 3, 4, 5
- solve the conflicts , then
git add . - run
git rebase --continue - Repeat 2, 3 steps for every commit - conflict
- Now The Master's Head is Branch's Base
- Move to Master
- run
git rebase branch_name - Now All the commits of Branch are added above your Master commits
- NOTE! : It is specified in the git docs that rebase should not be used in public repos (collaboration) as it can cause major errors and conflicts, it can be used in private repos.
Github
-
Creating new & Cloning Repo
- create a new repo on Github and copy the URL
- now push your code to it with
-
git push git_url master= pushing code of master branch (to push all branches replace master with --all) - creating an alias to not always type URL
-
git remote add origin git_url= origin can be name of anything else, but origin is the word most commonly used -
git push origin master= to push code to using alias -
git push -u origin master= pushes and starts tracking the branch (u don't need to specify it again , ex. if pulling) -
git clone git_url= will copy the repo to current directory and also add the origin alias by default -
git remote -v= to check all the aliases made - adding id and password in push\pull :
- replacing the origin in
git push origin master git push https://username:password@repo_url.git master- if password contains @ replace it with %40
- NOTE : this can store your password in plain text
- to avoid this you can remove the password and enter it later
git push https://username@repo_url.git master
- replacing the origin in
-
Collaborating
- Most of the collaboration features are already available on Github, Example
-
git pull git_url= to pull changes from remote to local repo - create a branch and make your changes
-
git push origin branch_name= to push the specific branch to remote - create a Compare & Pull Request when you want are ready for the branch to be merged (with a message)
- the reviewer of the repo will accept the changes and merge it (and specify a merge commit message)
- pull the project every time before editing to see the changes
-
git branch -r= helps us to see the remote branches & the connections
-
Forking (Contributing)
- to contribute to an open source project
- click on fork , which will copy the repo to your account
- make changes by pulling the repo, then push it ( this will happen on your account )
- then go to the owner account's repo and create a pull request there
- the owner can compare the changes and accept your changes
- which will end up merging your changes to their project
- ng changes as needed) ... might take you to vim editor (type ":wq" then "Enter" to exit)
-
git reset commit_ID --hard= will remove all the commits after the provided id and even delete all the files and lines from local directory too
Branches
- Used to test a new feature or code , by creating a branch .. then merging it to master only if needed
- can be used for multiple developers working on same project .. create different branch for each developer adding their own feature then merging at the end
-
git branch branch_name= to create a new branch -
git branch -a= to list all the branches -
git checkout branch_name= to shift to the other branch -
git branch -d branch_name= to delete the branch only when it has been merged -
git branch -D branch_name= to delete the branch (even if not merged to master) -
git checkout -b branch_name= to create and shift to a new branch at once
Merging branches
- after completing changes in a branch and commiting them
- come back to master and run
git merge branch_name= this will merge the branch to master (all commits show in master) = automaticgit merge --squash branch_name= this will merge the branch to master (only the commit after merge is shown in master) = manual
Conflicts
- If Branch's Base (First Commit) is Master's Head (Last Commit) = No Conflict
- If Master had commits after creating Branch = Conflicts Might Come
- to solve this , edit the files manually , Solve The Conflicts then ..
- run
git add .and thengit commit -m "Message"and the changes will be made
Git Rebase & Git Merge
- Using Git Merge Shows that the Branches Were Added to master , i.e the tree is not inline for all commits
- whereas Git Rebase keeps changing the base, and makes the commit inline , feels like the branch was never there
-
RUN
git rebase masteron your branch
- Takes the base of master , matches it with every commit of your branch
- If The Master is already your base , no need of step 3, 4, 5
- solve the conflicts , then
git add . - run
git rebase --continue - Repeat 2, 3 steps for every commit - conflict
- Now The Master's Head is Branch's Base
- Move to Master
- run
git rebase branch_name - Now All the commits of Branch are added above your Master commits
- NOTE! : It is specified in the git docs that rebase should not be used in public repos (collaboration) as it can cause major errors and conflicts, it can be used in private repos.
Github
-
Creating new & Cloning Repo
- create a new repo on Github and copy the URL
- now push your code to it with
-
git push git_url master= pushing code of master branch (to push all branches replace master with --all) - creating an alias to not always type URL
-
git remote add origin git_url= origin can be name of anything else, but origin is the word most commonly used -
git push origin master= to push code to using alias -
git push -u origin master= pushes and starts tracking the branch (u don't need to specify it again , ex. if pulling) -
git clone git_url= will copy the repo to current directory and also add the origin alias by default -
git remote -v= to check all the aliases made - adding id and password in push\pull :
- replacing the origin in
git push origin master git push https://username:password@repo_url.git master- if password contains @ replace it with %40
- NOTE : this can store your password in plain text
- to avoid this you can remove the password and enter it later
git push https://username@repo_url.git master
- replacing the origin in
-
Collaborating
- Most of the collaboration features are already available on Github, Example
-
git pull git_url= to pull changes from remote to local repo - create a branch and make your changes
-
git push origin branch_name= to push the specific branch to remote - create a Compare & Pull Request when you want are ready for the branch to be merged (with a message)
- the reviewer of the repo will accept the changes and merge it (and specify a merge commit message)
- pull the project every time before editing to see the changes
-
git branch -r= helps us to see the remote branches & the connections
-
Forking (Contributing)
- to contribute to an open source project
- click on fork , which will copy the repo to your account
- make changes by pulling the repo, then push it ( this will happen on your account )
- then go to the owner account's repo and create a pull request there
- the owner can compare the changes and accept your changes
- which will end up merging your changes to their project
Kubectl Kubernetes Free CheatSheet
- PDF Link: cheatsheet-kubernetes-A4.pdf, Category: Cloud
- Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-A4
- Related posts: Kubectl CheatSheet, Kubernetes Yaml, #denny-cheatsheets
1.1 Common Commands
| Name | Command |
|---|---|
| Run curl test temporarily | kubectl run --rm mytest --image=yauritux/busybox-curl -it |
| Run wget test temporarily | kubectl run --rm mytest --image=busybox -it |
| Run nginx deployment with 2 replicas | kubectl run my-nginx --image=nginx --replicas=2 --port=80 |
| Run nginx pod and expose it | kubectl run my-nginx --restart=Never --image=nginx --port=80 --expose |
| Run nginx deployment and expose it | kubectl run my-nginx --image=nginx --port=80 --expose |
| Set namespace preference | kubectl config set-context |
| List pods with nodes info | kubectl get pod -o wide |
| List everything | kubectl get all --all-namespaces |
| Get all services | kubectl get service --all-namespaces |
| Get all deployments | kubectl get deployments --all-namespaces |
| Show nodes with labels | kubectl get nodes --show-labels |
| Get resources with json output | kubectl get pods --all-namespaces -o json |
| Validate yaml file with dry run | kubectl create --dry-run --validate -f pod-dummy.yaml |
| Start a temporary pod for testing | kubectl run --rm -i -t --image=alpine test-$RANDOM -- sh |
| kubectl run shell command | kubectl exec -it mytest -- ls -l /etc/hosts |
| Get system conf via configmap | kubectl -n kube-system get cm kubeadm-config -o yaml |
| Get deployment yaml | kubectl -n denny-websites get deployment mysql -o yaml |
| Explain resource | kubectl explain pods, kubectl explain svc |
| Watch pods | kubectl get pods -n wordpress --watch |
| Query healthcheck endpoint | curl -L http://127.0.0.1:10250/healthz |
| Open a bash terminal in a pod | kubectl exec -it storage sh |
| Check pod environment variables | kubectl exec redis-master-ft9ex env |
| Enable kubectl shell autocompletion | echo "source <(kubectl completion bash)" >>~/.bashrc, and reload |
| Use minikube dockerd in your laptop | eval $(minikube docker-env), No need to push docker hub any more |
| Kubectl apply a folder of yaml files | kubectl apply -R -f . |
| Get services sorted by name | kubectl get services –sort-by=.metadata.name |
| Get pods sorted by restart count | kubectl get pods –sort-by=’.status.containerStatuses[0].restartCount’ |
| List pods and images | kubectl get pods -o=’custom-columns=PODS:.metadata.name,Images:.spec.containers[*].image’ |
| List all container images | list-all-images.sh |
| kubeconfig skip tls verification | skip-tls-verify.md |
| Ubuntu install kubectl | "deb https://apt.kubernetes.io/ kubernetes-xenial main" |
| Reference | GitHub: kubernetes releases |
| Reference | minikube cheatsheet, docker cheatsheet, OpenShift CheatSheet |
1.2 Check Performance
| Name | Command |
|---|---|
| Get node resource usage | kubectl top node |
| Get pod resource usage | kubectl top pod |
| Get resource usage for a given pod | kubectl top |
| List resource utilization for all containers | kubectl top pod --all-namespaces --containers=true |
1.3 Resources Deletion
| Name | Command |
|---|---|
| Delete pod | kubectl delete pod/ |
| Delete pod by force | kubectl delete pod/ |
| Delete pods by labels | kubectl delete pod -l env=test |
| Delete deployments by labels | kubectl delete deployment -l app=wordpress |
| Delete all resources filtered by labels | kubectl delete pods,services -l name=myLabel |
| Delete resources under a namespace | kubectl -n my-ns delete po,svc --all |
| Delete persist volumes by labels | kubectl delete pvc -l app=wordpress |
| Delete state fulset only (not pods) | kubectl delete sts/ |
1.4 Log & Conf Files
| Name | Comment |
|---|---|
| Config folder | /etc/kubernetes/ |
| Certificate files | /etc/kubernetes/pki/ |
| Credentials to API server | /etc/kubernetes/kubelet.conf |
| Superuser credentials | /etc/kubernetes/admin.conf |
| kubectl config file | ~/.kube/config |
| Kubernets working dir | /var/lib/kubelet/ |
| Docker working dir | /var/lib/docker/, /var/log/containers/ |
| Etcd working dir | /var/lib/etcd/ |
| Network cni | /etc/cni/net.d/ |
| Log files | /var/log/pods/ |
| log in worker node | /var/log/kubelet.log, /var/log/kube-proxy.log |
| log in master node | kube-apiserver.log, kube-scheduler.log, kube-controller-manager.log |
| Env | /etc/systemd/system/kubelet.service.d/10-kubeadm.conf |
| Env | export KUBECONFIG=/etc/kubernetes/admin.conf |
1.5 Pod
| Name | Command |
|---|---|
| List all pods | kubectl get pods |
| List pods for all namespace | kubectl get pods -all-namespaces |
| List all critical pods | kubectl get -n kube-system pods -a |
| List pods with more info | kubectl get pod -o wide, kubectl get pod/ |
| Get pod info | kubectl describe pod/srv-mysql-server |
| List all pods with labels | kubectl get pods --show-labels |
| List all unhealthy pods | kubectl get pods –field-selector=status.phase!=Running –all-namespaces |
| List running pods | kubectl get pods –field-selector=status.phase=Running |
| Get Pod initContainer status | kubectl get pod --template '{{.status.initContainerStatuses}}' |
| kubectl run command | kubectl exec -it -n “$ns” “$podname” – sh -c “echo $msg >>/dev/err.log” |
| Watch pods | kubectl get pods -n wordpress --watch |
| Get pod by selector | kubectl get pods –selector=”app=syslog” -o jsonpath='{.items[*].metadata.name}’ |
| List pods and images | kubectl get pods -o=’custom-columns=PODS:.metadata.name,Images:.spec.containers[*].image’ |
| List pods and containers | -o=’custom-columns=PODS:.metadata.name,CONTAINERS:.spec.containers[*].name’ |
| Reference | Link: kubernetes yaml templates |
6 Label & Annontation
| Name | Command |
|---|---|
| Filter pods by label | kubectl get pods -l owner=denny |
| Manually add label to a pod | kubectl label pods dummy-input owner=denny |
| Remove label | kubectl label pods dummy-input owner- |
| Manually add annonation to a pod | kubectl annotate pods dummy-input my-url=https://dennyzhang.com |
1.7 Deployment & Scale
| Name | Command |
|---|---|
| Scale out | kubectl scale --replicas=3 deployment/nginx-app |
| online rolling upgrade | kubectl rollout app-v1 app-v2 --image=img:v2 |
| Roll backup | kubectl rollout app-v1 app-v2 --rollback |
| List rollout | kubectl get rs |
| Check update status | kubectl rollout status deployment/nginx-app |
| Check update history | kubectl rollout history deployment/nginx-app |
| Pause/Resume | kubectl rollout pause deployment/nginx-deployment, resume |
| Rollback to previous version | kubectl rollout undo deployment/nginx-deployment |
| Reference | Link: kubernetes yaml templates, Link: Pausing and Resuming a Deployment |
1.8 Quota & Limits & Resource
| Name | Command |
|---|---|
| List Resource Quota | kubectl get resourcequota |
| List Limit Range | kubectl get limitrange |
| Customize resource definition | kubectl set resources deployment nginx -c=nginx --limits=cpu=200m |
| Customize resource definition | kubectl set resources deployment nginx -c=nginx --limits=memory=512Mi |
| Reference | Link: kubernetes yaml templates |
1.9 Service
| Name | Command |
|---|---|
| List all services | kubectl get services |
| List service endpoints | kubectl get endpoints |
| Get service detail | kubectl get service nginx-service -o yaml |
| Get service cluster ip | kubectl get service nginx-service -o go-template='{{.spec.clusterIP}}’ |
| Get service cluster port | kubectl get service nginx-service -o go-template='{{(index .spec.ports 0).port}}’ |
| Expose deployment as lb service | kubectl expose deployment/my-app --type=LoadBalancer --name=my-service |
| Expose service as lb service | kubectl expose service/wordpress-1-svc --type=LoadBalancer --name=ns1 |
| Reference | Link: kubernetes yaml templates |
1.10 Secrets
| Name | Command |
|---|---|
| List secrets | kubectl get secrets --all-namespaces |
| Generate secret | echo -n 'mypasswd', then redirect to base64 --decode |
| Get secret | kubectl get secret denny-cluster-kubeconfig |
| Get a specific field of a secret | kubectl get secret denny-cluster-kubeconfig -o jsonpath=”{.data.value}” |
| Create secret from cfg file | kubectl create secret generic db-user-pass –from-file=./username.txt |
| Reference | Link: kubernetes yaml templates, Link: Secrets |
1.11 StatefulSet
| Name | Command |
|---|---|
| List statefulset | kubectl get sts |
| Delete statefulset only (not pods) | kubectl delete sts/ |
| Scale statefulset | kubectl scale sts/ |
| Reference | Link: kubernetes yaml templates |
1.12 Volumes & Volume Claims
| Name | Command |
|---|---|
| List storage class | kubectl get storageclass |
| Check the mounted volumes | kubectl exec storage ls /data |
| Check persist volume | kubectl describe pv/pv0001 |
| Copy local file to pod | kubectl cp /tmp/my |
| Copy pod file to local | kubectl cp |
| Reference | Link: kubernetes yaml templates |
1.13 Events & Metrics
| Name | Command |
|---|---|
| View all events | kubectl get events --all-namespaces |
| List Events sorted by timestamp | kubectl get events –sort-by=.metadata.creationTimestamp |
1.14 Node Maintenance
| Name | Command |
|---|---|
| Mark node as unschedulable | kubectl cordon $NDOE_NAME |
| Mark node as schedulable | kubectl uncordon $NDOE_NAME |
| Drain node in preparation for maintenance | kubectl drain $NODE_NAME |
1.15 Namespace & Security
| Name | Command |
|---|---|
| List authenticated contexts | kubectl config get-contexts, ~/.kube/config |
| Set namespace preference | kubectl config set-context |
| Load context from config file | kubectl get cs --kubeconfig kube_config.yml |
| Switch context | kubectl config use-context |
| Delete the specified context | kubectl config delete-context |
| List all namespaces defined | kubectl get namespaces |
| List certificates | kubectl get csr |
| Reference | Link: kubernetes yaml templates |
1.16 Network
| Name | Command |
|---|---|
| Temporarily add a port-forwarding | kubectl port-forward redis-134 6379:6379 |
| Add port-forwaring for deployment | kubectl port-forward deployment/redis-master 6379:6379 |
| Add port-forwaring for replicaset | kubectl port-forward rs/redis-master 6379:6379 |
| Add port-forwaring for service | kubectl port-forward svc/redis-master 6379:6379 |
| Get network policy | kubectl get NetworkPolicy |
1.17 Patch
| Name | Summary |
|---|---|
| Patch service to loadbalancer | kubectl patch svc $svc_name -p '{"spec": {"type": "LoadBalancer"}}' |
1.18 Extenstions
1.19 Components & Services
1.19.1 Services on Master Nodes
| Name | Summary |
|---|---|
| kube-apiserver | exposes the Kubernetes API from master nodes |
| etcd | reliable data store for all k8s cluster data |
| kube-scheduler | schedule pods to run on selected nodes |
| kube-controller-manager | node controller, replication controller, endpoints controller, and service account & token controllers |
1.19.2 Services on Worker Nodes
| Name | Summary |
|---|---|
| kubelet | makes sure that containers are running in a pod |
| kube-proxy | perform connection forwarding |
| Container Runtime | Kubernetes supported runtimes: Docker, rkt, runc and any OCI runtime-spec implementation. |
1.19.3 Addons: pods and services that implement cluster features
| Name | Summary |
|---|---|
| DNS | serves DNS records for Kubernetes services |
| Web UI | a general purpose, web-based UI for Kubernetes clusters |
| Container Resource Monitoring | collect, store and serve container metrics |
| Cluster-level Logging | save container logs to a central log store with search/browsing interface |
1.19.4 Tools
| Name | Summary |
|---|---|
| kubectl | the command line util to talk to k8s cluster |
| kubeadm | the command to bootstrap the cluster |
| kubefed | the command line to control a Kubernetes Cluster Federation |
| Kubernetes Components | Link: Kubernetes Components |
1.20 More Resources
License: Code is licensed under MIT License.
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
https://codefresh.io/kubernetes-guides/kubernetes-cheat-sheet/
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
https://codefresh.io/kubernetes-guides/kubernetes-cheat-sheet/
Tuesday, August 14, 2018
MongoDB: List all collections by size
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
Improved how to get the collection:
function getReadableFileSizeString(fileSizeInBytes) {
var i = -1;
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
};
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db.getCollection(n).stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + getReadableFileSizeString(stats[c]['size']) + " (" + getReadableFileSizeString(stats[c]['storageSize']) + ")"); }
x
var i = -1;
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
};
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db.getCollection(n).stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + getReadableFileSizeString(stats[c]['size']) + " (" + getReadableFileSizeString(stats[c]['storageSize']) + ")"); }
x
Tuesday, June 12, 2018
manually load scan dir / load directory in command line php
For checking of the .ini loaded via command line is
php --ini
If scan directory is mentioning the right path of additional loading directory path then there is nothing to do. You can use it as per your requirement.
If additional scan directory is empty then run the following are the command, you can apply on the command line
PHP_INI_SCAN_DIR=/usr/local/etc/php/7.1/conf.d
php --ini
If scan directory is mentioning the right path of additional loading directory path then there is nothing to do. You can use it as per your requirement.
If additional scan directory is empty then run the following are the command, you can apply on the command line
PHP_INI_SCAN_DIR=/usr/local/etc/php/7.1/conf.d
export PHP_INI_SCAN_DIR
Subscribe to:
Comments (Atom)
How to solve mysql ERROR 1118 (42000) Row size too large
I had this issue with MYSQL 5.7 . The following worked althoug...
-
Introduction to PHP PDO (PHP Data Objects) 1. What is PDO 2. What Databases does PDO support 3. Where do I begin? 4. Connect to ...
-
SQLSTATE[HY000]: General error MySQL: 1364 Field 'coloum' doesn't have a default value, how to solveWith the root access of the mysql, do the following changes select @@ GLOBAL . sql_mode In my case, I get the following: ONLY_FULL_...
-
I had this issue with MYSQL 5.7 . The following worked althoug...