What's new

Solved Can someone do a simple guide to Rsync please

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

To make your cru commands persist through a router reboot you should put them in a services-start script.

It would be good practice to replace the verbose (v) parameter with quiet (q) because verbose is only meaningful when running rsync from the command line. So your commands for cron would be rsync -aq --delete ......
 
You can combine your cron syntex as "cru a 0 1,3,5,6 * * * command"

EDIT: Sorry @BreakingDad,I did not see that you have multiple command parameters. Ignore the above comment.

Also, you may need to enclose your actual rsync command in quotes to ensure all parameters get passed to rsync. That is way I usually perfer to build an independent script, then call the script via cron.

To Colin's point, you do understand that --delete will ensure a mirror copy of the source. Any files that you inadvertently place in the destination will get removed when rsync runs. It sounds like this is what you want, but I am making certain.

Yes thanks, am aware of the -delete command and it is what I want.
 
Will I lose the commands upon reboot ?

Thanks
 
You will, unless you place the cru commands in the /jffs/scripts/services-start script.
 
Will I lose the commands upon reboot ?

Thanks
To make your cru commands persist through a router reboot you should put them in a services-start script.

It would be good practice to replace the verbose (v) parameter with quiet (q) because verbose is only meaningful when running rsync from the command line. So your commands for cron would be rsync -aq --delete ......
 
shudder, im almost out of brain cells today
 
I managed it all by myself dad, winscp made it easy.

Thanks.

Hopefully all good, will test tonight.

Bored now, my choices are break something, or have a nap.
 
To make your cru commands persist through a router reboot you should put them in a services-start script.

It would be good practice to replace the verbose (v) parameter with quiet (q) because verbose is only meaningful when running rsync from the command line. So your commands for cron would be rsync -aq --delete ......
switch changed from v to q , so will replace on next reboot, thought this was less effort than editing all the crons.
 
@BreakingDad, your how-to-guide is expected right after you have tested all you've learned so far. :)
 
@BreakingDad, your how-to-guide is expected right after you have tested all you've learned so far. :)
I was thinking about doing that, my friend. When I know it's all up and running as expected. Hopefully that file will mysteriously disappear from my backup drive over night ;)

Right now I'm synching 3 hue bulbs to my screen and watching a light show however. I'm also planning a new 2 screen setup and desk with audio foam tiles, lights etc. I still need 2 hue plays for behind the screen but I have all the other stuff ready and delivered, just need a week off to do it as it involves a bit of hardboard to protect the walls from the foam panel chess board. Also got a dual monitor robot arm and a nice set of wheels for the pc to sit on :) I don't get out much ok. Except for work which I practically live at rn, good job really as it's paying for all this. The joys of being late 40s having barely any social life and a fully equiped house. Bit different from 20s when you have nothing and spend all your money on going out. TBH I'd rather be indoors doing this while wearing slippers though, real life is overrated. :)
 
Last edited:
You may find it useful to leave the verbose text included for a while (or forever) and redirect the output to a log file by adding something like
Code:
>logfilename 2>&1

When you really want to get "fancy", you can call a shell script from cron instead and process the log file to extract just the summary :) it would also allow you to have one script with a "for" loop that specifies the various directories you want to backup.

This is an example that I use the backup my raspberry pi (,overly complex for your needs, but an example if what can be done):
Code:
#!/bin/sh
#
# Rsync files from remote [RPi50]

# Check for and create a script flag
# to ensure only one script instance
FLAG="/tmp/rsync50.sh.run"
if [ -f "${FLAG}" ]; then
  exit
else
  echo "`date`" >"${FLAG}"
fi
HOST=`/bin/hostname`
SERIAL=`/bin/cat /proc/cpuinfo |grep Serial|cut -d' ' -f2 | /bin/sed -r s/00000000//g`
MODEL=`/bin/cat /sys/firmware/devicetree/base/model`
IPADD=`/bin/hostname -I | /bin/sed -r s/\ $//g`

# Redirect output to log file
exec >/root/rsync50.${SERIAL}.log 2>&1

echo "`date` Running script [${0}] on [${HOST}] IP Address [${IPADD}]"
echo "`date` System Type [${MODEL}] Serial Number [${SERIAL}]"

# Global Variables
SMNT="rsync://rsync@192.168.1.50:12000/root"
TLOG="/root/rsync50.${SERIAL}.detail.log"

# Create the password file and set permissions
PASS="/tmp/rsync_pass.txt"
echo "supersecret" >${PASS}
/bin/chmod 700 ${PASS}

for _f in "etc/automatic" "etc/apache2" "etc/samba"; do
  echo "`date` Checking source path [/${_f}/]"
  if [ -d "/${_f}" ]; then
    echo "`date` Rsyncing [${SMNT}/${_f}/] to [/${_f}/]"
    /usr/bin/rsync -av --update --stats --recursive --delete --password-file=${PASS} "${SMNT}/${_f}/" /${_f}/ >${TLOG} 2>&1
    if [ -f "${TLOG}" ]; then
      echo -n "`date` "
      if [ ! "`/bin/grep -i "Number of files:" ${TLOG}`" ]; then
        cat ${TLOG}
      else
        /bin/grep -i "Number of files:" ${TLOG}
        echo -n "`date` "
        /bin/grep -i "Number of regular files transferred:" ${TLOG}
        echo -n "`date` Number of files removed: "
        /bin/grep -c "deleting " ${TLOG}
      fi
      /bin/rm "${TLOG}"
    fi
  fi
done

# Remove the password file
if [ -f "${PASS}" ]; then
  /bin/rm "${PASS}"
fi

# Remove the script flag file
if [ -f "${FLAG}" ]; then
  /bin/rm "${FLAG}"
fi

if [ -f "/opt/vc/bin/vcgencmd" ]; then
  cpuTemp0=`/opt/vc/bin/vcgencmd measure_temp`
  cpuTemp0=`echo ${cpuTemp0} | /bin/sed -r s/\'/º/g`
  cpuTemp0=`echo ${cpuTemp0} | /bin/sed -r s/temp=//g`
  echo "`date` CPU Temp: ${cpuTemp0}"
fi

echo "`date``/usr/bin/uptime | /bin/sed -r s/\ \ /\ /g`"
echo "`date` `df -h | /bin/grep root | /bin/sed 's|\ \ |\ |g' | /bin/sed 's|\ \ |\ |g' | /bin/sed 's|\ \ |\ |g' | /bin/sed s:/$::g`"

/bin/sync
echo "`date` End of script [${0}] on [${HOST}]"

#EoF
Which outputs
Code:
Sun Feb 21 00:30:01 EST 2021 Running script [/root/rsync30.sh] on [RPi51] IP Address [192.168.1.51]
Sun Feb 21 00:30:01 EST 2021 System Type [Raspberry Pi 3 Model B Plus Rev 1.3] Serial Number [79736a62]
Sun Feb 21 00:30:01 EST 2021 Checking source path [/boot/]
Sun Feb 21 00:30:01 EST 2021 Rsyncing [/boot/] to [rsync@192.168.1.30::Public/Raspberry Pi 3 Model B Plus Rev 1.3 79736a62/boot/]
Sun Feb 21 00:30:25 EST 2021 Number of files: 259 (reg: 256, dir: 3)
Sun Feb 21 00:30:25 EST 2021 Number of regular files transferred: 0
Sun Feb 21 00:30:25 EST 2021 Number of files removed: 0
Sun Feb 21 00:30:25 EST 2021 Checking source path [/etc/]
Sun Feb 21 00:30:25 EST 2021 Rsyncing [/etc/] to [rsync@192.168.1.30::Public/Raspberry Pi 3 Model B Plus Rev 1.3 79736a62/etc/]
Sun Feb 21 00:30:26 EST 2021 Number of files: 1,339 (reg: 542, dir: 176, link: 621)
Sun Feb 21 00:30:26 EST 2021 Number of regular files transferred: 10
Sun Feb 21 00:30:26 EST 2021 Number of files removed: 0
Sun Feb 21 00:30:26 EST 2021 Checking source path [/home/]
Sun Feb 21 00:30:26 EST 2021 Rsyncing [/home/] to [rsync@192.168.1.30::Public/Raspberry Pi 3 Model B Plus Rev 1.3 79736a62/home/]
Sun Feb 21 00:30:27 EST 2021 Number of files: 8 (reg: 4, dir: 4)
Sun Feb 21 00:30:27 EST 2021 Number of regular files transferred: 0
Sun Feb 21 00:30:27 EST 2021 Number of files removed: 0
Sun Feb 21 00:30:27 EST 2021 Checking source path [/root/]
Sun Feb 21 00:30:27 EST 2021 Rsyncing [/root/] to [rsync@192.168.1.30::Public/Raspberry Pi 3 Model B Plus Rev 1.3 79736a62/root/]
Sun Feb 21 00:30:27 EST 2021 Number of files: 212 (reg: 195, dir: 17)
Sun Feb 21 00:30:27 EST 2021 Number of regular files transferred: 10
Sun Feb 21 00:30:27 EST 2021 Number of files removed: 0
Sun Feb 21 00:30:27 EST 2021 Checking source path [/var/backups/]
Sun Feb 21 00:30:27 EST 2021 Rsyncing [/var/backups/] to [rsync@192.168.1.30::Public/Raspberry Pi 3 Model B Plus Rev 1.3 79736a62/var/backups/]
Sun Feb 21 00:30:28 EST 2021 Number of files: 38 (reg: 37, dir: 1)
Sun Feb 21 00:30:28 EST 2021 Number of regular files transferred: 0
Sun Feb 21 00:30:28 EST 2021 Number of files removed: 0
Sun Feb 21 00:30:28 EST 2021 Checking source path [/var/log/]
Sun Feb 21 00:30:28 EST 2021 Rsyncing [/var/log/] to [rsync@192.168.1.30::Public/Raspberry Pi 3 Model B Plus Rev 1.3 79736a62/var/log/]
Sun Feb 21 00:30:29 EST 2021 Number of files: 71 (reg: 64, dir: 7)
Sun Feb 21 00:30:29 EST 2021 Number of regular files transferred: 52
Sun Feb 21 00:30:29 EST 2021 Number of files removed: 0
Sun Feb 21 00:30:30 EST 2021 CPU Temp: 53.7ºC
Sun Feb 21 00:30:30 EST 2021 00:30:30 up 15 min, 0 users, load average: 0.08, 0.04, 0.04
Sun Feb 21 00:30:30 EST 2021 /dev/root 7.0G 3.1G 3.6G 47%
Sun Feb 21 00:30:30 EST 2021 End of script [/root/rsync30.sh] on [RPi51]
 
I am relieved and pleased to report that everything worked as expected over night.

Thank you everyone for the help. Noobie guide to basic rsync to follow for others in due course.
 
I am relieved and pleased to report that everything worked as expected over night.
It would still be a good idea to enable the logging so that can actually look and see exactly what did or did not happen during the rsync session. Even overwriting the log daily is better than the wait and guess option :)
 
Similar threads

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top