# Backup date

today=$(date "+%Y_%m_%d-%H_%M_%S")

echo "Current date: $today"

# build up filename

# destination folder (change to your own needs)

BACKUP_FOLDER=/tmp

file_name=$BACKUP_FOLDER/bkup_vehiculos
new_name=$file_name-$today.sql
echo "Backup file name: " "$new_name"

kubectl --kubeconfig /home/creylopez/.kube/config -n vehiculos exec -ti deployment.apps/db -- /usr/lib/postgresql/15/bin/pg_dump --username=creylopez --dbname=vehiculos > $new_name

message="Backup stored "$today

sudo -u creylopez cat $new_name | mail -s "vehiculos  backup finished" "creylopez@yahoo.es"

sudo rm $new_name
