#!/bin/bash
# xpud-backup <path> [-p|-r|-s]

if [ -d $1 ]; then

# FIXME: maybe exclude /dev, /mnt, /var directories?
find /cow | grep -v "/dev" | grep -v "/mnt" | grep -v "/roopt" | grep -v "/tmp" | grep -v "/var" | cpio -H newc -o | gzip -9 > $1/xpud-data.gz

if [ -d $1/opt ]; then cp -apf /opt/*.opt $1/opt/; fi

# if additional parameter was passed - poweroff or reboot
case "$2" in
	'-p')
		#poweroff -f;
		poweroff;
	;;
	'-r')
		#reboot -f;
		reboot;
	;;
	'-s')
		boot-to-win;
	;;
esac

fi
