0

Hello Unix and Linux Lovers!

I have spent now about 2 days looking for a solution of my problem but couldn't find a fitting one; I like to back up files to any usb stick which is connected on a raspberry pi running raspbian.

I write here things I know, so you see what is missing:

  1. Using rsync will be the best for my purpose, this should work;

    rsync -v /home/pi/data /mnt/usb

  2. I can add the Job in crontab;

    crontab -e

    0 0 * * * rsync -v /home/pi/data /mnt/usb

This will back up my data every day (the 5 first signs are for the time Settings: Minutes Hours Days Months DayOfTheWeek, then Comes the command or script which should be executed).

  1. I can manually Mount a USB Stick like this:

    sudo mount -t vfat /dev/sda1 /mnt/usb

But what is missing:

  • How can I mount automatically every usb stick, which is plugged in, in the Directory /mnt/usb (or /mnt/usb1, /mnt/usb2 etc)?

  • How can I use rsync to sync the data in every Folder path? Do I Need a Shell script with a Loop or can I use it like this: rsync -v /home/pi/data /mnt/usb*?

Thanks in Advance for help, Kind Regards

  • Is udevd running on Raspbian? – Arkadiusz Drabczyk Oct 6 '15 at 14:04
  • Yes, I can acces the udevd Manual, so it is accessible – Sider Oct 6 '15 at 14:25
  • if Raspbian is a well designed system it's probably the case but in a wider perspective availability of a particular manpage does not imply availability of the given tool. Anyway, if udevd is running you can create a rule for automatic mounting of USB storage in a given directory and with a given set of options like this: axllent.org/docs/view/auto-mounting-usb-storage – Arkadiusz Drabczyk Oct 6 '15 at 14:32
  • Yes of course an existence of the manual doesn't say that the command is accessible. I just assumed that the widely spread raspbian is programmed well enough that only the needed manuals are there. Thanks, Auto mounting works with this tutorial, never thought on such a deep Level solution, just has worked. Linux is so great. – Sider Oct 7 '15 at 12:21
0

I was now able to do it

use the tutorial which Arkadiusz Drabczyk posted: http://www.axllent.org/docs/view/auto-mounting-usb-storage/

make a short script, which seeks for all Folders beginning with usbhd in the media folder and sync to them. Use "-rtuv" for Windows fat formats, they don't support POISX semantic. This all leads to this script:

sudo find /media -maxdepth 1 -name "usbhd*" | awk '
{
    cmd = "rsync -rtuv --exclude '\''.*'\'' /home/pi/test "$0
    system(cmd)
}' > /dev/null 2>&1

Add a line to crontab, that the script is called regularly. Call: crontab -e Add line (calls script every hr):

0 * * * * . /scriptpath/myscript.awk

And thats it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.