LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-19-2018, 01:40 PM   #1
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Rep: Reputation: Disabled
backup on a Pi without keyboard or monitor


I want to write a script in Bash that will automatically backup my RAW photos from an SD card to an external USB drive via a Raspberry Pi. I intend to use it when on holiday to backup photos without having to take my laptop with me.

What I'm attempting to do is power up the Pi, plug in my cameras SD card via a USB/SD card reader, then plug in a 320GB USB HD and then get the script to mount the SD card & HD then rsync files from the SD card to the HD.

I know how to mount both devices and do the rsync. However I'm unsure as how to get the Pi to correctly identify the SD card from the 320GB HD.

I guess that if I plug the SD card in first it will get mounted as sda1, then the second device, the HD, will mount as sda2? So I could cron a script to rsync from sda1 to sda2 every 5 mins. However this seems dangerous as it may copy in the wrong direction.

Is there a simple way to ensure it will always copy from the SD to the HD?

Man thanks for any help.
 
Old 03-19-2018, 02:08 PM   #2
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Entropy1024 View Post
I want to write a script in Bash that will automatically backup my RAW photos from an SD card to an external USB drive via a Raspberry Pi. I intend to use it when on holiday to backup photos without having to take my laptop with me.

What I'm attempting to do is power up the Pi, plug in my cameras SD card via a USB/SD card reader, then plug in a 320GB USB HD and then get the script to mount the SD card & HD then rsync files from the SD card to the HD.

I know how to mount both devices and do the rsync. However I'm unsure as how to get the Pi to correctly identify the SD card from the 320GB HD.

I guess that if I plug the SD card in first it will get mounted as sda1, then the second device, the HD, will mount as sda2? So I could cron a script to rsync from sda1 to sda2 every 5 mins. However this seems dangerous as it may copy in the wrong direction.

Is there a simple way to ensure it will always copy from the SD to the HD?

Man thanks for any help.
I found out that if I use the following:
Code:
lsblk -f -e 11 | grep EOS_DIGITAL
It returns
Code:
└─sda1      vfat   EOS_DIGITAL 1368-0838
So I can see that the Canon EOS_Digital SD card is on sda1. I now need to isolate that first part of the line. I thought I could awk the drive out of that line using:
Code:
lsblk -f -e 11 | grep EOS_DIGITAL | awk '{PRINT $1}'
However it returns nothing! Where am I going wrong?
 
Old 03-19-2018, 02:42 PM   #3
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,504

Rep: Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490Reputation: 2490
Quote:
I guess that if I plug the SD card in first it will get mounted as sda1, then the second device, the HD, will mount as sda2?
No, the second "device" would be sdb or sdc or something else, depending upon how many devices are attached. The sda is the device and sda1 is the partition on the device.
 
Old 03-19-2018, 02:48 PM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
use uuid's to identify the drives they dont change
 
1 members found this post helpful.
Old 03-19-2018, 02:55 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
[schneidz@hyper womens-health-challenge]$ lsblk -f -e 11 | awk '/swap/ {print $1}'
└─sda6
 
Old 03-19-2018, 03:22 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
One autonomous method would be to plug the drives into the Pi before you power it up. An @boot cron job would check to see if the both the card reader and drive was plugged and then copy the files.


Code:
lsblk -f -e 11 | grep EOS_DIGITAL | awk '{PRINT $1}'
Maybe a typo but PRINT should be print.
Code:
lsblk -f -e 11 | grep EOS_DIGITAL | awk 'print $1}'
 
1 members found this post helpful.
Old 03-19-2018, 03:25 PM   #7
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
Code:
[schneidz@hyper womens-health-challenge]$ lsblk -f -e 11 | awk '/swap/ {print $1}'
└─sda6
That still returns nothing for me. What does the swap do?
 
Old 03-19-2018, 03:34 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
awk will search for the string between the / /.

Code:
lsblk -l -f -e 11  awk '/EOS_DIGITAL/ {print $1}'

Last edited by michaelk; 03-19-2018 at 03:38 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Keyboard monitor iFunction Linux - Newbie 2 11-22-2015 04:22 AM
evtest for the keyboard to monitor ? patrick295767 Linux - General 1 05-21-2012 01:36 PM
How can I setup PC without monitor or keyboard bobwall Linux - Server 9 01-10-2010 03:55 PM
Monitor copying backup megerdin Linux - Server 2 07-04-2007 07:03 AM
Booting with no monitor no keyboard gillmanmac Linux - Hardware 24 03-06-2005 12:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration