Bash script to automate snap backup


I currently manually backup my snap following

I can run a cron nightly to create this backup, but I’d like to automate all of it with a bash script so as to be able to rsync or scp to a remote server. Essentially covering this:

  1. Script stops the server then runs: snap run rocketchat-server.backupdb
  2. Script takes the command’s output A backup of your data can be found at/var/snap/rocketchat-server/xxxx/backup.tgz” as source for the scp.
  3. scp executed
  4. script starts server again.

I can do 1, 3 and 4, but unsure of how to handle 2) section. Also is it really necessary to stop the server running, or is this just extra safety to avoid database corruption?


Please, did the backup directory changes every time?
If so you can use a pipe and select the backup file and it path from the message.

I don’t know commands for the selection yet.