#!/bin/sh
DateFormat="+%F %T %w" FilesDir='/data1/db/2.8/' MountedDir='/mnt/2.8/'
autotobz2() { ## Mount BAK dir.
umount $MountedDir sqlite3 ${FilesDir}jf28.db "delete from baksize;"
$($execStr) if test 0 == $? then ## If mount success.
sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','','Success','Mounted $MountedDir');" ## Is files exist?
ls -l ${MountedDir}etcom_cd_db_*.BAK if test 0 == $? then ## list file name and size. separator is "|".
for i in $(ls -l ${MountedDir}etcom_cd_db_*.BAK | sed 's/\// /g' | awk -F " " '{print $11"|"$5}'); do ## insert file name and size into baksize table.
## for debug echo 'Check: $i1 = '$i
Filename=$(echo $i | awk -F "|" '{print $1}') Filesize=$(echo $i | awk -F "|" '{print $2}') sqlite3 ${FilesDir}jf28.db "insert into baksize values('${Filename}','${Filesize}');" done ## delete recoder when name and size is same.
sqlite3 ${FilesDir}jf28.db "delete from baksize where filename in (select k.filename from bz2size z,baksize k where z.filename=k.filename and z.size=k.size);" ## ready Tar, separator is "|".
for i in $(sqlite3 ${FilesDir}jf28.db "select filename,size from baksize"); do ## exec Tar operation.
## for debug echo 'Check: $i2 = '$i
Filename=$(echo $i | awk -F "|" '{print $1}') Filesize=$(echo $i | awk -F "|" '{print $2}') execStr="tar -jcf $FilesDir$Filename.bz2 $MountedDir$Filename" $($execStr) if test 0 != $? then sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','$execStr','Fail','$(perror $?)');" else sqlite3 ${FilesDir}jf28.db "delete from bz2size where filename = '$Filename'" sqlite3 ${FilesDir}jf28.db "INSERT INTO bz2size VALUES('$Filename','$Filesize');" sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','','Success','$execStr');" fi done else sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','$execStr','Alarm','Not BAK file!');" fi umount $MountedDir ## If mount fail.
else sqlite3 ${FilesDir}jf28.db "insert into log values(NULL,'$(date "$DateFormat")','$execStr','Fail','$(perror $?)');" fi }
execStr="mount -t cifs -o username=administrator,password=spat123cd //192.224.2.8/etcomdb_bak1/ $MountedDir" autotobz2 execStr="mount -t cifs -o username=etcom,password=etcom //192.224.2.8/etcomdb_bak2/ $MountedDir" autotobz2
|