mawa85
Posts: 10
Joined: Mon Jan 23, 2012 12:14 pm

SD card copy station

Wed Jul 18, 2012 5:35 am

Hello,

I want to use my PI as an automated SD card copy station during my holidays.

In detail:
I want to stick my SDcard from my camera in a USB card reader and the rPI should automatically incremental copy the new images to a connected USB disk.

I want to go with a debian / raspbian distribution.

Could anyone hint me in the right direction in terms of what is needed to succeed so ?
I thought about rsync, but I'm not sure if there is a better solution.

CCitizenTO
Posts: 83
Joined: Sun May 20, 2012 2:14 am

Re: SD card copy station

Wed Jul 18, 2012 9:32 am

cp/mv would do the job ;)

All you need is a shell script to fire when you plug the stuff in.

If you were going to be able to connect to a TV and have a keyboard I'd say dispense with the need for all that and just use the command line to move things over.

mawa85
Posts: 10
Joined: Mon Jan 23, 2012 12:14 pm

Re: SD card copy station

Wed Jul 18, 2012 11:21 am

Hello,
thanks for your reply and your hints.

I don't want to connect mouse / keyboard or a TV.

I just found out that I can set udev rules to run scripts, thats probably the way to go.

I will give it a try.

Thanks.

obarthelemy
Posts: 1399
Joined: Tue Aug 09, 2011 10:53 pm

Re: SD card copy station

Wed Jul 18, 2012 11:52 am

Assuming
1- the pictures on your SD card are all in the same directory
2- have unique names, even if you delete your SD (ie, they're not all named pic00001, pic00002... on each and every new SD you put in)
3- are numerous and biggish, so you want to avoid re-copying already copied ones

I would

1- setup a shell script that
1a- checks if there's a card inserted, aborts if there is not, otherwise
1b- checks that the SD is a camera SD card (maybe you can name them different, or check the directory structure, or look for your pics' filename template...)
1b- runs rsync to copy the new pics, and only those, to your USB key

2- setup a cron job to run that script every 15s

In my experience, automatically copying stuff is very disaster-prone. A backup is off-line, so this doesn't really count as a backup until you've checked it, taken the stick out, and put it somewhere different and safe. You might at least want to make the copies read-only to be safer.

There might be an event raised when an SD card is inserted, but I've no clue how that works.

User avatar
rpdom
Posts: 14985
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SD card copy station

Wed Jul 18, 2012 1:38 pm

mawa85 wrote: I just found out that I can set udev rules to run scripts, thats probably the way to go.

I will give it a try.
That's what I do on my Debian laptop. When I connect my camera to a USB port a udev rule is triggered which runs a script using rsync to update a NFS share that my wife can access too :)

The udev rule uses the model number of the camera to trigger the script:
(in /etc/udev/rules.d/010-local-rules)
KERNEL=="sd*1",ATTRS{model}=="DMC-FZ7 ",RUN="/usr/local/bin/update_photos.sh"

Various useful shell variables are passed to the script, like ACTION (which should be "add"), ID_MODEL and DEVNAME.

Hope that helps a bit.

mawa85
Posts: 10
Joined: Mon Jan 23, 2012 12:14 pm

Re: SD card copy station

Fri Jul 20, 2012 5:41 am

Thanks froy all your help, I will hopefully have some time at the weekend to look into it :-)

mawa85
Posts: 10
Joined: Mon Jan 23, 2012 12:14 pm

Re: SD card copy station

Fri Jul 20, 2012 8:20 am

Maybe I can extend the project to add WiFi in hostapd and install Ajaxplorer to remotly copy and sort the images with my smartphone.

Return to “Networking and servers”