Last active
May 9, 2017 20:16
-
-
Save ale10257/6ac15cd968f378a2931f0631f0dcd14b to your computer and use it in GitHub Desktop.
backup sites & DB whith sshfs
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/bash | |
DATE=`/bin/date '+%d.%m.%Y'` | |
DB_PASSWD=passwd | |
PREV_USER=prev_user | |
cp rsync_email_orig rsync_email | |
date >> rsync_email | |
echo "==============================================" >> rsync_email | |
while read line;do | |
IFS=";" | |
set -- $line | |
USER=$1 | |
if [ $PREV_USER != $USER ];then | |
MOUNT=yes | |
PREV_USER=$USER | |
else | |
MOUNT=no | |
fi | |
SITES=$2 | |
DB=$3 | |
DB_USER=$4 | |
if [ $MOUNT != 'no' ];then | |
fusermount -uz ~/sshfs/ > /dev/null | |
sshfs -p port -o reconnect $USER@ip-address:./public_html ~/sshfs | |
fi | |
FILE_NAME=~/backup/backup_"$SITES"_"$DATE".zip | |
cd ~/sshfs | |
ssh -p port $USER@ip-address "mysqldump -u$DB_USER -p$DB_PASSWD $DB" > $DB.sql < /dev/null | |
zip -r9 $FILE_NAME $SITES $DB.sql > /dev/null | |
rm ./$DB.sql | |
zip -T $FILE_NAME >> ~/rsync_email | |
echo "==============================================" >> ~/rsync_email | |
done < ~/user_list | |
fusermount -uz ~/sshfs/ > /dev/null | |
find ~/backup/ -mtime +4 -exec rm -f {} \; | |
find ~/backup/ -name backup_nerehtavet.ru* -exec mv -f {} ~/vet_backup/ \; | |
find ~/vet_backup/ -mtime +4 -exec rm -f {} \; | |
/usr/bin/ydcmd put --rsync ~/backup/ disk:/backup >> ~/rsync_email | |
/usr/sbin/ssmtp [email protected] < ~/rsync_email | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment