D
D
Denis2016-06-17 22:28:38
MySQL
Denis, 2016-06-17 22:28:38

How to change the backup mysql script to Yandex.Disk?

In the question , mureevms suggested a script to backup the database to YandexDisk.
I need to make the backups of different databases be separate files.
Suggested script:

#!/bin/sh
TIME=`date +%Y-%m-%d`
# Логин пользователя мускула
USER=root
# Пароль пользователя мускула
PASS=root_password
WHERE=/home/backup/mysql
COPY=/mnt/yadisk/mysql
### Базы которые надо бэкапить
for base in base_name1 base_name2
do
# Сделать дамп баз
mysqldump -u$USER -p$PASS -B $base > $WHERE/$base-$TIME.sql
done
cp $WHERE/$base-$TIME.sql $COPY
find $WHERE -mtime +1 -print -delete
find $COPY -mtime +30 -print -delete

works almost as it should for me, except that both base_name1 base_name2 dumps are created in the /home/backup/mysql folder , but only one dump is copied to the /mnt/yadisk/mysql folder, as I understand it, which was the first one created. I feel that it is necessary either to make some kind of delay, or the script copies only one dump and you need to add something like a cycle so that everything copies in turn. In the future I will need to backup 5 dumps so that they are all separate files. Please tell me how to fix the script.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
strelmax, 2016-06-17
@Rentable

Move cp $WHERE/$base-$TIME.sql $COPY inside for, i.e. do this:
for base in base_name1 base_name2
do
mysqldump -u$USER -p$PASS -B $base > $WHERE/$base- $TIME.sql
cp $WHERE/$base-$TIME.sql $COPY
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question