From 4dd9821ba1cb2c9f6d6659b1728437454f8d4503 Mon Sep 17 00:00:00 2001 From: 6543 Date: Wed, 20 Feb 2019 00:48:33 +0100 Subject: [PATCH 1/3] explane algorythm add const set structure --- tools/db/update-file-state | 131 +++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tools/db/update-file-state diff --git a/tools/db/update-file-state b/tools/db/update-file-state new file mode 100644 index 0000000..8f79554 --- /dev/null +++ b/tools/db/update-file-state @@ -0,0 +1,131 @@ +#!/bin/bash +# @author 6543 +# @version 0.1 +# @date 2019-02-07 + +## Options/Parameter +# [$1]: + +{ #set enviroemnt + readonly TRUE=1 #like + readonly FALSE=0 #like + readonly TTSYNC_EXIST=0 + readonly TTSYNC_BACKUP=1 + readonly TTSYNC_REMOTE=2 + readonly TTSYNC_DEL=3 + readonly globalconf="/etc/tt/global" +} + +{ #get options & args + readonly mode=$(echo $1 | tr -d '-') + moviedir="$1" +} + +{ #db + dbname="tt_test" + dbhost="localhost" + dbuser="root" + dbpwd="" +} + +function help() { + #help menue + echo "$0 is part of the TerabyteTerminator Project" + echo "" + echo "update-file-state [moviedir]" + echo " moviedir: Is optional if it is already in the global config" + + exit 0 +} +[ "$mode" == "help" ] && help + +########################### +## Programm Haupt Ablauf ## +########################### +function main() { + #cd to moviedir + cd "$moviedir" + + ## dateiliste erstellen die mit DB abgeglichen wird + + ## Für alle existierenden Dateien: + ## * Path=DB.PATH && TTSync == TTSYNC_DEL + ## -> DB.Size != 0 && Size == DB.Size -> TTSYNC_DEL -> TTSYNC_EXIST // >>file_undel<< konsider other state ?!? + ## -> DB.Size != 0 || Size != DB.Size -> compare if md5 is same + ## -> Ja -> TTSYNC_DEL -> TTSYNC_EXIST // >>file_undel<< + ## -> NA -> delete DB Entry + ## * Path=DB.PATH && TTSync == TTSYNC_EXIST / TTSYNC_BACKUP + ## -> DB.Size = 0 -> file_add_size + ## -> Size != DB.Size -> compare if md5 is same + ## -> Ja -> update file size (file_add_size) + ## -> NA + ## -> makr DB.FID = TTSYNC_DEL + ## -> file_add // this is a new file + ## * Path=DB.PATH && TTSync == TTSYNC_REMOTE + ## -> DB.Size = 0 -> compare if md5 is same + ## -> Ja + ## -> update file size (file_add_size) + ## -> TTSYNC_REMOTE to TTSYNC_BACKUP + ## -> NA + ## -> Size = DB.Size TTSYNC_REMOTE to TTSYNC_BACKUP + ## -> Size != DB.Size // Error Remote CP incorect!!! + + ## alle nicht gecheckten path einträge in DB (fiels die nicht existieren) + ## A: HDD kaput + ## B: Absichtlich gelöscht + ## hdd_check // ob eine HDD defekt ist bzw das mounten irgendwo fehlgeschlagen ist + ## -> ja -> error mesage! + ## -> na -> set DB.FID TTSYNC_DEL + +} + +########################### +## help functions ######### +########################### + +##check & prepair args +[ -z "$moviedir" ] && [ -f "$globalconf" ] && { # if (no argument) and (globalconf exist) + if [ -z "$(grep "moviedir=" "$globalconf" )" ]; then # and (moviedir is NOT in globalconf) + echo 'neither "movie folder" is set in global config nor given as argument' + exit 2 + else # and (moviedir is in globalconf) + moviedir="$(grep "moviedir=" "$globalconf" | cut -d '=' -f 2)" + fi +} +[ -d "$moviedir" ] || { echo "moviedir \"$moviedir\" do not exist"; exit 3; } # check moviedir +moviedir=""$(echo $moviedir | sed 's|/$||g')"" +[ -z "$moviedir" ] && exit 255 #catch case moviedir="/" + +function md5_out_exist() { + db_query "SELECT CONCAT(MD5, ' ', ' ' ,'$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_EXIST OR TTSync=$TTSYNC_BACKUP;" >> $md5list + exit 0 +} + +function md5_out_del() { + db_query "SELECT CONCAT(MD5, ' ', ' ' ,'$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_DEL;" >> $md5list + exit 0 +} + +# file_size -> (du -b)/1024 [Kb] +function file_size() { + echo $(($(du -b "$1" | cut -f 1)/1024)) +} + +# db_query -> result +function db_query() { + local args="-sN" #no headers, no grid + args+=" -h$dbhost" + args+=" -u$dbuser" + [ -n "$dbpwd" ] && args+=" -p$dbpwd" + args+=" $dbname" + echo $@ | mysql $args +} + +# db_F-ID_getPath -> +function db_id_getPath() { + db_query "SELECT CONCAT('$moviedir/', Folder, '/', Name) FROM File WHERE ID=$1;" +} + + + +main #aufruf der main function (eig. programmstart) From 63d8cf57500aff4c36be3b22aa94afdabd5a1b49 Mon Sep 17 00:00:00 2001 From: 6543 Date: Mon, 29 Apr 2019 21:09:42 +0200 Subject: [PATCH 2/3] add note --- tools/db/update-file-state | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/db/update-file-state b/tools/db/update-file-state index 8f79554..6d4fec2 100644 --- a/tools/db/update-file-state +++ b/tools/db/update-file-state @@ -48,6 +48,8 @@ function main() { ## dateiliste erstellen die mit DB abgeglichen wird + ## alle die keien DB.PATH eintrag haben -> file_add + ## Für alle existierenden Dateien: ## * Path=DB.PATH && TTSync == TTSYNC_DEL ## -> DB.Size != 0 && Size == DB.Size -> TTSYNC_DEL -> TTSYNC_EXIST // >>file_undel<< konsider other state ?!? From 8c35837215085893d2e5d243c24de9f531309f31 Mon Sep 17 00:00:00 2001 From: 6543 Date: Mon, 29 Apr 2019 21:19:17 +0200 Subject: [PATCH 3/3] change DB Shema! resolve issue #18 (int -> varchar for IMDb ID) --- DB/shema.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DB/shema.sql b/DB/shema.sql index c02af18..34134b5 100644 --- a/DB/shema.sql +++ b/DB/shema.sql @@ -2,7 +2,7 @@ CREATE TABLE File ( ID INTEGER PRIMARY KEY AUTO_INCREMENT, - Name TEXT NOT NULL, -- bis zu 65535 Zeichen; + Name TEXT NOT NULL, -- bis zu 65535 Zeichen; Folder TEXT NOT NULL, -- bis zu 65535 Zeichen; Pfad = $Folder/$Name MD5 VARCHAR(32), FT_ID INTEGER DEFAULT 0, @@ -29,7 +29,7 @@ CREATE TABLE Universum ( CREATE TABLE Movie ( ID INTEGER PRIMARY KEY AUTO_INCREMENT, - IMDb_ID INTEGER, + IMDb_ID VARCHAR(100), U_ID INTEGER, Name VARCHAR(100), Description TEXT, @@ -97,4 +97,4 @@ CREATE TABLE Language ( ID INTEGER PRIMARY KEY AUTO_INCREMENT, TLD VARCHAR(2), Name VARCHAR(100) NOT NULL -); \ No newline at end of file +);