# Rancher script backup stack database

**URL:** https://forums.suse.com/t/rancher-script-backup-stack-database/12573
**Category:** General
**Created:** [December 4, 2018, 10:29am UTC](https://forums.suse.com/t/rancher-script-backup-stack-database/12573 "2018-12-04T10:29:42Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mattmurdock78](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mattmurdock78](https://forums.suse.com/u/mattmurdock78)
#### Post date: [December 4, 2018, 10:29am UTC](https://forums.suse.com/t/rancher-script-backup-stack-database/12573/1 "2018-12-04T10:29:42Z")

</div>

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 🙂

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](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&gt; / 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 🙂
