Skip to content

Instantly share code, notes, and snippets.

@ale10257
Last active May 9, 2017 20:16
Show Gist options
  • Save ale10257/6ac15cd968f378a2931f0631f0dcd14b to your computer and use it in GitHub Desktop.
Save ale10257/6ac15cd968f378a2931f0631f0dcd14b to your computer and use it in GitHub Desktop.
backup sites & DB whith sshfs
#!/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