# 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_jugaralpadel
new_name=$file_name-$today.sql
echo "Backup file name: " "$new_name"

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

message="Backup stored "$today

#sudo -u creylopez cat $new_name | mail -s "Jugar al Pádel  backup finished" "creylopez@yahoo.es"
sudo -u creylopez echo "Jugaralpadel backup adjunto" |mail -s "Backup de jugaralpadel" creylopez@yahoo.es -A $new_name

#sudo rm $new_name
