Last active
August 29, 2015 14:00
-
-
Save hongsw/11224491 to your computer and use it in GitHub Desktop.
wp add user and backup
This file contains hidden or 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 | |
_pwd="$(pwd)" | |
_home_path="$(pwd)" | |
_project_name=$1 | |
_DATABASE_NAME=`cat wp-config.php | grep DB_NAME | cut -d \' -f 4` | |
_DATABASE_USER=`cat wp-config.php | grep DB_USER | cut -d \' -f 4` | |
_DATABASE_PASSWORD=`cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4` | |
## output string | |
_files_target_str='wp_backup_'${_project_name}'.tgz' | |
_db_target_str=${_project_name}'_backup.sql' | |
## do something | |
echo "tar cvzf $_files_target_str ./*" | |
tar cvzf $_files_target_str ./* | |
echo "backup files! Done;" | |
echo "mysqldump" '-u'$_DATABASE_USER' -p'$_DATABASE_PASSWORD' '$_DATABASE_NAME' > '$_project_name'_backup.sql' | |
mysqldump -u$_DATABASE_USER -p$_DATABASE_PASSWORD $_DATABASE_NAME > $_db_target_str | |
echo "backup database! Done;" | |
#upload to sftp | |
HOST=$2 | |
PORT=22 | |
USER=$3 | |
PASSWORD=$4 | |
FILE=$_db_target_str | |
/usr/bin/expect<<EOD | |
spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST | |
expect "password:" | |
send "$PASSWORD\r" | |
expect "sftp>" | |
send "put $FILE\r" | |
expect "sftp>" | |
send "bye\r" | |
EOD | |
rm -f $FILE | |
FILE=$_files_target_str | |
/usr/bin/expect<<EOD | |
spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST | |
expect "password:" | |
send "$PASSWORD\r" | |
expect "sftp>" | |
send "put $FILE\r" | |
expect "sftp>" | |
send "bye\r" | |
EOD | |
rm -f $FILE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment