#!/bin/sh

if [ "$(id -u)" != "0" ]; then
    echo "You must be root"
    exit 1
fi

create_backup() {
    disk=$1
    archive=$2
    dd if=$disk status=progress | gzip -9 > $archive
}

restore_backup() {
    archive=$1
    disk=$2
    gzip -dc $archive | dd of=$disk status=progress
}

print_help() {
    printf "usage:\n\t$0 (create|restore)\nexample:\n\t$0 create (disk) (archive)\n\t$0 restore (archive) (disk)\n"
}

case "$1" in
    "create")
        if [[ "$2" == "" || "$3" == "" ]]; then
            print_help
            exit 1
        fi
        create_backup $2 $3
        ;;
    "restore")
        if [[ "$2" == "" || "$3" == "" ]]; then
            print_help
            exit 1
        fi
        restore_backup $2 $3
        ;;
    *)
        print_help
        ;;
esac

