Windows can test in a similar way, if exist g:\NULNUL always exists on a drive, if its not there - the drive isnt.
On Saturday, August 11, 2012 3:59:45 PM UTC+1, Patrick J wrote:Andy,
Linux/unix shell scripts can do this for you very easily. If you're only familiar with Windows, these are text files with multiple command lines in them like .cmd or .bat files.
However, shell scripts are very adaptable and are what run a whole lot of the linux system behind the scenes.
Linux shell allows you to test for the presence of a file with something like "if -f /media/usb0". Something like that could spot your plugged in flash drive (I'm guessing at syntax/paths as I'm not near a linux login). Then it could execute "cp -R /media/usb0 /home/pi/backups/`date`/". The -R means that it would recursively copy every sub-directory and file. The date command would probably want some parameters to make it easy to read.
I think there is an additional flag you can use to create the new destination directory or you could just use a mkdir command to make the directory separately. If the if statement evaluates as false, simply put a wait statement for 2 seconds. Enclose these few lines in a never ending loop and run the program. You can add the shell program name into the init sequence so that it is always running.
Maybe 10 lines of shell to get this working.
Patrick
When the memory stick is plugged in it is by definition the latest version and so the rsync command line (or whatever you choose to use) should be written accordingly. The use of rsync is to reduce the amount of unnecessary copying, it's not meant to be some sort of magic - just read the man page and test your assumptions, and you can't go too far wrong.
Interesting backstory:BTW, be careful with rsync - a lot of people recommend --delete, but this can obviously be destructive. Also, don't just check the timestamp - there are a lot of cases where Windows apps don't update the modified date.