Backup VPS

Here are simple steps to backup your VPS. Backup MySQL database Create a directory to store the backup files. Then run mysqldump command to backup your database. mysqldump -u your_mysql_user -pyour_mysql_password your_database_name > /path/to/dump_$(date +\%Y\%m\%d\%H\%M\%S).sql Or you run it as supersuer and backup all databases in once. sudo mysqldump --all-databases > /path/to/dump_$(date +\%Y\%m\%d\%H\%M\%S).sql To automate this, schedule a cron job that will run this command on a daily basis. crontab -e Insert the following line to execute the mysqldump command every day at midnight. ...

September 10, 2023 · 1 min · Amer Khalid

How to backup Kubernetes' Config

The easiest solution seems to be following script by Stackoverflow user, Timothy Perez : <pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">#!/bin/bash # NAMESPACED EXPORTS for ns in $( kubectl get ns --no-headers | cut -d " " -f1 ) ; do kubectl --namespace = " ${ ns} " get -o = json bindings,cm,ep,ev,limits,pvc,po,podtemplates,rc,quota,secrets,sa,svc,controllerrevisions,ds,deploy,rs,sts,localsubjectaccessreviews,hpa,cj,jobs,leases,ev,ds,deploy,ing,netpol,rs,pods,netpol,pdb,roles,rolebindings | \ jq '.items[] | select(.type!="kubernetes.io/service-account-token") | del( .spec.clusterIP, .metadata.uid, .metadata.selfLink, .metadata.resourceVersion, .metadata.creationTimestamp, .metadata.generation, .status, .spec.template.spec.securityContext, .spec.template.spec.dnsPolicy, .spec.template.spec.terminationGracePeriodSeconds, .spec.template.spec.restartPolicy )' >> "./ ${ ns} .json" done # NON-NAMESPACED EXPORTS kubectl get -o = json cs,ns,no,pv,mutatingwebhookconfigurations,validatingwebhookconfigurations,crds,apiservices,tokenreviews,selfsubjectaccessreviews,selfsubjectrulesreviews,subjectaccessreviews,csr,psp,nodes,psp,clusterrolebindings,clusterroles,pc,sc,volumeattachments | \ jq '.items[] | select(.type!="kubernetes.io/service-account-token") | del( .spec.clusterIP, .metadata.uid, .metadata.selfLink, .metadata.resourceVersion, .metadata.creationTimestamp, .metadata.generation, .status, .spec.template.spec.securityContext, .spec.template.spec.dnsPolicy, .spec.template.spec.terminationGracePeriodSeconds, .spec.template.spec.restartPolicy )' >> "./cluster_non-namespaced_export.json" Script copied here under CC BY-SA 4.0 license ...

January 20, 2022 · 1 min · Amer Khalid

Kubernetes not passing full path to Nodejs

I spent hours troubleshooting why url path was getting stripped from requests in our Nodejs/Expressjs based app. The reason was this line in Kubernetes’ Ingress: nginx.ingress.kubernetes.io/rewrite-target : / Removing it fixed the issue. Check Kubernetes documentation for more details.

December 29, 2021 · 1 min · Amer Khalid

Ask HN: Software Engineer hitting 40: what's next?

Recent thread on Hacker News, https://news.ycombinator.com/item?id=29360119, was very interesting for me especially since I turned 40 this year. Programming is something I enjoy and pretty good at it. I’m still not at the top of salary range for programmers but this is a tough question. I can get into FAANG but there is still a ceiling of how much one can earn as a software engineer. This comment says it best: ...

December 1, 2021 · 1 min · Amer Khalid

Wealth Lab Pro Earning Play Screener

This is a quick script that I use to find options to buy or sell. using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { DataSeries maFast = EMAModern.Series(Close, 50 ); DataSeries maSlow = EMAModern.Series(Close, 200 ); DataSeries maFast_1 = EMAModern.Series(Close, 10 ); DataSeries maSlow_2 = EMAModern.Series(Close, 50 ); DataSeries ma = EMAModern.Series(Close, 10 ); DataSeries maFast_3 = EMAModern.Series(Close, 10 ); DataSeries maSlow_4 = EMAModern.Series(Close, 50 ); PlotSeries(PricePane,EMAModern.Series(Close, 50 ),Color.Red,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 200 ),Color.Green,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 10 ),Color.Blue,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 50 ),Color.Red,LineStyle.Solid, 2 ); PlotSeries(PricePane,EMAModern.Series(Close, 10 ),Color.Blue,LineStyle.Solid, 2 ); //for(int bar = GetTradingLoopStartBar(201); bar < Bars.Count; bar++) int bar = Bars.Count - 1 ; { if (IsLastPositionActive) { Position p = LastPosition; if (p.EntrySignal.Contains("Group1|" )) { if (CrossUnder(bar, maFast_3, maSlow_4)) { SellAtMarket(bar + 1 , p, "Group1" ); } } } else { if (maFast[bar] > maSlow[bar]) { if (maFast_1[bar] > maSlow_2[bar]) { if (Close[bar] < ma[bar]) { if (EarningsDate.InWindow( this , bar, "earnings per share" , 7 , 0 )) { BuyAtMarket(bar + 1 , "Group1|" ); } } } } } } } } }

September 29, 2021 · 1 min · Amer Khalid

Docker in 5 minutes

I have been using Docker and Kubernetes for several years now but never really took any time to really read about it. There were a lot of gaps in my understanding of how Docker works and what really is possible with it. Just recently my employer started to offer Udemy’s subscription, so I took Hands on Docker course. Here are some of the important things I learned in this course. Where do you run Docker containers You run these in Windows or MacOS but most likely you will use Linux in production. And unlike Windows and MacOS, you can run Docker on Linux VPS. ...

May 17, 2021 · 2 min · Amer Khalid

Json_error_ctrl_char

I was using mcrypt to encrypt json_encoded data. On other side, mycrypt was able to decrpyt data but json_decode was not working. It would throw JSON\_ERROR\_CTRL_CHAR error. However, without mcrypt, json_decode worked flawlessly. After some trial and error, I found that applying trim function after decrypting data would let me use json_decode without any issues.

May 10, 2021 · 1 min · Amer Khalid

Error Xcode Select Error Tool Xcodebuild Requires Xcode Active Developer Directory Command Line Tools Instance

Playing with Cordova, I was getting this error when building iOS version: Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory is a command line tools instance Even full install of Xcode didn’t fix this error. The solution was to run following command to use full Xcode instead of command line tools version that I had installed earlier: sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer

May 9, 2021 · 1 min · Amer Khalid

Setup Outgoing Email on Lightsail Ubuntu VPS

I followed instructions here: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-18-04 Everything seemed okay but email were not getting delivered. Logs showed me that smtp connections were timing out: tail -f /var/log/mail.log May 3 12:28:10 postfix/smtp[3160]: connect to gmail-smtp-in.l.google.com[172.217.197.27]:25: Connection timed out May 3 12:28:10 postfix/smtp[3160]: connect to alt1.gmail-smtp-in.l.google.com[2800:3f0:4003:c00::1a]:25: Network is unreachable May 3 12:28:40 postfix/smtp[3160]: 4984C41A1E: to=<xxxx@gmail.com>, relay=none, delay=3246, delays=3186/0.01/60/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.google.com[2a00:1450:400b:c00::1a]:25: Network is unreachable) However, I could ping any of above ip addresses just fine. ...

May 9, 2021 · 1 min · Amer Khalid

hsts Neterr_cert_common_name_invalid

Without full understanding, I had enabled HSTS on amerkhalid.com with option includeSubDomains. I had a subdomain that was used as “Custom Domain” to SmugMug site. After enabling HSTS, these subdomains started to throw NET::ERR_CERT_COMMON_NAME_INVALID. The fix is of course simple, don’t use includeSubDomains. But that opens up your top level domain to man in middle attacks. For now, I decided to follow the best practices and leave includeSubDomains enabled. And decided to not use custom domain for my SmugMug site. ...

May 8, 2021 · 1 min · Amer Khalid