Making a ros backup script for a cron job


#1

I’m trying to make a script that will manually backup my Realm Object Server (v2 free developer edition)
which i will then use to schedule using cron.

script - backup.sh

rm -rf backup
./node_modules/.bin/ros backup -f data -t backup

I run the script using this command

su -c ./backup.sh -s /bin/sh root

but I get the following error

/root/realm/node_modules/realm-object-server/dist/BasicServer.js:146
this.addServices(…params.services);
^^^

SyntaxError: Unexpected token …
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions…js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/root/realm/node_modules/realm-object-server/dist/cli.js:4:23)
at Module._compile (module.js:410:26)
at Object.Module._extensions…js (module.js:417:10)

Can anyone tell please what I’m doing wrong please?

Thanks.

Duane.


#2

@cybermosh What happens when you run the command manually - not in a bash script?

Also, we have run into issues when you run ROS and install it as root - can you try it with another user?


#3

@cybermosh I think it might be due to an older version of Node is being used when running ROS. You may need to nvm use v8.9.3 in your script to ensure that the appropriate version of Node is used.


#4

Thanks for the quick reply

If I just do the commands it works fine as shown below:

$ rm -rf backup
$ ros backup -f data -t backup
info: The data directory /root/realm/data was backed up in the directory /root/realm/backup.
24 Realms were successfully backed up

I also tried using a different user
$ su -c ./backup.sh -s /bin/sh moshy
and got the same error.

I’m very new to linux though. Do i need to put !#/bin/bash or some variant at the same of the script?

Same error with
nvm use v8.9.3
inside the script


#5

@cybermosh Yes you have to declare that the script is a bash script