Backing Up Photos While Traveling – Components
Introduction
I have been looking for an ideal way to back up photos while traveling for a long time. Putting an SD card in your camera bag exposes you to too many risks: the SD card could get lost or stolen, data could get corrupted or fail during transfer. A better option is to copy it to another medium, even if it is also an SD card, and put it in a safer place. Backing up remotely is also a feasible option, but it is not practical if you go to a place without internet access.
My ideal backup steps require the following tools:
-
Using an iPad Pro instead of a laptop. I prefer to travel light, and most of my trips are business-related (rather than leisure photography). I hate carrying a personal laptop while also needing to bring a business one. My iPad has always been with me, which is why I chose it.
-
Using as few hardware devices as possible.
-
The connection between devices needs to be very secure. I need to use this setup in hotels and airports, so the connection between devices needs to be closed and encrypted.
-
The whole process should be reliable and stable. I have used other routers/combo devices, but the results were not ideal[1].
Devices
I configured a setup that meets the above conditions and can be expanded in the future. It includes the following components:
-
9.7-inch iPad Pro[2], which is the most powerful and lightweight iOS device at the time of writing this article. An Apple Pencil is not necessary, but as one of the components, I can do some editing work on the go, while the heavy lifting is done by the Raspberry Pi, and other devices can just connect via SSH.
-
Raspberry Pi 3 with Raspbian OS installed[3] (LCTT translation note: Raspbian is the Raspberry Pi operating system based on Debian).
-
Raspberry Pi’s Mini SD card[4] and box/case[5].
-
128G USB flash drive[6], which is enough for me; you can buy a larger one. You can also buy an external hard drive like this[7], but the Raspberry Pi cannot provide enough power to the external hard drive via USB, which means you need to prepare an external USB hub[8] and cables, which defeats the purpose of keeping the devices lightweight.
-
SD card reader[9]
-
Another SD card[10], I will use several SD cards, and will immediately switch to another one before filling it up, so that my photos during a trip are spread across different SD cards.
The image below shows how these devices are interconnected.
Photo Backup While Traveling – Flowchart
The Raspberry Pi will act as a secure hotspot. It will create its own WPA2 encrypted WIFI network, which the iPad Pro will connect to. Although there are many online tutorials that teach you how to create an Ad Hoc network (a computer-to-computer peer-to-peer network), it is simpler but not encrypted, and attached devices can easily connect. Therefore, I chose to create a WIFI network.
The camera’s SD card is inserted into one of the Raspberry Pi’s USB ports via the SD card reader, and the 128G USB flash drive is continuously plugged into another USB port on the Raspberry Pi. I chose a SanDisk[11] because it is compact. The main idea is to use a Python script to back up the photos from the SD card to the USB drive. The backup process is incremental, meaning that only the changed parts (such as newly taken photos) will be added to the backup folder each time the script runs, making this process particularly fast. If you have a lot of photos or have taken many RAW format photos, this is a huge advantage. The iPad will be used to run the Python script and browse the files on the SD card and USB drive.
As an added benefit, if you connect the Raspberry Pi to an internet-capable Ethernet cable (for example, through the Ethernet port), it can share the internet connection with devices connected via WIFI.
1. Setting Up the Raspberry Pi
This part requires you to roll up your sleeves and do it yourself. We will use the command line mode of Raspbian, and I will introduce it as detailed as possible to help you proceed.
Installing and Configuring Raspbian
Connect a mouse, keyboard, and LCD display to the Raspberry Pi, insert the SD card into the Raspberry Pi, and follow the steps on the Raspberry Pi official website[12] to install Raspbian.
Once installed, open the Raspbian terminal and execute the following commands:
sudo apt-get update
sudo apt-get upgrade
This will upgrade all software on the machine to the latest version. I connected the Raspberry Pi to the local network and changed the default password for security.
SSH is enabled by default in Raspbian, so all settings can be done on a remote device. I also set up RSA authentication, which is optional and you can find more information here[13].
This is a screenshot of establishing an SSH connection to the Raspberry Pi on a Mac using iTerm[14]. (LCTT translation note: the original image is missing.)
Establishing WPA2 Encrypted WIFI AP
The installation process is based on this article[16], adjusted according to my situation.
1. Install Packages
We need to install the following packages:
sudo apt-get install hostapd
sudo apt-get install dnsmasq
hostapd is used to create an AP using the built-in WiFi, and dnsmasq is a combined DHCP and DNS service that is easy to set up.
2. Edit dhcpcd.conf
Connect the Raspberry Pi via Ethernet. The network interface configuration on the Raspberry Pi is controlled by dhcpd
, so we will first ignore this and set wlan0
to a static IP.
Open the dhcpcd configuration file using sudo nano /etc/dhcpcd.conf
and add the following content at the end:
denyinterfaces wlan0
Note: It must be placed above any existing interface lines.
3. Edit Interfaces
Now set a static IP by opening the interface configuration file with sudo nano /etc/network/interfaces
and editing the wlan0
section as follows:
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Similarly, edit wlan1
as follows:
#allow-hotplug wlan1
#iface wlan1 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Important: Restart the dhcpd
service using sudo service dhcpcd restart
, and reload the configuration of wlan0
using sudo ifdown eth0; sudo ifup wlan0
.
4. Configure Hostapd
Next, we need to configure hostapd. Create a new configuration file using sudo nano /etc/hostapd/hostapd.conf
, and the content should be as follows:
interface=wlan0
# Use the nl80211 driver with the brcmfmac driver
driver=nl80211
# This is the name of the network
ssid=YOUR_NETWORK_NAME_HERE
# Use the 2.4GHz band
hw_mode=g
# Use channel 6
channel=6
# Enable 802.11n
ieee80211n=1
# Enable QoS Support
wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# Accept all MAC addresses
macaddr_acl=0
# Use WPA authentication
auth_algs=1
# Require clients to know the network name
ignore_broadcast_ssid=0
# Use WPA2
wpa=2
# Use a pre-shared key
wpa_key_mgmt=WPA-PSK
# The network passphrase
wpa_passphrase=YOUR_NEW_WIFI_PASSWORD_HERE
# Use AES, instead of TKIP
rsn_pairwise=CCMP
After configuring, we need to tell dhcpcd
where to find the configuration file at system startup. Open the default configuration file with sudo nano /etc/default/hostapd
and find #DAEMON_CONF=""
and replace it with DAEMON_CONF="/etc/hostapd/hostapd.conf"
.
5. Configure Dnsmasq
The default dnsmasq configuration file contains a lot of information that is convenient for you to use, but we do not need so many options. I recommend moving it elsewhere (instead of deleting it) and creating a new file:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
Paste the following information into the new file:
interface=wlan0 # Use interface wlan0
listen-address=192.168.1.1 # Explicitly specify the address to listen on
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=192.168.1.50,192.168.1.100,12h # Assign IP addresses in that range with a 12 hour lease time
6. Set Up IPv4 Forwarding
The last thing we need to do is configure packet forwarding. Open the sysctl.conf
file with sudo nano /etc/sysctl.conf
, and remove the # before the line containing net.ipv4.ip_forward=1
, which will take effect on the next reboot.
We also need to share the internet connection with devices connected to the Raspberry Pi via WIFI, creating a NAT between wlan0
and eth0
. We can refer to the script below to achieve this.
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
I named this script hotspot-boot.sh
and made it executable:
sudo chmod 755 hotspot-boot.sh
This script should run when the Raspberry Pi starts. There are many ways to achieve this; here is how I implemented it:
-
Place the file in the
/home/pi/scripts
directory. -
Enter
sudo nano /etc/rc.local
to edit therc.local
file and place the command to run the script beforeexit 0
. (For more information, refer here[17]).
After editing, rc.local
looks like this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
sudo /home/pi/scripts/hotspot-boot.sh &
exit 0
Installing Samba Service and NTFS Compatible Driver
We need to install the following software to enable samba protocol, allowing the file browser[18] to access the folders shared by the Raspberry Pi, and ntfs-3g
will allow us to access files in the NTFS file system on external hard drives.
sudo apt-get install ntfs-3g
sudo apt-get install samba samba-common-bin
You can refer to these documents[19] to configure Samba.
Important Note: The referenced document describes mounting an external hard drive to the Raspberry Pi, which we will not do, as at the time of writing this article, the Raspberry Pi’s auto-mount function mounts both the SD card and USB drive to /media/pi/
on startup. We will not adopt some of the extra features in that article.
2. Python Script
Once the Raspberry Pi is set up, we need to develop a script to actually copy and back up the photos. Note that this script only provides a specific automated backup process. If you have basic Linux/Raspberry Pi command line skills, you can SSH into the Raspberry Pi, create the necessary folders, and use cp
or rsync
commands to copy your own photos from one device to another. In the script, we use the rsync
command, which is reliable and supports incremental backups.
This process relies on two files: the script file itself and the backup_photos.conf
configuration file, which contains a few lines specifying the mounted destination drive (USB drive) and the directory it should be mounted to. It looks like this:
mount folder=/media/pi/
destination folder=PDRIVE128GB
Important Note: Do not add extra spaces before or after the symbol =
, or the script will fail.
Below is the Python script, which I named backup_photos.py
, and placed it in the /home/pi/scripts/
directory. I have commented each line for easy reference.
#!/usr/bin/python3
import os
import sys
from sh import rsync
'''
This script copies the contents of the SD card mounted at /media/pi to the destination disk in the same directory,
with the destination disk name defined in the .conf file.
Argument: label/name of the mounted SD Card.
'''
CONFIG_FILE = '/home/pi/scripts/backup_photos.conf'
ORIGIN_DEV = sys.argv[1]
def create_folder(path):
print ('attempting to create destination folder: ',path)
if not os.path.exists(path):
try:
os.mkdir(path)
print ('Folder created.')
except:
print ('Folder could not be created. Stopping.')
return
else:
print ('Folder already in path. Using that instead.')
confFile = open(CONFIG_FILE,'rU')
#Important: The rU option opens the file in universal newline mode,
#so
and/or
are recognized as a new line.
confList = confFile.readlines()
confFile.close()
for line in confList:
line = line.strip('\n')
try:
name , value = line.split('=')
if name == 'mount folder':
mountFolder = value
elif name == 'destination folder':
destDevice = value
except ValueError:
print ('Incorrect line format. Passing.')
pass
destFolder = mountFolder+destDevice+'/'+ORIGIN_DEV
create_folder(destFolder)
print ('Copying files...')
# Uncomment this line to delete files not in the source
# rsync("-av", "--delete", mountFolder+ORIGIN_DEV, destFolder)
rsync("-av", mountFolder+ORIGIN_DEV+'/', destFolder)
print ('Done.')
3. Configuring the iPad Pro
Since the heavy lifting is done by the Raspberry Pi, files are not transferred through the iPad Pro, which is a huge advantage compared to a previous solution I tried[20]. We only need to install Prompt2[21] on the iPad to connect to the Raspberry Pi via SSH, allowing you to run the Python script and manually copy files.
Connecting to Raspberry Pi via SSH on iPad using Prompt2
Since we installed Samba, we can access the USB devices connected to the Raspberry Pi in a more graphical way. You can watch the video to copy and move files between different devices, and the file browser[22] is perfect for this purpose. (LCTT translation note: the original video is missing.)
4. Putting It All Together
We assume that SD32GB-03
is the label of the SD card connected to one of the Raspberry Pi’s USB ports, and PDRIVE128GB
is the label of the USB drive, also connected to the device and defined in the configuration file mentioned above. If we want to back up the photos on the SD card, we need to do the following:
-
Power on the Raspberry Pi and ensure the drives are automatically mounted.
-
Connect to the configured WIFI network on the Raspberry Pi.
-
Use the Prompt2[23] app to connect to the Raspberry Pi via SSH.
-
Once connected, enter the following command:
python3 backup_photos.py SD32GB-03
The first backup will take some time, depending on how much capacity your SD card has used. This means you need to keep the Raspberry Pi and iPad connected. You can solve this before running the script using the nohup
command:
nohup python3 backup_photos.py SD32GB-03 &
Running the completed script as shown
Future Customization
I installed vnc service on the Raspberry Pi so that I can connect to the graphical interface of the Raspberry Pi from other computers or on my iPad using the Remoter App[24]. I installed BitTorrent Sync[25] for remote backup of my photos, which obviously needs to be set up first. Once I have a working solution, I will add to my article.
You can leave your comments and questions below, and I will respond at the bottom of this page.
via: http://www.movingelectrons.net/blog/2016/06/26/backup-photos-while-traveling-with-a-raspberry-pi.html
Author: Lenin[26] Translator: jiajia9linuxer Proofreader: wxy
This article is originally compiled by LCTT[27] and honorably published by Linux China.
[1]: http://bit.ly/1MVVtZi[2]: http://www.amazon.com/dp/B01D3NZIMA/?tag=movinelect0e-20[3]: http://www.amazon.com/dp/B01CD5VC92/?tag=movinelect0e-20[4]: http://www.amazon.com/dp/B010Q57T02/?tag=movinelect0e-20[5]: http://www.amazon.com/dp/B01F1PSFY6/?tag=movinelect0e-20[6]: http://amzn.to/293kPqX[7]: http://amzn.to/290syFY[8]: http://amzn.to/290syFY[9]: http://amzn.to/290syFY[10]: http://amzn.to/290syFY[11]: http://amzn.to/293kPqX[12]: https://www.raspberrypi.org/downloads/noobs/[13]: https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md[14]: https://www.iterm2.com/[15]: https://www.iterm2.com/[16]: https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/[17]: https://www.raspberrypi.org/documentation/linux/usage/rc-local.md[18]: https://itunes.apple.com/us/app/filebrowser-access-files-on/id364738545?mt=8&uo=4&at=11lqkH[19]: http://www.howtogeek.com/139433/how-to-turn-a-raspberry-pi-into-a-low-power-network-storage-device/[20]: http://bit.ly/1MVVtZi[21]: https://itunes.apple.com/us/app/prompt-2/id917437289?mt=8&uo=4&at=11lqkH[22]: https://itunes.apple.com/us/app/filebrowser-access-files-on/id364738545?mt=8&uo=4&at=11lqkH[23]: https://itunes.apple.com/us/app/prompt-2/id917437289?mt=8&uo=4&at=11lqkH[24]: https://itunes.apple.com/us/app/remoter-pro-vnc-ssh-rdp/id519768191?mt=8&uo=4&at=11lqkH[25]: https://getsync.com/[26]: http://www.movingelectrons.net/blog/2016/06/26/backup-photos-while-traveling-with-a-raspberry-pi.html[27]: https://github.com/LCTT/TranslateProject
Recommended Articles
Click the title or enter the article ID to go directly to the article |
---|
3985 5 Raspberry Pi Projects Perfect for Classroom Demonstration |
4160 Open Source News: RaspAnd Distribution Can Turn Raspberry Pi 3 Into a Complete Android Computer |
4218 Securi-Pi: Using Raspberry Pi as a Security Jump Point |
Sharing this article with friends is the best compliment!