I'm trying to create a bash script to automate a process that backups my WordPress blog (on a VPS) on my NAS. I always do it manually, but I'd like to just launch a command and let the thing do its work. What I do usually:
On the NAS
- ssh user@NAS-IP
- Enter password
- cd backupblog /* the directory I sync the backups to */
- rsync -avhP -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress user@VPS-IP:/blog/directory --exclude 'wp-content/cache' .
- Enter password for the VPS-IP user
Then, on the VPS
- ssh user@VPS-IP
- Enter password
- mysqldump -uDBuser -pDBpassword DBname > WP_blog-ddmmyyyy.sql
- exit
Then again on the NAS
- rsync -avhP -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress user@VPS-UP:/blog/directory/WP_blog-ddmmyyyy.sql .
- exit
I've seen I can automate ssh connections with expect but I think that's not the way to continue automating things via the script. Can you help?