rivernews / iriversland2-api

My personal website's backend code base.
https://api.shaungc.com
0 stars 0 forks source link

Create Cron Jobs for Backing Up Database Periodically #14

Closed rivernews closed 5 years ago

rivernews commented 5 years ago

Seems like the K8 cron job is not working, because doesn't receive admin email.

rivernews commented 5 years ago

For future reference:

If you want to migrate to an database that already has some data in it (it's like a restore):

If you are migrating to a brand new database:

Some useful K8 commands for debugging cron jobs

# Example: get the pods running the job `db-backup-cronjob-1566709740`
. ./my-kubectl.sh get pods --selector=job-name=db-backup-cronjob-1566709740 -n cicd-django

. ./my-kubectl.sh get jobs

# You can also grep to get cron job pods
. ./my-kubectl.sh get pods --all-namespaces | grep cron

# Or try combo to get the pod
job_name="$(. ./my-kubectl.sh get jobs | grep --max-count 1 cronjob | awk '{print $1;}')"
echo "job name is ${job_name}"
. ./my-kubectl.sh get pods --all-namespaces --selector=job-name=${job_name} 
# pods=$(. ./my-kubectl.sh get pods --selector=job-name=${job_name} --output=jsonpath={.items[].metadata.name})

# Get the log
 . ./my-kubectl.sh logs $pods

# Directly by the name
 . ./my-kubectl.sh get jobs
 . ./my-kubectl.sh logs jobs/<the job name you see>