Backing up and restoring whole block devices

SD cards are not really a reliable storage, especially when used constantly e.g. while sitting in always powered-on Raspberry Pi. Because of that I’ve recently needed to perform lots of backup/restore operations ;)

I wrote this script for backing up:


if [[ -z $1 ]]; then
    echo "usage: $0 device_to_clone"


timestamp=`date +%Y%m%d`

echo "about to clone $device to $dest_file"
echo "ctrl-c or [enter]"

sudo umount $device?
sudo umount $device

sudo sync
sudo pv -tpreb $device | dd bs=4M | pixz > $dest_file
sudo sync

And this one for restoring:


if [[ -z $1 ]] || [[ -z $2 ]]; then
    echo "usage: $0 restore_file.xz device_to_restore_to"

if [[ ! -f $source_file ]]; then
    echo "cannot open $source_file"


echo "about to restore $source_file onto $device"
echo "ctrl-c or [enter]"

sudo umount $device?
sudo umount $device

pv -tpreb $source_file | pixz -d | sudo dd bs=4M of=$device
sudo sync
sudo eject $device

Some of the more fun features include progressbars and making sure you’ve unmounted the device properly before ;)
This also uses parallel threads to deflate the data, so the XZ compression should not be a bottleneck on any modern machine.
The scripts above were used to backup and restore SD cards but will work for any block device, be it an external or internal disk drive, etc.

usage example [remember to use the whole device, not just its partition as an argument]:

./backup_sdcard /dev/sdc
about to clone /dev/sdc to /tmp/20150214.dd.xz
ctrl-c or [enter]

[sudo] password for cyryl: 
umount: /dev/sdc1: not mounted
umount: /dev/sdc2: not mounted
umount: /dev/sdc: not mounted
19,6MiB 0:00:02 [9,72MiB/s] [>                                                                                                                                               ]  0% ETA 0:52:26

Flattr this!

Standing desk

It was some time since the last photo-story so, please accept these pictures of my standing desk.

On the actual desk, there is a laptop stand serving a role of a keyboard and mouse rest. Laptop itself is flipped on its back, motherboard attached to the back of what once was a lid. The whole thing is flying on standard monitor desk mount, using custom vesa-to-acrylic mounting system ;)

Flattr this!

GUI Vagrant box

Recently I’ve started working on changing my default development workflow. I’m evaluating vagrant as a main env manager, and then docker for extra speed. In short, my vagrant up boots up new dev box and then couple of docker containers. What I’ve found is that there is not really a plethora of GUI-enabled vagrant boxes, so I’ve created one !

If you want to use it, go:

vagrant init cyplo/ubuntu-gnome-utopic-gui
vagrant up

I will write about the whole setup later, as I’m not yet sure what approach is best for me.

Flattr this!

Tor talk

I gave a talk this Monday, an important one I think. The one from the kind of spreading  knowledge on the safe internet usage to people not necessarily of the tech background.

This was my first one given to a such audience and to add to it all, it was given in Polish. The biggest challenge ? Finding good equivalent for the English tech terms.

I think the talks went quite okay and the discussion afterwards was quite lively. I said a bit on how the internet works and what’s wrong with that, to transition later to what problems Tor addresses and which it does not. I tried to emphasize that using Tor does not make you automatically immune to the dangers of the internet.

Big thanks to the organizers, Praxis student group from the Wroclaw University of Economy.

You can find my slides’ sources here, along with speaker notes.

Flattr this!

Running Eagle on Ubuntu 14.10 64bit

Eagle is still the first choice when it comes to Open Hardware electronics design. That’s a bit unfortunate because the software itself is proprietary. Sometimes you need to run it though. For example to migrate projects over to non-proprietary software !

Say, you’d like to run new Eagle 7.1 under Ubuntu ?
Try repos.
Repos have the old major version 6 only.
The harder to get proprietary software the better, I suppose.

Download the blob then:

$ wget -c
$ chmod a+x

Inspect and run the stuff:

$ vim 
$ ./ 
Ensure the following 32 bit libraries are available: => not found => not found => not found => not found => not found => not found => not found => not found

32bit craziness, you say.
New Ubuntu does not have ia32 libs prepackaged, you say ?

Here, have this handy list of all of the dependencies then:

$ sudo apt-get install libxrandr2:i386 libxrender1:i386 libxcursor1:i386 libfreetype6:i386 libfontconfig:i386 libxi6:i386 libssl1.0.0:i386 libcrypto++9:i386
# should show you the installation wizard [sic !]
$ ./ 

Flattr this!

Poor man’s secrets storage

I’m a bit cautious when it comes to storing my passwords and other secrets. I do not use any web or desktop applications to do this for me. How do I remember those passphrases then ?

I have a central file server, accessible via a tunnel. I store there a gpg-encrypted file containing a tar archive of a directory with various files containing secrets. Syncing these files across computers became a bit cumbersome lately. I’m using git to version them, but because I do not want to have the sync server to contain unencrypted secrets I needed to bake some custom solution.

Bash to the rescue !
There are still some assumptions made here about permissions, directories layout and some stuff not failing, but I’m sure you’ll be able to figure this out and tweak to your needs.




pushd `pwd`

echo "removing old vault backup at $LOCAL_VAULT_BACKUP_DIR"

set -e

echo "backing up local vault..."

echo "establishing tunnel ..."

echo "tunnel ready, copying remote version of the vault..."
rsync --progress -avz -e "ssh -p $TMP_LOCAL_PORT" "$STORAGE_CREDS:$REMOTE_VAULT_PATH" "$TMP_VAULT"

echo "decrypting new vault..."
gpg -d "$TMP_VAULT" > "$TMP_VAULT_TAR"

echo "unpacking new vault..."
mkdir -p "$TMP_VAULT_DIR"

echo "pulling from remote vault..."
git pull "$TMP_VAULT_DIR"

echo "pulling to remote vault..."
git pull "$LOCAL_VAULT_DIR"

echo "cleaning up a bit..."
rm -fr "$TMP_VAULT_TAR"
rm -fr "$TMP_VAULT"

echo "packing refreshed remote vault..."
tar pcf "$TMP_VAULT_TAR" -C "$TMP_VAULT_DIR" .

echo "encrypting refreshed remote vault..."
gpg -c "$TMP_VAULT_TAR"

echo "sending out updated vault"
rsync --progress -avz "$TMP_VAULT" -e "ssh -p $TMP_LOCAL_PORT" "$STORAGE_CREDS:$REMOTE_VAULT_PATH"

echo "cleaning up.. "
rm -fr "$TMP_VAULT_DIR"
rm -fr "$TMP_VAULT_TAR"
rm -fr "$TMP_VAULT"

echo "closing tunnel.."
ssh -S "$SOCKET" -O exit $TUNNEL_CREDS


Flattr this!

Compiling git 2.0 on cygwin

I had some troubles compiling git 2.0 under cygwin. I present you with a very dirty hack to do so. Proper patch will probably follow.
Did I mention that the hack is dirty and will make your hands burn if you’re gonna type it in ?

git clone
cd git
git checkout v2.0.1
# so far so good...

# oops
# ....

make[2]: /home/cplotnicki/dev/git/perl/0: Command not found
perl.mak:375: recipe for target 'blib/lib/.exists' failed
make[2]: *** [blib/lib/.exists] Error 127
Makefile:16: recipe for target 'all' failed
make[1]: *** [all] Error 2
Makefile:1653: recipe for target 'all' failed
make: *** [all] Error 2

Want perl as ‘0’ ? Well, why not. Here you are:

# link perl as 0 to some directory that is in your path
ln -s /usr/bin/perl ~/tools/0
# also link here, obviously.
# 'perl' is a direct subdir for your git checkout
ln -s /usr/bin/perl perl/0

make # should now compile

# cygwin's permission scheme is very peculiar
# here, have a dirty hack for your default install
# where there is no su or sudo
chmod a+rwX -R /usr/local/share/man/man3
chmod a+rwX -R /usr/local/lib/perl5/site_perl

make install
git --version
# should display 2.0.1.
# update man pages' cache manually

Flattr this!