Pages

Saturday, 16 March 2013

Discovering rsync - TDD approach

rsyncdiscovery

A test script to find out rsync parameters for backup.

Conclusion

To copy src to tgt:

rsync -r -H -l -g -o -t -D -p --del src tgt

And you will end up with

tgt/src

being a mirror of the original src directory.

Test usage

The shell script's source and this document lives here

To discover the tests:

./test_rsync.sh list_tests

To run the tests:

sudo ./test_rsync.sh

Background

I would like to create a file-level backup of some files. My goal is to use rsync to do the job. As rsync has a lot of command line switches, first, I would need to know, which ones to use. For this, I have some expectations:

  1. Backup is recursive
  2. Extra files removed
  3. Links are preserved
  4. Symlinks are preserved
  5. Symlinks are not rewritten
  6. Preserve permissions
  7. Modification times are preserved
  8. Special files reserved

And of course, a test-driven approach will be used. Bash does not prevent you from writing tests, so go ahead.

Ending slash: The ending slash is important on the source side, if you wish to say to copy the contents of that directory, not the directory itself.

The archive mode includes:

  • r - recursive
  • l - copy symlinks as symlinks
  • p - preserve permissions
  • t - preserve modification times
  • g - preserve group
  • o - preserve owner
  • D - preserve device and special files

And the manual also states, that it does not include:

  • H - preserve hard links
  • A - preserve ACLs
  • X - preserve extended attributes

For me the hardlinks seem to be important.

Sunday, 10 March 2013

Make an md array writable

I usually set my arrays to readoly, after assembling them. This way I could avoid unattended rebuilds. But sometimes, you would want to update some data on the disk. For doing this, let's see what we have:
root@plugged:~# mdadm --detail /dev/md1 | grep Update 
    Update Time : Sun Dec  2 12:58:58 2012
And what is the short info?
root@plugged:~# cat /proc/mdstat 
Personalities : [raid1] 
md1 : active (read-only) raid1 sdc2[0] sdd2[1]
      83884984 blocks super 1.2 [2/2] [UU]
Now, let's put it into r/w mode:
mdadm --readwrite /dev/md1
Let's see what happened:
cat /proc/mdstat
md1 : active raid1 sdc2[0] sdd2[1]
      83884984 blocks super 1.2 [2/2] [UU]
Did the superblock date changed?
root@plugged:~# mdadm --detail /dev/md1 | grep Update
    Update Time : Sun Mar 10 18:23:18 2013
So, it changed as soon, as I set it to readwrite mode.

Sunday, 3 March 2013

Meet with buildroot - Custom Linux

I was thinking about having a really small linux system for cloud images. I already knew about the concept of JeOS (Just enough OS), but I still can't agree having more than 100MB as a disk. Actually, I would like to be able to have something around 50 MB. I knew about CirrOS, which we use for functional testing OpenStack. CirrOS is small, the qcow image is 10 Megs. So I looked at the launchpad site, and discovered, that cirros is using buildroot to create the root filesystem. That was enough inspiration for me to try to create a very minimal Linux. First build
$ mkdir myl
$ cd myl
$ wget -qO - http://buildroot.uclibc.org/downloads/buildroot-2013.02.tar.gz | tar -xzf -
$ cd buildroot*
$ make qemu_x86_defconfig
$ time make
Before starting make, I looked into the configuration, and it turned out, that qemu_x86_defconfig includes building a kernel, so I expect the build to last at least for an hour. In the meanwhile, it makes sense to read how I will start the machine:
$ cat board/qemu/x86/readme.txt
In the end, it was quicker than I expected:
real 26m5.626s
user 32m15.753s
sys  3m55.447s
And, let's see how it boots!
qemu-system-i386 -M pc \
-kernel output/images/bzImage \
-drive file=output/images/rootfs.ext2,if=ide \
-append root=/dev/sda
Wow! that was fast. To get a feeling on how fast it is, see this video And you might be interested in the size of the whole stuff:
$ du -shc output/images/
3.2M output/images/
3.2M total

TDD framework with inotifywait and tox

So let's say, you want to do TDD. It means, that whenever you change something, you would want to run the tests. Okay, it sounds like a boring task, so let's automate it, to meet the Agile practices. So a user-space utility, called
inotifywait
will be used. This blocks, until some even happens with the monitored files. As my source code is in git, I will use:
git ls-files
to get the files to be watched. Okay, let's put it together:
$ git ls-files | inotifywait -q --fromfile -
This blocks, until something happens to a file that is watched. Let's save a file with vim, that is under version control, and see that inotifywait unblocks, and outputs:
fs/__init__.py MOVE_SELF 
Okay, that works, so let's use it as a framework to run our tests:
$ while true; do git ls-files | inotifywait -q --fromfile -; tox; done
As you add a new file to git, that will result in a change in .gitignore, so it should be automatically picked up by our framework. Tox gives you pretty colours as well!

Monday, 10 December 2012

PIL jpeg support on 64 bit Precise

If you have problems with installing PIL, look at this site
In short:
sudo ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/
sudo ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/

Sunday, 9 December 2012

My First Android App

Yesterday, I decided to keep up with the rest of the world in some ways, so I bought a Samsung Galaxy ACE smartphone. I know, it is not a really high-end stuff, according to the current state of the smartphone market. Anyhow, I think it is a great value for 85 pounds, with a pay as you go contract. I am really impressed by this phone, and I decided, to develop a hello world application. So, I first downloaded the Android SDK. As I extracted the tar.gz, the Readme file told me how to carry on with the installation. So I followed the instructions, first with the UI:
tools/android update sdk
With the UI, I selected to install:
  • Android SDK Tools
  • Android SDK Platform-tools
  • For Android 2.3.3
    • SDK Platform
    • Samples for SDK
After the process finished, the log window had a warning:
Stopping ADB server failed (code -1).
I will ignore it for now. The whole stuff is consuming around 307 megs at the moment.
cd tools
./android list targets
And I created a project:
./android create project --target "android-10" --name HelloWorldApp \
--path ~/Documents/android/workspace/HelloWorldApp \
--activity MainActivity --package eu.lakat.example.helloworldapp
Let's go back to the "root":
cd ..
I created a small script, to include all the paths in one shot:
export PATH=$PATH:"$(pwd)/android-sdk-linux/tools/":"$(pwd)/android-sdk-linux/platform-tools/"
Changed the directory to the applications:
cd workspace/HelloWorldApp/
Compiled it to debug:
ant debug
And installed it on my device:
adb install bin/HelloWorldApp-debug.apk
Everything worked perfectly fine, I found the app in my device, and was able to run that easily. Cool!

Virtual device

android avd
Use th UI to create a new device, and simply execute:
adb install bin/HelloWorldApp-debug.apk

Monday, 3 December 2012

NFS installation

So I decided to put an NFS server to my DreamPlug. First, an easy step:
apt-get --no-install-recommends install nfs-kernel-server
Let's see what do I have:
root@plugged:~# lsmod | grep nfs
nfsd                  243695  11 
exportfs                3108  1 nfsd
So, next step is to export a directory. I would like to create a read-only export.
cat /etc/exports
/mnt/md2        192.168.0.2(ro,no_subtree_check)
TODO: Some security Okay, so let's restart the nfs server:
/etc/init.d/nfs-kernel-server stop
/etc/init.d/nfs-kernel-server start
Install the client on the other machine:
sudo apt-get --no-install-recommends install nfs-common
And mount the export:
sudo mount 192.168.0.4:/mnt/md2 /mnt/md2
It does not seem to perform very well. For example, from the client, through wifi:
time ls -la /mnt/md2/1/ > /dev/null
Gives
real 1m18.605s
user 0m0.560s
sys 0m2.632s
Whereas running the same stuff on the DreamPlug:
real 0m2.572s
user 0m1.650s
sys 0m0.920s
And that's fast. Let's try to dd some files.
dd if=/mnt/md2/1/ffc4f5bc7f6b78ac371f3ecebdd9701e4cb8c68f of=/dev/null
Gives:
577409024 bytes (577 MB) copied, 103.255 s, 5.6 MB/s
And what is the raw speed? On the server:
nc -l -p 4545 -q 1 < /mnt/md2/1/ffc4f5bc7f6b78ac371f3ecebdd9701e4cb8c68f
On the client:
nc 192.168.0.4 4545 | dd of=/dev/null
And the results:
577409024 bytes (577 MB) copied, 103.84 s, 5.6 MB/s
So nfs gives almost no overhead. (Please note, that the 1 sec was the waiting time added by the netcat server. That's negligable.) Let's see the same thing locally on the server:
dd if=/mnt/md2/1/ffc4f5bc7f6b78ac371f3ecebdd9701e4cb8c68f of=/dev/null
Result:
577409024 bytes (577 MB) copied, 19.4105 s, 29.7 MB/s
NFS over a gigabit connection (after umount-mount, to clear the cache):
577409024 bytes (577 MB) copied, 24.6491 s, 23.4 MB/s
Without NFS (nc way):
577409024 bytes (577 MB) copied, 20.9865 s, 27.5 MB/s
So yes, NFS has some overhead at these rates.