0

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

  1. ssh user@NAS-IP
  2. Enter password
  3. cd backupblog /* the directory I sync the backups to */
  4. rsync -avhP -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress user@VPS-IP:/blog/directory --exclude 'wp-content/cache' .
  5. Enter password for the VPS-IP user

Then, on the VPS

  1. ssh user@VPS-IP
  2. Enter password
  3. mysqldump -uDBuser -pDBpassword DBname > WP_blog-ddmmyyyy.sql
  4. exit

Then again on the NAS

  1. rsync -avhP -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress user@VPS-UP:/blog/directory/WP_blog-ddmmyyyy.sql .
  2. 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?

javipas
  • 1,332
  • 3
  • 23
  • 38
  • Conceptually: **1.** use **ssh keys** (without passwords) for authentication to prevent getting asked for passwords. (For extra security and credit: Make use of the options section in ˜/.ssh/authorized_keys` files to impose limits on what is allowed with that passwordless key.) **2.** make use of the fact that you can remotely trigger a script/command over ssh with `ssh user@host command-or-script` – Rob Jul 25 '22 at 14:01
  • I can explore that, thank you. – javipas Jul 27 '22 at 06:47

0 Answers0