Scripting a mover + rsync combo


Recommended Posts

Hey everyone,

I'm fairly new to Unraid, and loving it. Today I'm working on a script that will do the following:

1) Run mover

2) Mount attached unassigned device by serial

3) Use Rsync to synchronize 2 folders to this unassigned device from 2 shares on my array

4) Unmount the unassigned device

 

I have what I believe is a solid solution for parts 2-4 (below), but I'm struggling with getting mover to run first. The reason I'm trying to merge these tasks instead of letting them run on separate schedules, is just to optimize spin-ups. If the disks are spun up to handle the move, I'd rather continue with the sync directly after, rather than spinning them up again an hour later to handle that. It's also partly just to challenge myself to write something.

Thanks.

(Also credit to user CS01-HS, whose code I borrowed for the mounting by serial trick.

#!/bin/bash

#RUN MOVER
#

#MOUNT DISK BY ID (PLUG IN YOUR DISK_ID)
DISK_ID=50_0123456789ABCDEF
THIS_DISK=`ls -l /dev/disk/by-id/ | grep '$DISK_ID' | head -1 | tail -c4`
/usr/local/sbin/rc.unassigned mount "/dev/$THIS_DISK"
if [[ $? -ne 0 ]]; then 
  echo "Exiting due to ERROR."
  exit 1
fi

#RUN SYNC COMMANDS
test -e "/mnt/disks/Mega" && rsync -avh --progress "/mnt/user/Mega/" "/mnt/disks/Mega/2D"
test -e "/mnt/disks/Mega" && rsync -avh --progress "/mnt/user/VR/" "/mnt/disks/Mega/VR"

#UNMOUNT DISK BY ID
/usr/local/sbin/rc.unassigned umount "/dev/$THIS_DISK"

 

Edited by stev067
Link to comment
1 hour ago, hugenbdd said:

I added two sections to mover tuning to run script before and/or after mover runs, plus it allows for a "test" mode. (Test at least for the mover part).

 

Else you can just start mover with the "start" argument.

Thanks. Running mover by percentage full will make for even fewer spin ups, and I didn't realize I could call scripts from this plugin.

Link to comment
2 hours ago, hugenbdd said:

I added two sections to mover tuning to run script before and/or after mover runs, plus it allows for a "test" mode. (Test at least for the mover part).

 

Else you can just start mover with the "start" argument.

 

Any tips on syntax for the before/after script fields? I'm entering this value below, but looking at syslog, it seems the spaces aren't welcome. And trying to add double or single quotes isn't helping. 

 

/boot/config/plugins/user.scripts/scripts/Sync to Raid-50

 

edit: sounds like it's unavoidable. I just renamed the script to have no spaces and hopefully that works.

Edited by stev067
  • Like 1
Link to comment
12 minutes ago, stev067 said:

 

Any tips on syntax for the before/after script fields? I'm entering this value below, but looking at syslog, it seems the spaces aren't welcome. And trying to add double or single quotes isn't helping. 

 

/boot/config/plugins/user.scripts/scripts/Sync to Raid-50

 

edit: sounds like it's unavoidable. I just renamed the script to have no spaces and hopefully that works.

Maybe put it in quotes, I didn't test it with spaces.  Generally if possible, you want to avoid spaces as much as possible in directory/file names.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.