#!/bin/sh # # Script to export files # Parameters: # $1: password used to encrypt the file # $2: name of zipped file # $3: path to files to backup # $4: temporary path to store the zipped file # Configuration EXPORTER=/home/tool/bin/7za # check exporter if [ ! -e $EXPORTER ]; then echo "Exporter not found" >&2 exit 1 fi # param1 password check if [ $# -eq 0 ]; then echo "Password required" >&2 exit 1 fi PWD=$1 if [ "$PWD" = "" ]; then echo "No empty password" >&2 exit 1 fi # param2 export (zipped) file name if [ $# -eq 1 ]; then echo "Export file name required" >&2 exit 1 fi EXPORTFNAME=$2 if [ "$EXPORTFNAME" = "" ]; then echo "Empty export file name given" >&2 exit 1 fi # param3 the path to file name if [ $# -eq 2 ]; then echo "full target program file name required" >&2 exit 1 fi FILE_LIST=$3 # param4 the temporary path to save the zipped file if [ $# -eq 3 ]; then # use SD card logger -p user.info "log_exporter.sh use SD card" # check SD BLOCK_LIST=$(find /sys/class/block/mmcblk* -maxdepth 0 2>/dev/null) if [ ! $? -eq 0 ]; then echo "No SD card" >&2 logger -p user.err "log_exporter.sh no SD card found" exit 1 fi # get SD mount path PART_LIST=$(find /sys/class/block/mmcblk*p* -maxdepth 0 2>/dev/null) if [ ! $? -eq 0 ]; then # No partitions DEV_PATH=$(find /sys/class/block/mmcblk* -maxdepth 0 | head -n 1) else # Partitions. get the first DEV_PATH=$(find /sys/class/block/mmcblk*p* -maxdepth 0 | head -n 1) fi SD_PATH=/mnt/mmc/$(basename $DEV_PATH) if [ ! -e $SD_PATH ];then echo "SD card not mounted" >&2 logger -p user.err "log_exporter.sh SD card not mounted" exit 1 fi TARGET_FILE=$SD_PATH/$EXPORTFNAME TARGET_DIR=`dirname $SD_PATH/$EXPORTFNAME` if [ ! -d $TARGET_DIR ] then mkdir $TARGET_DIR fi echo "Exporting" $TARGET_FILE logger -p user.info "log_exporter.sh Exporting: " $TARGET_FILE else TARGET_FILE=$4/$EXPORTFNAME fi # remove previous archive rm -f $TARGET_FILE #echo /bin/tar cf - $FILE_LIST \| $EXPORTER a -si -tzip -mx=1 $TARGET_FILE -p$PWD $EXPORTER a -t7z -mx=3 $TARGET_FILE $FILE_LIST -p$PWD sync RETVAL=$? if [ $RETVAL -eq 0 ];then logger -p user.info "log_exporter.sh Success" echo Success fi if [ $RETVAL -ne 0 ];then logger -p user.err "log_exporter.sh Failure" echo Failure fi exit $RETVAL