#!/bin/bash USER=`whoami` if [ "$USER" != "root" ]; then echo "need root" exit 1 fi if mount | grep target 2>&1 >/dev/null; then umount /target fi if mount | grep source 2>&1 >/dev/null; then umount /source fi echo 9 > /proc/sys/kernel/printk echo Mounting ext4 test partitions > /dev/kmsg mount /dev/sda3 /source mount /dev/sda4 /target #mount /dev/sda4 /target -o data=journal #mount /dev/sda4 /target -o data=writeback #echo 512 > /sys/fs/ext4/sda4/max_writeback_mb_bump cat > /tmp/copy.py << EOF #!/usr/bin/python import os import sys def copy_file(sourcepath, targetpath): sourcefh = None targetfh = None try: sourcefh = open(sourcepath, 'rb') targetfh = open(targetpath, 'wb') while 1: buf = sourcefh.read(16*1024) if not buf: break targetfh.write(buf) finally: if targetfh: targetfh.close() if sourcefh: sourcefh.close() copy_file(sys.argv[1], sys.argv[2]) EOF chmod +x /tmp/copy.py echo -n "Sync.." sync; sleep 1 echo -n "." sync; sleep 1 echo -n "." sync; sleep 1 echo -n "." echo "Done!" # # And free up caches # echo Freeing the page cache: echo 1 > /proc/sys/vm/drop_caches echo Free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches echo Free the page cache, dentries and the inodes: echo 3 > /proc/sys/vm/drop_caches echo 30 > /proc/sys/kernel/hung_task_timeout_secs echo 3000 > /proc/sys/vm/dirty_writeback_centisecs echo 6000 > /proc/sys/vm/dirty_expire_centisecs for I in {1..1000} do echo TEST $I echo TEST $I > /dev/kmsg cd /source find . | while read x do d=`dirname $x` b=`basename $x` mkdir -p /target/$d if [ -f $x ]; then /tmp/copy.py $x /target/$d/$b fi done done cd umount /source umount /target