Running command on VPS without SSH

This is mostly linux question, however using it with nextcloud so trying to check here first.
Goal is: create automated backup with Backup — Nextcloud latest Administration Manual latest documentation

I need to enable maintenance mode, create mysql dump and disable maintenance mode programmatically.

Can I do following in cron (on local machine):
ssh to VPS; maintenance mode on; create mysql dump; exit; rsync nc directory; rsync mysql dump; ssh to VPS; maintenance mode off

I also need to figure out how cron will access ssh key-pair
If this is good I can just put these commands in bash script and run script instead (through cron)

Thanks

Checkout your config.php, there is a variable maintenance or maintenance mode, you can set this to True. Try to access your Nextcloud via browser, it should show you that it is in maintenance mode. Then you can work on your database.

I’m sorry, I don’t understand how this will help. Can you please elaborate some more?

I know how to put NC in maintenance mode, I also know how to take mysql dump.
My question is more related to Linux than NC, just wondering if someone here already went through similar scenario.

I want to automate backups to local machine.
I want to write crontab on local machine (not on machine hosting NC)
and I’m asking if crontab can perform ssh followed by terminal commands.

On other hand I may just try it and see if it works.

you can set up to access your server via ssh-key (on your backup machine you create a ssh-key-pair, you load the public key in the ~.ssh/authorized-keys file of the user as you wish to login). On your backup machine, you can set up a .ssh/config to specify the key for the server:
https://www.cyberciti.biz/faq/how-to-set-up-ssh-keys-on-linux-unix/

Then you can easily run commands remotely: https://www.cyberciti.biz/faq/unix-linux-execute-command-using-ssh/

database dump

i think you must create a cron job on the nextcloud server.

backup "data and mysql dump"
Cron on your nextcloud server can backup to a backup server or a backup server get get “data and mysql dump” from the nextcloud server. In this part you do not need nextcloud maintenance mode anymore. Only in this part you need e.g. ssh/sftp.