Cloud Sync Pre- and Post- script behavior & missing documentation

kiler129

Dabbler
Joined
Apr 16, 2016
Messages
22
I'm looking to add some external monitoring into the Cloud Sync tasks in TNS. However, I don't see any documentation regarding what scripts get, when they're executed (e.g. is post script called on error?).

I found https://www.truenas.com/docs/scale/scaleuireference/dataprotection/cloudsynctasksscreensscale/ where it says in the table "For advanced user. Enter a script to execute after running sync. See for more information." hinting at some more docs being available. Unfortunately "See for more..." is not linked anywhere.
 

dubya386

Cadet
Joined
Nov 22, 2023
Messages
1
I'm looking to add some external monitoring into the Cloud Sync tasks in TNS. However, I don't see any documentation regarding what scripts get, when they're executed (e.g. is post script called on error?).

I found https://www.truenas.com/docs/scale/scaleuireference/dataprotection/cloudsynctasksscreensscale/ where it says in the table "For advanced user. Enter a script to execute after running sync. See for more information." hinting at some more docs being available. Unfortunately "See for more..." is not linked anywhere.
Not sure if you've found your answer, but I did see that they've apparently fixed the page. It now links to this page here, which says that post-scripts only run after successful task completion: https://www.truenas.com/docs/scale/scaletutorials/dataprotection/cloudsynctasks/addcloudsynctasks/
 
Joined
Aug 11, 2021
Messages
8
Docs need some love!

Do I put the content of the script into the boxes? Or do I put the path to a script in the boxes?

For the next guy that googles, I was able to confirm that putting script content directly into the box works.

If you put this in the pre/post-script boxes:

```shell
#!/usr/bin/env bash

echo "this is a test, currently running as $(id)"
echo "here is env: $(env)"
echo "and we're out!"
```

You'll get output that looks like this:

```text
[Post-script] this is a test, currently running as uid=0(root) gid=0(wheel) groups=0(wheel)
[Post-script] here is env: CLOUD_SYNC_ENCRYPTION_PASSWORD=<yourValueHere>
[Post-script] IOCAGE_DEBUG=TRUE
[Post-script] CLOUD_SYNC_FILENAME_ENCRYPTION=0
[Post-script] CLOUD_SYNC_PATH=<yourValueHere>
... 15 more lines ...
[Post-script] CLOUD_SYNC_TRANSFER_MODE=MOVE
[Post-script] SHLVL=0
[Post-script] http_proxy=
[Post-script] MM_CHARSET=UTF-8
[Post-script] CLOUD_SYNC_PASS=<yourValueHere>
[Post-script] LC_ALL=en_US.UTF-8
[Post-script] PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
[Post-script] BLOCKSIZE=K
[Post-script] _=/usr/bin/env
[Post-script] and we're out!
```

**Note:** running as `root`! so you have almost no limits on where a longer script can be put. Presumably you can just put `./somePath/somePrePostScriptHere.sh` in the boxes if you need a script that's longer than what the boxes allow for.
 
Joined
Aug 11, 2021
Messages
8
And after a bit more testing, you can _also_ just put a path to a script in the box as well.

```text
/root/cloud-sync/do-stuff-post-sync.sh
```

as long as the +x bit is set on the script for `root`, the script will be run and the various `CLOUD_SYNC_*` vars will be set as expected.
 
Top