Last active
August 29, 2015 14:04
-
-
Save greenpeas/c8581e6b2ce1d810292b to your computer and use it in GitHub Desktop.
Резервное копирование нескольких БД
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DATE=`date +%Y-%m-%d_%H-%M-%S` | |
DIR=~/backups/ | |
DB_USER=root | |
DB_PASS='********' | |
DB_HOST=localhost | |
REMOTE_STORAGE_HOST=***.***.244.225 | |
REMOTE_STORAGE_USER=backups | |
KEY_PATH=~/.ssh/id_rsa | |
DATABASES="db1 db2 db3 db4" | |
for DB in $DATABASES ; | |
do | |
################################################################################################################### | |
mysqldump -u ${DB_USER} -h ${DB_HOST} -p${DB_PASS} --routines --single-transaction ${DB} | gzip -c > ${DIR}mysql_${DB}_${DATE}.gz | |
scp -B -i ${KEY_PATH} ${DIR}mysql_${DB}_${DATE}.gz ${REMOTE_STORAGE_USER}@${REMOTE_STORAGE_HOST}:~/${DB} | |
################################################################################################################### | |
# каталог (remote_host:~/${DB}) на удаленной машине должен быть создан заранее | |
done | |
find ${DIR} -name "*.gz" -mtime 30 -exec rm -f {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment