Rancher script backup stack database

Hi,

I would like to set up a script that backup stacks rancher (the database in particular). For the moment, the script works manually, but not via the cron.

So I added lines “echo” to get an idea of ​​where the problem could come from :slight_smile:

I think (but I’m not sure) that it could come from my $ stacks line that the “echo” command does not show ^^

Here is the script with the “echo” commands

Do you have an idea ?

#! / Bin / bash

set -ex

TODAY = (date + "% Y-% m-% d") echo "TODAY value is: TODAY" > /home/backup/test.log
BACKUP_DIR = / mnt / lacinetek-backup / backup / TODAY echo "BACKUP_DIR value is: BACKUP_DIR" >> /home/backup/test.log
STACKS = (racks stacks ls | awk 'NR> 1 {print 2}’)
echo “STACKS value is: STACKS" >> /home/backup/test.log MYSQL_PASSWD = "AZTYPOURNVODPDZNZDnkn, of, ocofdfpdpf" echo "value of MYSQL_PASSWD is: MYSQL_PASSWD” >> /home/backup/test.log

export RANCHER_ENVIRONMENT = 987564412
export RANCHER_URL = https: //url.infraweb.local
export RANCHER_ACCESS_KEY = 1244899366545419646464
RANCHER_SECRET_KEY export = Azkngfjdnvcvl,icvlfgjnofjofnjofkpfbpf,bfonbf,obpb

for folder in database infra
do
if [! -d " BACKUP_DIR / folder"]; Then
echo “create folder BACKUP_DIR / folder” >> /home/backup/test.log
mkdir -p " BACKUP_DIR / folder"
fi
therefore

script --return --quiet --command “rancher exec -it site / db / bin / bash -c” export MYSQL_PWD = \ " {MYSQL_PASSWD} \"; mysqldump -uroot site 2> / dev / null '"\ | gzip -c9 > " BACKUP_DIR / db / site.sql.gz"

#echo ‘the command will be: script --return --quiet --command "rancher exec -it site / db / bin / bash -c’" ‘"’ export MYSQL_PWD = " {MYSQL_PASSWD} \ "; mysqldump - uroot site 2 > / dev / null '"'" '"\ | gzip -c9 > " BACKUP_DIR / db / site.sql.gz" ’ >> /home/backup/test.log

for stack in STACKS do rancher export -f " BACKUP_DIR / infra / stack.tar" stack
done

Best regards :slight_smile: