From c6f238ae0154f9c4fc9c82010abcbbb509ee43de Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Sun, 26 May 2024 12:39:50 -0500 Subject: [PATCH] Finished feature --- bucket-tool | 75 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/bucket-tool b/bucket-tool index a5aaff6..bbb60f6 100755 --- a/bucket-tool +++ b/bucket-tool @@ -22,43 +22,44 @@ Description: search the filebucket and restore from it. Actions: - search : Search for bucket entries matching a portion of the filepath - list : List all Bucket entries - list-files : List all files/paths that have been backed up to the bucket - get : Get the content of a specific entry (by hash) - restore : Restore previous state of file stored in bucket. Value can be hash or filename/filepath - : Note: To restore to an alternate path you will need to provide the path via the -o flag - : - backup : Backup the file to the bucket (will work relatively unless full path is provided) + search : Search for bucket entries matching a portion of the filepath + list : List all Bucket entries + list-files : List all files/paths that have been backed up to the bucket + get : Get the content of a specific entry (by hash) + restore : Restore previous state of file stored in bucket. Value can be hash or filename/filepath + : Note: To restore to an alternate path you will need to provide the path via the -o flag + : + backup : Backup the file to the bucket (will work relatively unless full path is provided) Restore Flags: - -o | --output-file : Used to provide an alternate restoral path for the restore function + -o | --output-file : Used to provide an alternate restoral path for the restore function Global Flags: - -d | --debug : Set debug flag - -h | --help : This help message + -d | --debug : Set debug flag + -h | --help : This help message + -b | --bucket : User specified bucket directory Listing Filter Flags: - --from-date : Filter listings from starting after this point (FORMAT: YYYY-MM-DD HH:MM:SS) - : EX: - : 1. --from-date 2023-05-10 - : 2. --from-date "2023-05-10 13:23" - : - --to-date : Filter listings from ending at this point (FORMAT: YYYY-MM-DD HH:MM:SS) - : EX: - : 1. --to-date 2024-05-10 - : 2. --to-date "2024-05-10 05:27" - : + --from-date : Filter listings from starting after this point (FORMAT: YYYY-MM-DD HH:MM:SS) + : EX: + : 1. --from-date 2023-05-10 + : 2. --from-date "2023-05-10 13:23" + : + --to-date : Filter listings from ending at this point (FORMAT: YYYY-MM-DD HH:MM:SS) + : EX: + : 1. --to-date 2024-05-10 + : 2. --to-date "2024-05-10 05:27" + : Info Format Flags: - -i | --inline : Set the info format to inline (MTIME : HASH : FILENAME) - -l | --long : Set the info format to long - : Entry [HASH]: - : Paths: path1,path2,...,pathn - : MTIME: YYYY-MM-DD HH:MM:SS -#### - : - -c | --csv : Set the info format to csv ( MTIME,HASH,FILENAME1[;FILENAMEn] ) + -i | --inline : Set the info format to inline (MTIME : HASH : FILENAME) + -l | --long : Set the info format to long + : Entry [HASH]: + : Paths: path1,path2,...,pathn + : MTIME: YYYY-MM-DD HH:MM:SS -#### + : + -c | --csv : Set the info format to csv ( MTIME,HASH,FILENAME1[;FILENAMEn] ) Author: Name: Tristan Ancelet @@ -284,6 +285,19 @@ while i < ARGV.count usage exit end + + when '-b', '--bucket' + log "user provided ARGV[i.next] == #{ARGV[i.next]}" + if ARGV[i.next] != "" and not ARGV[i.next] =~ FLAG_REGEX + $CONFIG[:bucketdir]=ARGV[i.next] + log "$CONFIG[:bucketdir] was set to #{ARGV[i.next]}" + i+=2 + else + puts "Flag[#{ARGV[i]}] : Argument[#{ARGV[i.next]}] : Either the argument was not provided or it was a flag" + usage + exit + end + when '--to-date', '--from-date' if ARGV[i.next] != "" and ARGV[i.next] =~ DATE_REGEX date_matches = DATE_REGEX.match(ARGV[i.next]).named_captures.each_value.select{|val| not val.nil?}.map(&:to_i) @@ -319,6 +333,11 @@ if $CONFIG[:action] == "" puts "Action was not provided" end +if not Dir.exist? $CONFIG[:bucketdir] + puts "BucketDir[#{$CONFIG[:bucketdir]}] Does not exist. Please check to make sure configuration is correct" + exit +end + case $CONFIG[:action] when 'search', 'get' if $CONFIG[:search_term] == ""