Blog

July 06, 2013 | Raspberry Pi |

Backing up your Raspberry Pi code using rsync

This is how I develop code on my Raspberry Pi:

ssh into the Pi from my Macbook Pro from 2 Terminals, and use emacs on one to edit the code, while I run the code from the other. This way I don't need to use the annoyingly slow X-server or VNC solutions to display UI from the PI for editing.

Installing emacs on the Pi is exceedingly simple, by the way:

sudo apt-get install emacs

There are other editors, but really nothing beats emacs or vi when it comes to editing code on Linux, and I highly recommend that you spend some time learning one of these editors.

Since I develop code on the Pi directly, I need a backup plan, and the plan is rsync.

rsync is a Unix utility that can synchronyze your files between directories and other machines (via ssh).

rsync is very powerful, and not to be meddled with unless you are paying attention. If you are mucking around it with it, (a) back up your test files and (b) use the -n or "dry run" flag so it only tells you what will be done and not actually do it, till you are satisfied.

Here is my script to back up my code directory (recursively) from the Raspberry Pi on to my Macbook:

Here is a typical run:

$./bkup-pi.sh
Backing up RPi #1...
pi@192.168.4.31's password:
receiving file list ... done
python/hello.py
python/hello.py~
python/cat9532/
python/cat9532/pi-cat9532.py~
python/cat9532/rpi-cat9532.py
python/cat9532/rpi-cat9532.py~
python/gpiotest/
python/gpiotest/testGPIO.py
python/i2ctest/
python/i2ctest/i2ctest.py
python/i2ctest/i2ctest.py~
python/mma7660/
python/mma7660/mma7455.c
python/mma7660/rpi-mma7660.c
python/mma7660/rpi-mma7660.py
python/mma7660/rpi-mma7660.py~
python/opencv/
python/opencv/ocvtest.py
python/servo-test/
python/servo-test/servo-test.py
python/servo-test/servo-test.py~
python/speech/
python/speech/hello.py~
python/speech/speech-test.py
python/speech/speech-test.py~
python/speech/test.py
python/speech/test.py~

sent 502 bytes received 24631 bytes 4569.64 bytes/sec
total size is 23024 speedup is 0.92
...
done.


Consulting

Need help with a hardware project or product? Drop us an email at info@electronut.in. We offer consulting services on AVR and Nordic nRF BLE - hardware design, firmware development, prototyping, PCB design/assembly, sourcing and manufacturing. We can help you bring your product to market!


Bluey nRF52 BLE IoT dev board

bluey
Check out our Bluey nRF52 BLE development board with built-in Accelerometer/Gyroscope, Temperature/Humidity and Ambient Light sensors. It's a fabulous tool to learn Nordic nRF52 BLE programming and explore IoT technologies.

Questions/Comments

We love hearing from our readers. Email us at info@electronut.in for questions or comments on this article. If you found this article useful, please support us by buying some of our hardware products.


Please sign up for updates

Once in a while, we will send you an email update on the latest Electronut Labs projects and products. Your email address will never be shared or abused, ever.

2016 Electronut Labs. All rights reserved.